Class: Imgproxy::OptionsBuilders::Base

Inherits:
Hash
  • Object
show all
Defined in:
lib/imgproxy/options_builders/base.rb

Overview

Formats and regroups URL options

Direct Known Subclasses

Info, Processing

Constant Summary collapse

CASTERS =

Hash of options casters. Redefine this in subclases

{}.freeze
META =

Array of meta-options names. Redefine this in subclases

[].freeze

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Base

Returns a new instance of Base.

Parameters:

  • options (Hash)

    raw options



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/imgproxy/options_builders/base.rb', line 17

def initialize(options)
  super()

  # Options order hack: initialize known and meta options with nil value to preserve order
  self.class::CASTERS.each_key do |n|
    self[n] = nil if options.key?(n) || self.class::META.include?(n)
  end

  options.each do |name, value|
    caster = self.class::CASTERS[name]
    self[name] = caster ? caster.cast(value) : unwrap_hash(value)
  end

  group_opts

  compact!
end