Class: Holoserve::Pair::Validator

Inherits:
Object
  • Object
show all
Defined in:
lib/holoserve/pair/validator.rb

Defined Under Namespace

Classes: Error, InvalidError, InvalidSchemaError

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(schema_path = File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "..", "schema", "schema.yaml"))) ⇒ Validator

Returns a new instance of Validator.



27
28
29
30
31
32
# File 'lib/holoserve/pair/validator.rb', line 27

def initialize(schema_path = File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "..", "schema", "schema.yaml")))
  @schema_path = schema_path
  @meta_validator = Kwalify::MetaValidator.instance
  load_schema
  @validator = Kwalify::Validator.new(@schema)
end

Instance Attribute Details

#schema_pathObject

Returns the value of attribute schema_path.



25
26
27
# File 'lib/holoserve/pair/validator.rb', line 25

def schema_path
  @schema_path
end

Instance Method Details

#validate(hash) ⇒ Object

Raises:



34
35
36
37
# File 'lib/holoserve/pair/validator.rb', line 34

def validate(hash)
  errors = @validator.validate(hash)
  raise InvalidError, errors if errors && !errors.empty?
end