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, line 51
def assign(value)
  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.metadata[source.to_s])
    else
      record.send(:"#{attribute_name}=", nil)
    end
  end
end