Class: Flags::DisallowedValuesValidator

Inherits:
FlagValidator show all
Defined in:
lib/flags.rb

Overview

A validator that raises an error if the flag’s value is in the provided set of disallowed values.

Instance Method Summary collapse

Methods inherited from FlagValidator

#validate!

Constructor Details

#initialize(*disallowed_values) ⇒ DisallowedValuesValidator

Returns a new instance of DisallowedValuesValidator.



406
407
408
409
410
411
# File 'lib/flags.rb', line 406

def initialize(*disallowed_values)
  disallowed_values = disallowed_values.to_a.flatten
  proc = Proc.new { |flag_value| !disallowed_values.include?(flag_value) }
  error_message = "illegal value, may not be one of [#{disallowed_values.join(',')}]"
  super(proc, error_message)
end