module Shrine::Plugins::Entity::AttacherMethods

  1. lib/shrine/plugins/entity.rb

Attributes

name [R]
record [R]

Public Instance methods

attribute()

Returns the entity attribute name used for reading and writing attachment data.

attacher = Shrine::Attacher.from_entity(photo, :image)
attacher.attribute #=> :image_data
[show source]
    # File lib/shrine/plugins/entity.rb
143 def attribute
144   :"#{name}_data" if name
145 end
column_values()

Returns a hash with entity attribute name and column data.

attacher.column_values
#=> { image_data: '{"id":"...","storage":"...","metadata":{...}}' }
[show source]
    # File lib/shrine/plugins/entity.rb
134 def column_values
135   { attribute => column_data }
136 end
load_entity(record, name)

Saves record and name and initializes attachment from the entity attribute. Called from Attacher.from_entity.

[show source]
   # File lib/shrine/plugins/entity.rb
96 def load_entity(record, name)
97   set_entity(record, name)
98   read
99 end
read()

Loads attachment from the entity attribute.

[show source]
    # File lib/shrine/plugins/entity.rb
126 def read
127   load_column(read_attribute)
128 end
reload()

Overwrites the current attachment with the one from model attribute.

photo.image_data #=> nil
attacher = Shrine::Attacher.from_entity(photo, :image)
photo.image_data = uploaded_file.to_json

attacher.file #=> nil
attacher.reload
attacher.file #=> #<Shrine::UploadedFile>
[show source]
    # File lib/shrine/plugins/entity.rb
119 def reload
120   read
121   @previous = nil
122   self
123 end
set_entity(record, name)

Sets record and name without loading the attachment from the entity attribute.

[show source]
    # File lib/shrine/plugins/entity.rb
103 def set_entity(record, name)
104   @record = record
105   @name   = name.to_sym
106 
107   @context.merge!(record: record, name: name)
108 end