module Shrine::Plugins::MetadataAttributes::AttacherMethods

  1. lib/shrine/plugins/metadata_attributes.rb

Methods

Public Instance

  1. assign

Public Instance methods

assign (value)
[show source]
   # File lib/shrine/plugins/metadata_attributes.rb
21 def assign(value)
22   super
23   cached_file = get
24 
25   shrine_class.opts[:metadata_attributes_mappings].each do |source, destination|
26     attribute_name = destination.is_a?(Symbol) ? :"#{name}_#{destination}" : :"#{destination}"
27 
28     next unless record.respond_to?(:"#{attribute_name}=")
29 
30     if cached_file
31       record.send(:"#{attribute_name}=", cached_file.metadata[source.to_s])
32     else
33       record.send(:"#{attribute_name}=", nil)
34     end
35   end
36 end