Class: Attachie::Attachment::Version

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attachment, name, options) ⇒ Version

Returns a new instance of Version.



20
21
22
23
24
# File 'lib/attachie.rb', line 20

def initialize(attachment, name, options)
  self.attachment = attachment
  self.name = name
  self.options = options
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, &block) ⇒ Object



90
91
92
93
94
# File 'lib/attachie.rb', line 90

def method_missing(method_name, *args, &block)
  return attachment.options[:versions][name][method_name.to_sym] if attachment.options[:versions][name].key?(method_name.to_sym)

  super
end

Instance Attribute Details

#attachmentObject

Returns the value of attribute attachment.



18
19
20
# File 'lib/attachie.rb', line 18

def attachment
  @attachment
end

#nameObject

Returns the value of attribute name.



18
19
20
# File 'lib/attachie.rb', line 18

def name
  @name
end

#optionsObject

Returns the value of attribute options.



18
19
20
# File 'lib/attachie.rb', line 18

def options
  @options
end

Instance Method Details

#containerObject Also known as: bucket



42
43
44
# File 'lib/attachie.rb', line 42

def container
  interpolate option(:container) || option(:bucket)
end

#deleteObject



74
75
76
# File 'lib/attachie.rb', line 74

def delete
  option(:driver).delete(path, container)
end

#download(dest_path) ⇒ Object



62
63
64
# File 'lib/attachie.rb', line 62

def download(dest_path)
  option(:driver).download(path, container, dest_path)
end

#exists?Boolean

Returns:

  • (Boolean)


78
79
80
# File 'lib/attachie.rb', line 78

def exists?
  option(:driver).exists?(path, container)
end

#infoObject



66
67
68
# File 'lib/attachie.rb', line 66

def info
  option(:driver).info(path, container)
end

#inspectObject



82
83
84
# File 'lib/attachie.rb', line 82

def inspect
  to_s
end

#objectObject



86
87
88
# File 'lib/attachie.rb', line 86

def object
  attachment.object
end

#pathObject



34
35
36
# File 'lib/attachie.rb', line 34

def path
  "#{interpolate(option(:path_prefix)) + "/" if option(:path_prefix)}#{path_without_prefix}"
end

#path_without_prefixObject



38
39
40
# File 'lib/attachie.rb', line 38

def path_without_prefix
  interpolate option(:path)
end

#presigned_post(options = {}) ⇒ Object



26
27
28
# File 'lib/attachie.rb', line 26

def presigned_post(options = {})
  option(:driver).presigned_post(path, container, options)
end

#respond_to_missing?(method_name, *args) ⇒ Boolean

Returns:

  • (Boolean)


96
97
98
# File 'lib/attachie.rb', line 96

def respond_to_missing?(method_name, *args)
  attachment.options[:versions][name].key?(method_name.to_sym)
end

#store(data_or_io, opts = {}) ⇒ Object



58
59
60
# File 'lib/attachie.rb', line 58

def store(data_or_io, opts = {})
  option(:driver).store(path, data_or_io, container, opts)
end

#store_multipart(opts = {}, &block) ⇒ Object



70
71
72
# File 'lib/attachie.rb', line 70

def store_multipart(opts = {}, &block)
  option(:driver).store_multipart(path, container, opts, &block)
end

#temp_url(opts = {}) ⇒ Object



48
49
50
51
52
# File 'lib/attachie.rb', line 48

def temp_url(opts = {})
  return url unless option(:driver).respond_to?(:temp_url)

  option(:driver).temp_url(path, container, opts)
end

#urlObject



30
31
32
# File 'lib/attachie.rb', line 30

def url
  "#{interpolate option(:protocol)}://#{interpolate option(:host)}/#{interpolate(option(:url_prefix)).to_s + "/" if option(:url_prefix)}#{path}#{interpolate(option(:url_suffix)) if option(:url_suffix)}"
end

#valueObject



54
55
56
# File 'lib/attachie.rb', line 54

def value
  option(:driver).value(path, container)
end