Class: TBird::Uploader

Inherits:
Object
  • Object
show all
Defined in:
lib/t_bird/uploader.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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, options = {})
  @file = file
  @acl = options.fetch(:acl, :public_read)
  @options = default_options.merge(options)
  @uploads = {}
  @content_type = @file[:type]
  @original_filename = @file[:filename]
   = { acl: acl, content_type: content_type, metadata: @options[:metadata] || {} }
end

Instance Attribute Details

#aclObject (readonly)

Returns the value of attribute acl.



5
6
7
# File 'lib/t_bird/uploader.rb', line 5

def acl
  @acl
end

#content_typeObject (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

#fileObject (readonly)

Returns the value of attribute file.



5
6
7
# File 'lib/t_bird/uploader.rb', line 5

def file
  @file
end

#metadataObject (readonly)

Returns the value of attribute metadata.



5
6
7
# File 'lib/t_bird/uploader.rb', line 5

def 
  
end

#optionsObject (readonly)

Returns the value of attribute options.



5
6
7
# File 'lib/t_bird/uploader.rb', line 5

def options
  @options
end

#original_filenameObject (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

#uploadsObject (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

.versionsObject



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

#namerObject



16
17
18
# File 'lib/t_bird/uploader.rb', line 16

def namer
  @namer ||= Namer.new(original_filename, options[:identifier], options[:token])
end

#processorObject



20
21
22
# File 'lib/t_bird/uploader.rb', line 20

def processor
  Processor.new(@file[:tempfile])
end

#transmitterObject



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

#versionsObject



35
36
37
# File 'lib/t_bird/uploader.rb', line 35

def versions
  self.class.versions
end