Module: Shrine::Plugins::Entity::AttacherMethods
- Defined in:
- lib/shrine/plugins/entity.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#record ⇒ Object
readonly
Returns the value of attribute record.
Instance Method Summary collapse
-
#attribute ⇒ Object
Returns the entity attribute name used for reading and writing attachment data.
-
#column_values ⇒ Object
Returns a hash with entity attribute name and column data.
-
#load_entity(record, name) ⇒ Object
Saves record and name and initializes attachment from the entity attribute.
-
#read ⇒ Object
Loads attachment from the entity attribute.
-
#reload ⇒ Object
Overwrites the current attachment with the one from model attribute.
-
#set_entity(record, name) ⇒ Object
Sets record and name without loading the attachment from the entity attribute.
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
92 93 94 |
# File 'lib/shrine/plugins/entity.rb', line 92 def name @name end |
#record ⇒ Object (readonly)
Returns the value of attribute record.
92 93 94 |
# File 'lib/shrine/plugins/entity.rb', line 92 def record @record end |
Instance Method Details
#attribute ⇒ Object
143 144 145 |
# File 'lib/shrine/plugins/entity.rb', line 143 def attribute :"#{name}_data" if name end |
#column_values ⇒ Object
Returns a hash with entity attribute name and column data.
attacher.column_values
#=> { image_data: '{"id":"...","storage":"...","metadata":{...}}' }
134 135 136 |
# File 'lib/shrine/plugins/entity.rb', line 134 def column_values { attribute => column_data } end |
#load_entity(record, name) ⇒ Object
Saves record and name and initializes attachment from the entity attribute. Called from ‘Attacher.from_entity`.
96 97 98 99 |
# File 'lib/shrine/plugins/entity.rb', line 96 def load_entity(record, name) set_entity(record, name) read end |
#read ⇒ Object
Loads attachment from the entity attribute.
126 127 128 |
# File 'lib/shrine/plugins/entity.rb', line 126 def read load_column(read_attribute) end |
#reload ⇒ Object
119 120 121 122 123 |
# File 'lib/shrine/plugins/entity.rb', line 119 def reload read @previous = nil self end |
#set_entity(record, name) ⇒ Object
Sets record and name without loading the attachment from the entity attribute.
103 104 105 106 107 108 |
# File 'lib/shrine/plugins/entity.rb', line 103 def set_entity(record, name) @record = record @name = name.to_sym @context.merge!(record: record, name: name) end |