Class: HecksPlugins::JSONValidator::SchemaParser

Inherits:
Object
  • Object
show all
Defined in:
lib/parsers/schema_parser.rb

Overview

Create a JSON Schema from an object

Constant Summary collapse

JSON_TYPES =
%w{string number object array boolean null}
HECKS_NUMBER_TYPES =
%w{integer currency}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(domain_module:, object:) ⇒ SchemaParser

Returns a new instance of SchemaParser.



9
10
11
12
13
# File 'lib/parsers/schema_parser.rb', line 9

def initialize domain_module:, object:
  @domain_module = domain_module
  @object =        object
  @properties =    {}
end

Instance Attribute Details

#schemaObject (readonly)

Returns the value of attribute schema.



5
6
7
# File 'lib/parsers/schema_parser.rb', line 5

def schema
  @schema
end

Instance Method Details

#callObject



15
16
17
18
19
20
# File 'lib/parsers/schema_parser.rb', line 15

def call
  parse_required_fields
  object.attributes.each { |a| parse_property(a) }
  build_schema
  self
end