Module: Shrine::Plugins::StoreDimensions::ClassMethods
- Defined in:
- lib/shrine/plugins/store_dimensions.rb
Instance Method Summary collapse
-
#dimensions_analyzer(name) ⇒ Object
Returns callable dimensions analyzer object.
-
#dimensions_analyzers ⇒ Object
Returns a hash of built-in dimensions analyzers, where keys are analyzer names and values are ‘#call`-able objects which accepts the IO object.
-
#extract_dimensions(io) ⇒ Object
(also: #dimensions)
Determines the dimensions of the IO object by calling the specified analyzer.
Instance Method Details
#dimensions_analyzer(name) ⇒ Object
Returns callable dimensions analyzer object.
61 62 63 64 65 |
# File 'lib/shrine/plugins/store_dimensions.rb', line 61 def dimensions_analyzer(name) on_error = opts[:store_dimensions][:on_error] DimensionsAnalyzer.new(name, on_error: on_error).method(:call) end |
#dimensions_analyzers ⇒ Object
Returns a hash of built-in dimensions analyzers, where keys are analyzer names and values are ‘#call`-able objects which accepts the IO object.
54 55 56 57 58 |
# File 'lib/shrine/plugins/store_dimensions.rb', line 54 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.
39 40 41 42 43 44 45 46 47 48 |
# File 'lib/shrine/plugins/store_dimensions.rb', line 39 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 |