Class: Services::FieldsValidator
- Inherits:
-
Object
- Object
- Services::FieldsValidator
- Defined in:
- lib/services/fields_validator.rb
Instance Attribute Summary collapse
-
#error ⇒ Object
readonly
Returns the value of attribute error.
-
#fields ⇒ Object
Returns the value of attribute fields.
-
#schema ⇒ Object
Returns the value of attribute schema.
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(attributes = {}) ⇒ FieldsValidator
constructor
A new instance of FieldsValidator.
- #valid? ⇒ Boolean
Constructor Details
#initialize(attributes = {}) ⇒ FieldsValidator
Returns a new instance of FieldsValidator.
10 11 12 13 14 |
# File 'lib/services/fields_validator.rb', line 10 def initialize(attributes = {}) attributes.each do |key, value| instance_variable_set("@#{key}", value) end end |
Instance Attribute Details
#error ⇒ Object (readonly)
Returns the value of attribute error.
8 9 10 |
# File 'lib/services/fields_validator.rb', line 8 def error @error end |
#fields ⇒ Object
Returns the value of attribute fields.
7 8 9 |
# File 'lib/services/fields_validator.rb', line 7 def fields @fields end |
#schema ⇒ Object
Returns the value of attribute schema.
7 8 9 |
# File 'lib/services/fields_validator.rb', line 7 def schema @schema end |
Instance Method Details
#call ⇒ Object
16 17 18 19 20 |
# File 'lib/services/fields_validator.rb', line 16 def call JSON::Validator.validate!(schema, fields) rescue JSON::Schema::ValidationError => e @error = e. end |
#valid? ⇒ Boolean
22 23 24 |
# File 'lib/services/fields_validator.rb', line 22 def valid? @error.nil? end |