Class: Marty::PgEnumAttribute

Inherits:
JSON::Schema::Attribute
  • Object
show all
Defined in:
lib/marty/json_schema.rb

Class Method Summary collapse

Class Method Details

.validate(curr_schema, data, frag, pro, _validator, opt = {}) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/marty/json_schema.rb', line 7

def self.validate(curr_schema, data, frag, pro, _validator, opt = {})
  values = nil
  path = '#/' + frag.join('/')
  begin
    cs = curr_schema.schema['pg_enum']
    enum = cs.constantize
    values = enum.values
  rescue StandardError => e
    msg = "The property '#{path}': '#{cs}' is not a pg_enum class"
    validation_error(pro, msg, frag, curr_schema, self, opt[:record_errors])
  end
  if values && !values.include?(data)
    msg = "The property '#{path}' value '#{data}' not contained in #{enum}"
    validation_error(pro, msg, frag, curr_schema, self, opt[:record_errors])
  end
end