module Shrine::Plugins::StoreDimensions::ClassMethods

  1. lib/shrine/plugins/store_dimensions.rb

Public Instance Aliases

dimensions -> extract_dimensions

Public Instance methods

dimensions_analyzer (name)

Returns callable dimensions analyzer object.

[show source]
   # File lib/shrine/plugins/store_dimensions.rb
57 def dimensions_analyzer(name)
58   on_error = opts[:store_dimensions][:on_error]
59 
60   DimensionsAnalyzer.new(name, on_error: on_error).method(:call)
61 end
dimensions_analyzers ()

Returns a hash of built-in dimensions analyzers, where keys are analyzer names and values are #call-able objects which accepts the IO object.

[show source]
   # File lib/shrine/plugins/store_dimensions.rb
50 def dimensions_analyzers
51   @dimensions_analyzers ||= DimensionsAnalyzer::SUPPORTED_TOOLS.inject({}) do |hash, tool|
52     hash.merge!(tool => dimensions_analyzer(tool))
53   end
54 end
extract_dimensions (io)

Determines the dimensions of the IO object by calling the specified analyzer.

[show source]
   # File lib/shrine/plugins/store_dimensions.rb
35 def extract_dimensions(io)
36   analyzer = opts[:store_dimensions][:analyzer]
37   analyzer = dimensions_analyzer(analyzer) if analyzer.is_a?(Symbol)
38   args = [io, dimensions_analyzers].take(analyzer.arity.abs)
39 
40   dimensions = instrument_dimensions(io) { analyzer.call(*args) }
41   io.rewind
42 
43   dimensions
44 end