Class: Twiglet::Validator
- Inherits:
-
Object
- Object
- Twiglet::Validator
- Defined in:
- lib/twiglet/validator.rb
Instance Attribute Summary collapse
-
#custom_error_handler ⇒ Object
Returns the value of attribute custom_error_handler.
Instance Method Summary collapse
-
#initialize(schema) ⇒ Validator
constructor
A new instance of Validator.
- #validate(message) ⇒ Object
Constructor Details
#initialize(schema) ⇒ Validator
Returns a new instance of Validator.
10 11 12 13 14 |
# File 'lib/twiglet/validator.rb', line 10 def initialize(schema) @schema = JSON.parse(schema) @custom_error_handler = ->(e) { raise e } @validator = JSON::Validator.new(@schema) end |
Instance Attribute Details
#custom_error_handler ⇒ Object
Returns the value of attribute custom_error_handler.
8 9 10 |
# File 'lib/twiglet/validator.rb', line 8 def custom_error_handler @custom_error_handler end |
Instance Method Details
#validate(message) ⇒ Object
16 17 18 19 20 |
# File 'lib/twiglet/validator.rb', line 16 def validate() @validator.validate() rescue JSON::Schema::ValidationError => e custom_error_handler.call(e) end |