module Shrine::Plugins::Model::AttacherMethods

  1. lib/shrine/plugins/model.rb

Methods

Public Class

  1. new

Public Instance

  1. load_model
  2. model_assign
  3. set
  4. set_model
  5. write

Public Class methods

new(model_cache: shrine_class.opts[:model][:cache], **options)
[show source]
   # File lib/shrine/plugins/model.rb
93 def initialize(model_cache: shrine_class.opts[:model][:cache], **options)
94   super(**options)
95   @model_cache = model_cache
96   @model       = nil
97 end

Public Instance methods

load_model(record, name)

Saves record and name and initializes attachment from the model attribute. Called from Attacher.from_model.

[show source]
    # File lib/shrine/plugins/model.rb
101 def load_model(record, name)
102   set_model(record, name)
103   read
104 end
model_assign(value, **options)

Called by the attachment attribute setter on the model.

[show source]
    # File lib/shrine/plugins/model.rb
114 def model_assign(value, **options)
115   if model_cache?
116     assign(value, **options)
117   else
118     attach(value, **options)
119   end
120 end
set(*)

Writes uploaded file data into the model.

[show source]
    # File lib/shrine/plugins/model.rb
123 def set(*)
124   result = super
125   write if model?
126   result
127 end
set_model(record, name)

Saves record and name without loading attachment from the model attribute.

[show source]
    # File lib/shrine/plugins/model.rb
108 def set_model(record, name)
109   set_entity(record, name)
110   @model = true
111 end
write()

Writes the attachment data into the model attribute.

[show source]
    # File lib/shrine/plugins/model.rb
130 def write
131   column_values.each do |name, value|
132     write_attribute(name, value)
133   end
134 end