Class: Services::FieldsValidator

Inherits:
Object
  • Object
show all
Defined in:
lib/services/fields_validator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#errorObject (readonly)

Returns the value of attribute error.



8
9
10
# File 'lib/services/fields_validator.rb', line 8

def error
  @error
end

#fieldsObject

Returns the value of attribute fields.



7
8
9
# File 'lib/services/fields_validator.rb', line 7

def fields
  @fields
end

#schemaObject

Returns the value of attribute schema.



7
8
9
# File 'lib/services/fields_validator.rb', line 7

def schema
  @schema
end

Instance Method Details

#callObject



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.message
end

#valid?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/services/fields_validator.rb', line 22

def valid?
  @error.nil?
end