Class: Holoserve::Pair::Validator
- Inherits:
-
Object
- Object
- Holoserve::Pair::Validator
- Defined in:
- lib/holoserve/pair/validator.rb
Defined Under Namespace
Classes: Error, InvalidError, InvalidSchemaError
Instance Attribute Summary collapse
-
#schema_path ⇒ Object
Returns the value of attribute schema_path.
Instance Method Summary collapse
-
#initialize(schema_path = File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "..", "schema", "schema.yaml"))) ⇒ Validator
constructor
A new instance of Validator.
- #validate(hash) ⇒ Object
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.(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_path ⇒ Object
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
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 |