Class: Flags::ClassValidator

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

Overview

A validator that raises an error if the class of the flag’s value is not one of the expected classes.

Instance Method Summary collapse

Methods inherited from FlagValidator

#validate!

Constructor Details

#initialize(*expected_value_classes) ⇒ ClassValidator

Returns a new instance of ClassValidator.



376
377
378
379
380
381
# File 'lib/flags.rb', line 376

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