Class: Yarrow::Schema::Validator
- Inherits:
-
Object
- Object
- Yarrow::Schema::Validator
- Defined in:
- lib/yarrow/schema.rb
Overview
Checks values plugged into each slot and runs any required validations (validations not yet implemented).
Current design throws on error rather than returns a boolean result.
Instance Method Summary collapse
- #check(fields) ⇒ Object
-
#initialize(fields_spec) ⇒ Validator
constructor
A new instance of Validator.
Constructor Details
#initialize(fields_spec) ⇒ Validator
Returns a new instance of Validator.
15 16 17 |
# File 'lib/yarrow/schema.rb', line 15 def initialize(fields_spec) @spec = fields_spec end |
Instance Method Details
#check(fields) ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/yarrow/schema.rb', line 19 def check(fields) raise "wrong number of args" unless fields.keys.length == @spec.keys.length fields.keys.each do |key| raise "key does not exist" unless @spec.key?(key) end end |