Class: ImageFlux::Option
- Inherits:
-
Object
- Object
- ImageFlux::Option
- Defined in:
- lib/image_flux/option.rb
Constant Summary collapse
- ALLOWED_FORMATS =
output attributes
%w[auto jpg png gif webp:jpeg webp:png webp:auto]
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Option
constructor
A new instance of Option.
- #prefix_path ⇒ Object
- #to_query(ignore_default: true) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Option
Returns a new instance of Option.
88 89 90 91 92 93 94 95 96 |
# File 'lib/image_flux/option.rb', line 88 def initialize( = {}) @values = {} .each_pair do |key, val| key = key.to_s.to_sym attribute = self.class.key_pairs[key] @values[attribute] = val if attribute end end |
Class Method Details
.attribute(name, type, options = {}, &block) ⇒ Object
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/image_flux/option.rb', line 16 def self.attribute(name, type, = {}, &block) attribute = ImageFlux::Attribute.new(name, type, ) attribute.instance_eval(&block) if block_given? key_pairs[attribute.name] = attribute attribute.aliases.each do |key| key_pairs[key] = attribute end attributes.push(attribute) end |
.attributes ⇒ Object
8 9 10 |
# File 'lib/image_flux/option.rb', line 8 def self.attributes @attributes ||= [] end |
.key_pairs ⇒ Object
12 13 14 |
# File 'lib/image_flux/option.rb', line 12 def self.key_pairs @key_pairs ||= {} end |
Instance Method Details
#prefix_path ⇒ Object
98 99 100 101 |
# File 'lib/image_flux/option.rb', line 98 def prefix_path prefix_attr = self.class.key_pairs[:prefix] @values[prefix_attr] end |
#to_query(ignore_default: true) ⇒ Object
103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/image_flux/option.rb', line 103 def to_query(ignore_default: true) errors = [] queries = @values.to_a.map do |pair| attribute = pair.first value = pair.last errors.concat(attribute.validate!(value)) attribute.querize(value) end raise ImageFlux::InvalidOptionError, errors.join(', ') unless errors.length.zero? queries.reject(&:nil?).join(',') end |