module Shrine::Plugins::StoreDimensions::ClassMethods

Public Instance Methods

dimensions(io)
Alias for: extract_dimensions
dimensions_analyzer(name) click to toggle source

Returns callable dimensions analyzer object.

# 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_analyzers() click to toggle source

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

# 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) click to toggle source

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

# 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
Also aliased as: dimensions

Private Instance Methods

instrument_dimensions(io) { || ... } click to toggle source

Sends a ‘image_dimensions.shrine` event for instrumentation plugin.

# File lib/shrine/plugins/store_dimensions.rb, line 66
def instrument_dimensions(io, &block)
  return yield unless respond_to?(:instrument)

  instrument(:image_dimensions, io: io, &block)
end