Class: RiderServer::Validate::Hash

Inherits:
Base show all
Defined in:
lib/rider_server/validate/hash.rb

Instance Method Summary collapse

Methods inherited from Base

#fail, validate

Methods included from PredicateLogic

#add_predicate, #check_predicates

Constructor Details

#initialize(schema) ⇒ Hash

Returns a new instance of Hash.



15
16
17
# File 'lib/rider_server/validate/hash.rb', line 15

def initialize(schema)
  @schema = schema
end

Instance Method Details

#validate(data, loc = "") ⇒ Object



19
20
21
22
23
24
25
# File 'lib/rider_server/validate/hash.rb', line 19

def validate(data, loc = "")
  @schema.map do |key, validator|
    if data.key? key
      [key, validator.validate(data[key], "#{loc}[#{key}]")]
    end
  end.to_h
end