Class: Flags::FlagValidator
- Inherits:
-
Object
- Object
- Flags::FlagValidator
- Defined in:
- lib/flags.rb
Overview
A FlagValidator can check whether a flag’s value is valid (with validity implicitly defined via a provided callback), and raise an error if the validation check fails.
Direct Known Subclasses
AllowedValuesValidator, ClassValidator, DisallowedValuesValidator, RangeValidator
Instance Method Summary collapse
-
#initialize(proc, error_message) ⇒ FlagValidator
constructor
A new instance of FlagValidator.
- #validate!(flag_name, flag_value) ⇒ Object
Constructor Details
#initialize(proc, error_message) ⇒ FlagValidator
Returns a new instance of FlagValidator.
364 365 366 367 |
# File 'lib/flags.rb', line 364 def initialize(proc, ) @proc = proc @error_message = end |
Instance Method Details
#validate!(flag_name, flag_value) ⇒ Object
369 370 371 |
# File 'lib/flags.rb', line 369 def validate!(flag_name, flag_value) raise InvalidFlagValueError.new(flag_name, flag_value, @error_message) unless @proc.call(flag_value) end |