Class: AttachmentField
- Inherits:
-
Field
- Object
- Field
- AttachmentField
show all
- Defined in:
- lib/yodel/models/core/fields/attachment_field.rb
Constant Summary
Constants inherited
from Field
Field::TYPES
Instance Attribute Summary
Attributes inherited from Field
#name, #options
Instance Method Summary
collapse
Methods inherited from Field
#display?, field_from_type, from_options, #include_in_search_keywords?, #index?, #inherited?, #initialize, #method_missing, #numeric?, #required?, #searchable?, #strip_nil?, #to_json, #to_str, #unique?, #validate
Constructor Details
This class inherits a constructor from Field
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
in the class Field
Instance Method Details
#after_destroy(record) ⇒ Object
39
40
41
42
43
|
# File 'lib/yodel/models/core/fields/attachment_field.rb', line 39
def after_destroy(record)
if record.get(name).is_a?(Attachment)
record.get(name).remove_files
end
end
|
#default ⇒ Object
6
7
8
|
# File 'lib/yodel/models/core/fields/attachment_field.rb', line 6
def default
Attachment.new({}, nil, self).to_hash
end
|
2
3
4
|
# File 'lib/yodel/models/core/fields/attachment_field.rb', line 2
def default_input_type
:file
end
|
#from_json(value, record) ⇒ Object
33
34
35
36
37
|
# File 'lib/yodel/models/core/fields/attachment_field.rb', line 33
def from_json(value, record)
original = record.get(name)
original.set_file(value)
original
end
|
#json_action(action, value, record) ⇒ Object
19
20
21
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/yodel/models/core/fields/attachment_field.rb', line 19
def json_action(action, value, record)
original = record.get(name)
case action
when 'set'
return if value.nil?
original.set_file(value)
record.set_raw(name, original.to_hash)
when 'clear'
original.remove_files
record.set_raw(name, nil)
end
record.changed!(name)
end
|
#typecast(value, record) ⇒ Object
15
16
17
|
# File 'lib/yodel/models/core/fields/attachment_field.rb', line 15
def typecast(value, record)
Attachment.new(value, record, self)
end
|
#untypecast(value, record) ⇒ Object
10
11
12
13
|
# File 'lib/yodel/models/core/fields/attachment_field.rb', line 10
def untypecast(value, record)
value.to_hash
end
|