Class: TBird::Uploader
- Inherits:
-
Object
- Object
- TBird::Uploader
- Defined in:
- lib/t_bird/uploader.rb
Instance Attribute Summary collapse
-
#acl ⇒ Object
readonly
Returns the value of attribute acl.
-
#content_type ⇒ Object
readonly
Returns the value of attribute content_type.
-
#file ⇒ Object
readonly
Returns the value of attribute file.
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#original_filename ⇒ Object
readonly
Returns the value of attribute original_filename.
-
#uploads ⇒ Object
readonly
Returns the value of attribute uploads.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(file, options = {}) ⇒ Uploader
constructor
A new instance of Uploader.
- #namer ⇒ Object
- #processor ⇒ Object
- #transmitter ⇒ Object
- #upload! ⇒ Object
- #versions ⇒ Object
Constructor Details
#initialize(file, options = {}) ⇒ Uploader
6 7 8 9 10 11 12 13 14 |
# File 'lib/t_bird/uploader.rb', line 6 def initialize(file, = {}) @file = file @acl = .fetch(:acl, :public_read) = .merge() @uploads = {} @content_type = @file[:type] @original_filename = @file[:filename] = { acl: acl, content_type: content_type, metadata: [:metadata] || {} } end |
Instance Attribute Details
#acl ⇒ Object (readonly)
Returns the value of attribute acl.
5 6 7 |
# File 'lib/t_bird/uploader.rb', line 5 def acl @acl end |
#content_type ⇒ Object (readonly)
Returns the value of attribute content_type.
5 6 7 |
# File 'lib/t_bird/uploader.rb', line 5 def content_type @content_type end |
#file ⇒ Object (readonly)
Returns the value of attribute file.
5 6 7 |
# File 'lib/t_bird/uploader.rb', line 5 def file @file end |
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
5 6 7 |
# File 'lib/t_bird/uploader.rb', line 5 def end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
5 6 7 |
# File 'lib/t_bird/uploader.rb', line 5 def end |
#original_filename ⇒ Object (readonly)
Returns the value of attribute original_filename.
5 6 7 |
# File 'lib/t_bird/uploader.rb', line 5 def original_filename @original_filename end |
#uploads ⇒ Object (readonly)
Returns the value of attribute uploads.
5 6 7 |
# File 'lib/t_bird/uploader.rb', line 5 def uploads @uploads end |
Class Method Details
.version(name, &block) ⇒ Object
46 47 48 49 |
# File 'lib/t_bird/uploader.rb', line 46 def self.version(name, &block) @versions ||= {} @versions[name.to_sym] = block end |
.versions ⇒ Object
39 40 41 42 43 44 |
# File 'lib/t_bird/uploader.rb', line 39 def self.versions @versions ||= { thumbnail: ->(img) { img.thumbnail }, original: ->(img) { img.original } } end |
Instance Method Details
#namer ⇒ Object
16 17 18 |
# File 'lib/t_bird/uploader.rb', line 16 def namer @namer ||= Namer.new(original_filename, [:identifier], [:token]) end |
#processor ⇒ Object
20 21 22 |
# File 'lib/t_bird/uploader.rb', line 20 def processor Processor.new(@file[:tempfile]) end |
#transmitter ⇒ Object
24 25 26 |
# File 'lib/t_bird/uploader.rb', line 24 def transmitter @transmitter ||= Transmitter.new end |
#upload! ⇒ Object
28 29 30 31 32 33 |
# File 'lib/t_bird/uploader.rb', line 28 def upload! versions.each do |version,block| @uploads[version] = transmitter.transmit!(namer.new_name(version), block.call(processor), ) end uploads end |
#versions ⇒ Object
35 36 37 |
# File 'lib/t_bird/uploader.rb', line 35 def versions self.class.versions end |