class Schash::Schema::Rule::OneOfTypes

Public Class Methods

new(*klasses) click to toggle source
# File lib/schash/schema/rule/one_of_types.rb, line 5
def initialize(*klasses)
  @klasses = klasses
end

Public Instance Methods

validate(target, position = []) click to toggle source
# 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