Class: Flags::AllowedValuesValidator

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

Overview

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

Instance Method Summary collapse

Methods inherited from FlagValidator

#validate!

Constructor Details

#initialize(*allowed_values) ⇒ AllowedValuesValidator

Returns a new instance of AllowedValuesValidator.



396
397
398
399
400
401
# File 'lib/flags.rb', line 396

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