Module: Shrine::Plugins::MetadataAttributes::AttacherMethods

Defined in:
lib/shrine/plugins/metadata_attributes.rb

Instance Method Summary collapse

Instance Method Details

#assign(value, **options) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/shrine/plugins/metadata_attributes.rb', line 21

def assign(value, **options)
  super
  cached_file = get

  shrine_class.opts[:metadata_attributes_mappings].each do |source, destination|
    attribute_name = destination.is_a?(Symbol) ? :"#{name}_#{destination}" : :"#{destination}"

    next unless record.respond_to?(:"#{attribute_name}=")

    if cached_file
      record.send(:"#{attribute_name}=", cached_file.[source.to_s])
    else
      record.send(:"#{attribute_name}=", nil)
    end
  end
end