Class: Schash::Schema::Rule::OneOfTypes
- Defined in:
- lib/schash/schema/rule/one_of_types.rb
Instance Method Summary collapse
-
#initialize(*klasses) ⇒ OneOfTypes
constructor
A new instance of OneOfTypes.
- #validate(target, position = []) ⇒ Object
Methods inherited from Base
Constructor Details
#initialize(*klasses) ⇒ OneOfTypes
Returns a new instance of OneOfTypes.
5 6 7 |
# File 'lib/schash/schema/rule/one_of_types.rb', line 5 def initialize(*klasses) @klasses = klasses end |
Instance Method Details
#validate(target, position = []) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/schash/schema/rule/one_of_types.rb', line 9 def validate(target, position = []) match = @klasses.any? do |klass| target.is_a?(klass) end if match [] else [Error.new(position, "is not any of #{@klasses.map(&:to_s).join(', ')}")] end end |