Class: Hashidator

Inherits:
Object
  • Object
show all
Defined in:
lib/hashidator.rb,
lib/hashidator/version.rb

Constant Summary collapse

VERSION =
"0.4.1"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(schema) ⇒ Hashidator

Returns a new instance of Hashidator.


10
11
12
# File 'lib/hashidator.rb', line 10

def initialize(schema)
  @schema = schema
end

Instance Attribute Details

#schemaObject

Returns the value of attribute schema


8
9
10
# File 'lib/hashidator.rb', line 8

def schema
  @schema
end

Class Method Details

.validate(schema, input) ⇒ Object


4
5
6
# File 'lib/hashidator.rb', line 4

def self.validate(schema, input)
  new(schema).validate(input)
end

Instance Method Details

#validate(input) ⇒ Object


14
15
16
17
18
19
# File 'lib/hashidator.rb', line 14

def validate(input)
  input ||= {}
  schema.all? {|key, validator|
    validate_value(validator, input[key])
  }
end