Module: Attachs::Attachment::Attributes
- Extended by:
- ActiveSupport::Concern
- Included in:
- Attachs::Attachment
- Defined in:
- lib/attachs/attachment/attributes.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
87
88
89
90
91
92
93
|
# File 'lib/attachs/attachment/attributes.rb', line 87
def method_missing(name, *args, &block)
if attributes.has_key?(name)
attributes[name]
else
super
end
end
|
Instance Attribute Details
#attributes ⇒ Object
Returns the value of attribute attributes.
6
7
8
|
# File 'lib/attachs/attachment/attributes.rb', line 6
def attributes
@attributes
end
|
#options ⇒ Object
Returns the value of attribute options.
6
7
8
|
# File 'lib/attachs/attachment/attributes.rb', line 6
def options
@options
end
|
#original_attributes ⇒ Object
Returns the value of attribute original_attributes.
6
7
8
|
# File 'lib/attachs/attachment/attributes.rb', line 6
def original_attributes
@original_attributes
end
|
#record ⇒ Object
Returns the value of attribute record.
6
7
8
|
# File 'lib/attachs/attachment/attributes.rb', line 6
def record
@record
end
|
#record_attribute ⇒ Object
Returns the value of attribute record_attribute.
6
7
8
|
# File 'lib/attachs/attachment/attributes.rb', line 6
def record_attribute
@record_attribute
end
|
#source ⇒ Object
Returns the value of attribute source.
6
7
8
|
# File 'lib/attachs/attachment/attributes.rb', line 6
def source
@source
end
|
#value ⇒ Object
Returns the value of attribute value.
6
7
8
|
# File 'lib/attachs/attachment/attributes.rb', line 6
def value
@value
end
|
Instance Method Details
#basename ⇒ Object
21
22
23
24
25
|
# File 'lib/attachs/attachment/attributes.rb', line 21
def basename
if filename
File.basename filename, extension
end
end
|
#blank? ⇒ Boolean
37
38
39
|
# File 'lib/attachs/attachment/attributes.rb', line 37
def blank?
!present?
end
|
#changed? ⇒ Boolean
45
46
47
|
# File 'lib/attachs/attachment/attributes.rb', line 45
def changed?
@original_attributes != @attributes
end
|
#extension ⇒ Object
27
28
29
30
31
|
# File 'lib/attachs/attachment/attributes.rb', line 27
def extension
if filename
File.extname filename
end
end
|
#initialize(record, record_attribute, options = {}, attributes = {}) ⇒ Object
8
9
10
11
12
13
|
# File 'lib/attachs/attachment/attributes.rb', line 8
def initialize(record, record_attribute, options={}, attributes={})
@record = record
@record_attribute = record_attribute
@options = options
@original_attributes = @attributes = normalize_attributes(attributes)
end
|
#persisted? ⇒ Boolean
41
42
43
|
# File 'lib/attachs/attachment/attributes.rb', line 41
def persisted?
record.persisted? && paths.any? && uploaded_at
end
|
#position ⇒ Object
59
60
61
62
63
|
# File 'lib/attachs/attachment/attributes.rb', line 59
def position
if options[:multiple]
attributes[:position]
end
end
|
#position=(value) ⇒ Object
65
66
67
68
69
70
|
# File 'lib/attachs/attachment/attributes.rb', line 65
def position=(value)
if options[:multiple]
attributes[:position] = value
write_record
end
end
|
#present? ⇒ Boolean
33
34
35
|
# File 'lib/attachs/attachment/attributes.rb', line 33
def present?
filename.present? && content_type.present? && size.present?
end
|
#respond_to_missing?(name, include_private = false) ⇒ Boolean
83
84
85
|
# File 'lib/attachs/attachment/attributes.rb', line 83
def respond_to_missing?(name, include_private=false)
attributes.has_key?(name) || super
end
|
#styles ⇒ Object
72
73
74
75
76
77
78
79
80
81
|
# File 'lib/attachs/attachment/attributes.rb', line 72
def styles
case value = options[:styles]
when Proc
value.call(record) || {}
when Hash
value
else
{}
end
end
|
#type ⇒ Object
49
50
51
52
53
54
55
56
57
|
# File 'lib/attachs/attachment/attributes.rb', line 49
def type
if content_type
if content_type.starts_with?('image/')
'image'
else
'file'
end
end
end
|