Class: RenderEditorjs::Validator
- Inherits:
-
Object
- Object
- RenderEditorjs::Validator
- Defined in:
- lib/render_editorjs/validator.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#schema ⇒ Object
readonly
Returns the value of attribute schema.
Instance Method Summary collapse
-
#initialize(data, schema) ⇒ Validator
constructor
A new instance of Validator.
- #valid? ⇒ Boolean
- #validate! ⇒ Object
Constructor Details
#initialize(data, schema) ⇒ Validator
Returns a new instance of Validator.
7 8 9 10 11 12 |
# File 'lib/render_editorjs/validator.rb', line 7 def initialize(data, schema) @data = data @schema = schema @errors = [] end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
5 6 7 |
# File 'lib/render_editorjs/validator.rb', line 5 def data @data end |
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
5 6 7 |
# File 'lib/render_editorjs/validator.rb', line 5 def errors @errors end |
#schema ⇒ Object (readonly)
Returns the value of attribute schema.
5 6 7 |
# File 'lib/render_editorjs/validator.rb', line 5 def schema @schema end |
Instance Method Details
#valid? ⇒ Boolean
14 15 16 17 18 19 20 |
# File 'lib/render_editorjs/validator.rb', line 14 def valid? validate! rescue JSON::Schema::ValidationError => e @errors << e. false end |
#validate! ⇒ Object
22 23 24 |
# File 'lib/render_editorjs/validator.rb', line 22 def validate! JSON::Validator.validate!(schema, data) end |