Class: Attachs::Attachment
- Inherits:
-
Object
- Object
- Attachs::Attachment
- Defined in:
- lib/attachs/attachment.rb
Instance Attribute Summary collapse
-
#attribute ⇒ Object
readonly
Returns the value of attribute attribute.
-
#content_type ⇒ Object
readonly
Returns the value of attribute content_type.
-
#filename ⇒ Object
readonly
Returns the value of attribute filename.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#record ⇒ Object
readonly
Returns the value of attribute record.
-
#size ⇒ Object
readonly
Returns the value of attribute size.
-
#updated_at ⇒ Object
readonly
Returns the value of attribute updated_at.
-
#upload ⇒ Object
readonly
Returns the value of attribute upload.
Instance Method Summary collapse
- #blank? ⇒ Boolean
- #default? ⇒ Boolean
- #exists? ⇒ Boolean
-
#initialize(record, attribute, options, source = false) ⇒ Attachment
constructor
A new instance of Attachment.
- #private? ⇒ Boolean
- #processed? ⇒ Boolean
- #processors ⇒ Object
- #public? ⇒ Boolean
- #styles ⇒ Object
- #upload? ⇒ Boolean
- #uploaded! ⇒ Object
- #url? ⇒ Boolean
Constructor Details
#initialize(record, attribute, options, source = false) ⇒ Attachment
Returns a new instance of Attachment.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/attachs/attachment.rb', line 8 def initialize(record, attribute, , source=false) @record = record @attribute = attribute @options = case source when nil %w(filename content_type size updated_at).each do |name| record.send "#{attribute}_#{name}=", nil end when false %w(filename content_type size updated_at).each do |name| instance_variable_set :"@#{name}", record.send("#{attribute}_#{name}") end else load source %w(filename content_type size updated_at).each do |name| record.send "#{attribute}_#{name}=", send(name) end end end |
Instance Attribute Details
#attribute ⇒ Object (readonly)
Returns the value of attribute attribute.
4 5 6 |
# File 'lib/attachs/attachment.rb', line 4 def attribute @attribute end |
#content_type ⇒ Object (readonly)
Returns the value of attribute content_type.
4 5 6 |
# File 'lib/attachs/attachment.rb', line 4 def content_type @content_type end |
#filename ⇒ Object (readonly)
Returns the value of attribute filename.
4 5 6 |
# File 'lib/attachs/attachment.rb', line 4 def filename @filename end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
4 5 6 |
# File 'lib/attachs/attachment.rb', line 4 def @options end |
#record ⇒ Object (readonly)
Returns the value of attribute record.
4 5 6 |
# File 'lib/attachs/attachment.rb', line 4 def record @record end |
#size ⇒ Object (readonly)
Returns the value of attribute size.
4 5 6 |
# File 'lib/attachs/attachment.rb', line 4 def size @size end |
#updated_at ⇒ Object (readonly)
Returns the value of attribute updated_at.
4 5 6 |
# File 'lib/attachs/attachment.rb', line 4 def updated_at @updated_at end |
#upload ⇒ Object (readonly)
Returns the value of attribute upload.
4 5 6 |
# File 'lib/attachs/attachment.rb', line 4 def upload @upload end |
Instance Method Details
#blank? ⇒ Boolean
68 69 70 |
# File 'lib/attachs/attachment.rb', line 68 def blank? !exists? end |
#default? ⇒ Boolean
72 73 74 |
# File 'lib/attachs/attachment.rb', line 72 def default? ![:default_path].nil? end |
#exists? ⇒ Boolean
64 65 66 |
# File 'lib/attachs/attachment.rb', line 64 def exists? filename and content_type and size and updated_at end |
#private? ⇒ Boolean
37 38 39 |
# File 'lib/attachs/attachment.rb', line 37 def private? @private ||= [:private] == true end |
#processed? ⇒ Boolean
55 56 57 58 59 60 61 62 |
# File 'lib/attachs/attachment.rb', line 55 def processed? exists? and record.persisted? and !( record.send("#{attribute}_filename_changed?") or record.send("#{attribute}_content_type_changed?") or record.send("#{attribute}_size_changed?") or record.send("#{attribute}_updated_at_changed?") ) end |
#processors ⇒ Object
41 42 43 44 45 |
# File 'lib/attachs/attachment.rb', line 41 def processors @processors ||= ([:processors] || Attachs.config.default_processors).map do |processor| "Attachs::Processors::#{processor.to_s.classify}".constantize end end |
#public? ⇒ Boolean
47 48 49 |
# File 'lib/attachs/attachment.rb', line 47 def public? !private? end |
#styles ⇒ Object
33 34 35 |
# File 'lib/attachs/attachment.rb', line 33 def styles @styles ||= (([:styles] || []) | Attachs.config.global_styles) end |
#upload? ⇒ Boolean
51 52 53 |
# File 'lib/attachs/attachment.rb', line 51 def upload? !upload.nil? end |
#uploaded! ⇒ Object
29 30 31 |
# File 'lib/attachs/attachment.rb', line 29 def uploaded! @upload = nil end |
#url? ⇒ Boolean
76 77 78 |
# File 'lib/attachs/attachment.rb', line 76 def url? public? and (default? or processed?) end |