Class: Flags::FlagValidator

Inherits:
Object
  • Object
show all
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.

Instance Method Summary collapse

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, error_message)
  @proc = proc
  @error_message = 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