Class: Yarrow::Schema::Validator

Inherits:
Object
  • Object
show all
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

Constructor Details

#initialize(fields_spec) ⇒ Validator

Returns a new instance of Validator.

Parameters:

  • fields_spec (Hash)

    defines the slots in the schema to validate against



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