GitXplorerGitXplorer
k

attached

public
22 stars
9 forks
0 issues

Commits

List of commits on branch master.
Unverified
6ef5681efd94807d334b12d8229b57ac472a6576

jruby support

kksylvest committed 10 years ago
Unverified
51a7cb61f3452ef84195e5fd1ff3eb7ddf2202df

fixing up appraisals

kksylvest committed 10 years ago
Unverified
14898612b41cd40cb0bc36c754de17f9e6987fb5

simplifying testing suite

kksylvest committed 10 years ago
Unverified
ec49b3099e7cdcc43ba158041ff3105122898628

fixing travis

kksylvest committed 10 years ago
Unverified
f59cb7b9b062aaeac960c7b16ec2c152f9fa9d92

appraisals

kksylvest committed 10 years ago
Unverified
f3010e01c210b0fc93a2e2137b48cfffa0789e4e

appraisals

kksylvest committed 10 years ago

README

The README file for this repository.

= Attached

Attached is a Ruby on Rails file attachment tool that lets users upload to the cloud. The gem supports AWS, Google and Rackspace for storage networks by default. It is influenced (and copied) from Paperclip and makes heavy use of the incredibly awesome Fog library.

== Requirements

The gem is tested with:

  • Ruby on Rails 4.1.6
  • Ruby 2.1.6
  • Ruby 2.0.0
  • Ruby 1.9.3
  • JRuby

== Installation

gem install attached

== Optional

brew install imagemagick brew install lame

== Examples

Migration:

rails g model video name:string encoding:attachment

class CreateVideo < ActiveRecord::Migration def self.up create_table :videos do |t| t.string :name t.attachment :encoding

    t.timestamps
  end
end

def self.down
  drop_table :videos
end

end

Model:

class Video < ActiveRecord::Base

has_attached :encoding, styles: { 
  webm: { extension: '.webm' },
  mp4:  { extension: '.mp4'  },
  ogv:  { extension: '.ogv'  },
}

after_save do
  remote.encode(self.encoding.url)
end

end

Form:

<%= form_for @video, html: { multipart: true } do |form| %> <%= form.file_field :encoding %> <% end %>

View:

== Advanced

=== Validations

app/models/person.rb

validates_attached_presence :file validates_attached_size :file, in: 2.kilobytes..2.megabytes validates_attached_extension :file, in: %w(jpe jpg jpeg png)

==== Storage

app/models/user.rb

has_attached :file, medium: :aws, credentials: "#{Rails.root}/config/aws.yml"

app/models/user.rb

has_attached :file, medium: :google, credentials: "#{Rails.root}/config/google.yml"

app/models/user.rb

has_attached :file, medium: :rackspace, credentials: "#{Rails.root}/config/rackspace.yml"

config/initializers/attached.rb

Attached::Attachment.options[:medium] = :aws Attached::Attachment.options[:credentials] = "#{Rails.root}/config/aws.yml"

config/initializers/attached.rb

Attached::Attachment.options[:medium] = :google Attached::Attachment.options[:credentials] = "#{Rails.root}/config/google.yml"

config/initializers/attached.rb

Attached::Attachment.options[:medium] = :rackspace Attached::Attachment.options[:credentials] = "#{Rails.root}/config/rackspace.yml"

=== Processors

app/models/image.rb

has_attached :file, processor: :image, styles: { small: { size: '200x200>', extension: '.jpg', quality: 90 }, large: { size: '400x400<', extension: '.jpg', quality: 90 }, default: { size: '300x300#', extension: '.jpg', quality: 90 }, }

app/models/image.rb

has_attached :file, processor: :image, styles: { small: { operation: :decrease, width: 200, height: 200, extension: '.jpg', quality: 90 }, large: { operation: :increase, width: 400, height: 400, extension: '.jpg', quality: 90 }, default: { operation: :resize, width: 300, height: 300, extension: '.jpg', quality: 90 }, }

app/models/audio.rb

has_attached :file, processor: :audio, styles: { full: { preset: '320kbps', extension: '.wav' }, large: { preset: '256kbps', extension: '.wav' }, small: { preset: '128kbps', extension: '.wav' }, }

app/models/audio.rb

has_attached :file, processor: :audio, styles: { full: { preset: 'insane', extension: '.wav' }, large: { preset: 'extreme', extension: '.wav' }, small: { preset: 'medium', extension: '.wav' }, }

=== Strategies

app/models/sample.rb

has_attached :file, processor: ..., styles: { ... }, strategy: :delay has_attached :file, processor: ..., styles: { ... }, strategy: :cache

=== Reprocessing

rake attached:process[Image,file] rake attached:process[Audio,file]

=== Aliases

app/initializer/attached.rb

Attached::Attachment.options[:alias] = "https://storage.ksylvest.com/"

app/initializer/attached.rb

Attached::Attachment.options[:aliases] = %w( https://a.storage.ksylvest.com/ https://b.storage.ksylvest.com/ https://c.storage.ksylvest.com/ https://d.storage.ksylvest.com/ )

=== Metadata

app/initializers/attached.rb

Attached::Attachment.options[:metadata] = { 'Cache-Control' => 'max-age=3153600' }

== Status

{}[https://gemnasium.com/ksylvest/attached] {}[https://travis-ci.org/ksylvest/attached] {}[https://coveralls.io/r/ksylvest/attached] {}[https://codeclimate.com/github/ksylvest/attached]

== Copyright

Copyright (c) 2010 - 2014 Kevin Sylvestre. See LICENSE for details.