Module: Fontisan::Converters::ConversionStrategy::ClassMethods
- Defined in:
- lib/fontisan/converters/conversion_strategy.rb
Overview
Class methods mixed into including classes via included.
Instance Method Summary collapse
-
#declared_options ⇒ Array<Option>
(also: #supported_options)
All options declared by this class.
-
#default_options ⇒ Hash{Symbol => Object}
Default values for every declared option.
-
#option(name, type:, default:, cli:, desc:, range: nil, values: nil) ⇒ void
Declare an option this strategy accepts.
-
#option_for(name) ⇒ Option?
Find the option schema for a given key (symbol or string).
-
#validate_options!(user_options) ⇒ void
Validate a user-provided options hash against this strategy's schema.
Instance Method Details
#declared_options ⇒ Array<Option> Also known as: supported_options
All options declared by this class.
70 71 72 |
# File 'lib/fontisan/converters/conversion_strategy.rb', line 70 def @declared_options ||= [] end |
#default_options ⇒ Hash{Symbol => Object}
Default values for every declared option.
88 89 90 |
# File 'lib/fontisan/converters/conversion_strategy.rb', line 88 def .to_h { |o| [o.name, o.default] } end |
#option(name, type:, default:, cli:, desc:, range: nil, values: nil) ⇒ void
This method returns an undefined value.
Declare an option this strategy accepts.
60 61 62 63 64 65 |
# File 'lib/fontisan/converters/conversion_strategy.rb', line 60 def option(name, type:, default:, cli:, desc:, range: nil, values: nil) << Option.new( name: name, type: type, default: default, cli: cli, desc: desc, range: range, allowed_values: values ) end |
#option_for(name) ⇒ Option?
Find the option schema for a given key (symbol or string).
81 82 83 |
# File 'lib/fontisan/converters/conversion_strategy.rb', line 81 def option_for(name) .find { |o| o.name == name.to_sym } end |
#validate_options!(user_options) ⇒ void
This method returns an undefined value.
Validate a user-provided options hash against this strategy's schema.
Raises ArgumentError for any unknown key, wrong type, or
out-of-range value. Called by FormatConverter after strategy
selection, so cross-format misuse (e.g., --zlib-level on a
WOFF2 conversion) is caught here.
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/fontisan/converters/conversion_strategy.rb', line 102 def () .each_key do |key| opt = option_for(key) next if opt names = .map(&:name) list = names.empty? ? "(none)" : names.join(", ") raise ArgumentError, "Unknown option #{key.inspect} for #{name}. " \ "Supported: #{list}" end .each do |key, value| opt = option_for(key) validate_option_value!(opt, value) unless value.nil? end end |