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.
-
#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.
86 87 88 |
# File 'lib/shrine/plugins/entity.rb', line 86 def name @name end |
#record ⇒ Object (readonly)
Returns the value of attribute record.
86 87 88 |
# File 'lib/shrine/plugins/entity.rb', line 86 def record @record end |
Instance Method Details
#attribute ⇒ Object
131 132 133 |
# File 'lib/shrine/plugins/entity.rb', line 131 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":{...}}' }
122 123 124 |
# File 'lib/shrine/plugins/entity.rb', line 122 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`.
90 91 92 93 |
# File 'lib/shrine/plugins/entity.rb', line 90 def load_entity(record, name) set_entity(record, name) read end |
#reload ⇒ Object
113 114 115 116 |
# File 'lib/shrine/plugins/entity.rb', line 113 def reload read self end |
#set_entity(record, name) ⇒ Object
Sets record and name without loading the attachment from the entity attribute.
97 98 99 100 101 102 |
# File 'lib/shrine/plugins/entity.rb', line 97 def set_entity(record, name) @record = record @name = name.to_sym @context.merge!(record: record, name: name) end |