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.



22
23
24
25
26
# File 'lib/attachie.rb', line 22

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



92
93
94
95
96
# File 'lib/attachie.rb', line 92

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.



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

def attachment
  @attachment
end

#nameObject

Returns the value of attribute name.



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

def name
  @name
end

#optionsObject

Returns the value of attribute options.



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

def options
  @options
end

Instance Method Details

#containerObject Also known as: bucket



44
45
46
# File 'lib/attachie.rb', line 44

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

#deleteObject



76
77
78
# File 'lib/attachie.rb', line 76

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

#download(dest_path) ⇒ Object



64
65
66
# File 'lib/attachie.rb', line 64

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

#exists?Boolean

Returns:

  • (Boolean)


80
81
82
# File 'lib/attachie.rb', line 80

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

#infoObject



68
69
70
# File 'lib/attachie.rb', line 68

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

#inspectObject



84
85
86
# File 'lib/attachie.rb', line 84

def inspect
  to_s
end

#objectObject



88
89
90
# File 'lib/attachie.rb', line 88

def object
  attachment.object
end

#pathObject



36
37
38
# File 'lib/attachie.rb', line 36

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

#path_without_prefixObject



40
41
42
# File 'lib/attachie.rb', line 40

def path_without_prefix
  interpolate option(:path)
end

#presigned_post(options = {}) ⇒ Object



28
29
30
# File 'lib/attachie.rb', line 28

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

#respond_to_missing?(method_name, *args) ⇒ Boolean

Returns:

  • (Boolean)


98
99
100
# File 'lib/attachie.rb', line 98

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

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



60
61
62
# File 'lib/attachie.rb', line 60

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

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



72
73
74
# File 'lib/attachie.rb', line 72

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

#temp_url(opts = {}) ⇒ Object



50
51
52
53
54
# File 'lib/attachie.rb', line 50

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

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

#urlObject



32
33
34
# File 'lib/attachie.rb', line 32

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



56
57
58
# File 'lib/attachie.rb', line 56

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