Module: Shrine::Plugins::StoreDimensions::ClassMethods

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

Instance Method Summary collapse

Instance Method Details

#dimensions_analyzer(name) ⇒ Object

Returns callable dimensions analyzer object.



57
58
59
60
61
# File 'lib/shrine/plugins/store_dimensions.rb', line 57

def dimensions_analyzer(name)
  on_error = opts[:store_dimensions][:on_error]

  DimensionsAnalyzer.new(name, on_error: on_error).method(:call)
end

#dimensions_analyzersObject

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



50
51
52
53
54
# File 'lib/shrine/plugins/store_dimensions.rb', line 50

def dimensions_analyzers
  @dimensions_analyzers ||= DimensionsAnalyzer::SUPPORTED_TOOLS.inject({}) do |hash, tool|
    hash.merge!(tool => dimensions_analyzer(tool))
  end
end

#extract_dimensions(io) ⇒ Object Also known as: dimensions

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



35
36
37
38
39
40
41
42
43
44
# File 'lib/shrine/plugins/store_dimensions.rb', line 35

def extract_dimensions(io)
  analyzer = opts[:store_dimensions][:analyzer]
  analyzer = dimensions_analyzer(analyzer) if analyzer.is_a?(Symbol)
  args = [io, dimensions_analyzers].take(analyzer.arity.abs)

  dimensions = instrument_dimensions(io) { analyzer.call(*args) }
  io.rewind

  dimensions
end