module Shrine::Plugins::AddMetadata::InstanceMethods

  1. lib/shrine/plugins/add_metadata.rb

Methods

Public Instance

  1. extract_metadata

Public Instance methods

extract_metadata (io, context)
[show source]
# File lib/shrine/plugins/add_metadata.rb, line 72
def extract_metadata(io, context)
  metadata = super

  opts[:metadata].each do |metadata_block|
    custom_metadata = instance_exec(io, context, &metadata_block) || {}
    io.rewind
    # convert symbol keys to strings
    custom_metadata.keys.each do |key|
      custom_metadata[key.to_s] = custom_metadata.delete(key) if key.is_a?(Symbol)
    end
    metadata.merge!(custom_metadata)
  end

  metadata
end