Module: Shrine::Plugins::InferExtension::ClassMethods

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

Instance Method Summary collapse

Instance Method Details

#extension_inferrer(name) ⇒ Object


39
40
41
# File 'lib/shrine/plugins/infer_extension.rb', line 39

def extension_inferrer(name)
  ExtensionInferrer.new(name).method(:call)
end

#extension_inferrersObject


33
34
35
36
37
# File 'lib/shrine/plugins/infer_extension.rb', line 33

def extension_inferrers
  @extension_inferrers ||= ExtensionInferrer::SUPPORTED_TOOLS.inject({}) do |hash, tool|
    hash.merge!(tool => extension_inferrer(tool))
  end
end

#infer_extension(mime_type) ⇒ Object


25
26
27
28
29
30
31
# File 'lib/shrine/plugins/infer_extension.rb', line 25

def infer_extension(mime_type)
  inferrer = opts[:infer_extension][:inferrer]
  inferrer = extension_inferrer(inferrer) if inferrer.is_a?(Symbol)
  args     = [mime_type, extension_inferrers].take(inferrer.arity.abs)

  instrument_extension(mime_type) { inferrer.call(*args) }
end