module Shrine::Plugins::Model::AttacherMethods
Public Class Methods
# File lib/shrine/plugins/model.rb 93 def initialize(model_cache: shrine_class.opts[:model][:cache], **) 94 super(**) 95 @model_cache = model_cache 96 @model = nil 97 end
Calls superclass method
Public Instance Methods
Source
# File lib/shrine/plugins/model.rb 101 def load_model(record, name) 102 set_model(record, name) 103 read 104 end
Saves record and name and initializes attachment from the model attribute. Called from Attacher.from_model.
Source
# File lib/shrine/plugins/model.rb 114 def model_assign(value, **) 115 if model_cache? 116 assign(value, **) 117 else 118 attach(value, **) 119 end 120 end
Called by the attachment attribute setter on the model.
Source
# File lib/shrine/plugins/model.rb 123 def set(*) 124 result = super 125 write 126 result 127 end
Writes uploaded file data into the model.
Calls superclass method
Source
# File lib/shrine/plugins/model.rb 108 def set_model(record, name) 109 set_entity(record, name) 110 @model = true 111 end
Saves record and name without loading attachment from the model attribute.
Source
# File lib/shrine/plugins/model.rb 131 def write 132 return unless model? 133 134 column_values.each do |name, value| 135 write_attribute(name, value) 136 end 137 end
Writes the attachment data into the model attribute. Does nothing when the attacher isnβt backed by a model instance.