Class: EasyJSONMatcher::SchemaGenerator
- Inherits:
-
Object
- Object
- EasyJSONMatcher::SchemaGenerator
- Defined in:
- lib/easy_json_matcher/schema_generator.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#node ⇒ Object
readonly
Returns the value of attribute node.
Instance Method Summary collapse
- #_create_validator(opts) ⇒ Object
- #_node_generator(opts = {}) ⇒ Object
- #contains_node(key:, opts: {}) {|generator| ... } ⇒ Object
- #generate_node ⇒ Object
- #has_attribute(key:, opts: {}) ⇒ Object
-
#initialize(opts: {}) {|_self| ... } ⇒ SchemaGenerator
constructor
A new instance of SchemaGenerator.
- #register(schema_name:) ⇒ Object
- #validator_opts(key, opts) ⇒ Object
Constructor Details
#initialize(opts: {}) {|_self| ... } ⇒ SchemaGenerator
Returns a new instance of SchemaGenerator.
9 10 11 12 |
# File 'lib/easy_json_matcher/schema_generator.rb', line 9 def initialize(opts: {}) @name = opts[:key] yield self if block_given? end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
7 8 9 |
# File 'lib/easy_json_matcher/schema_generator.rb', line 7 def name @name end |
#node ⇒ Object (readonly)
Returns the value of attribute node.
6 7 8 |
# File 'lib/easy_json_matcher/schema_generator.rb', line 6 def node @node end |
Instance Method Details
#_create_validator(opts) ⇒ Object
29 30 31 |
# File 'lib/easy_json_matcher/schema_generator.rb', line 29 def _create_validator(opts) ValidatorFactory.create opts end |
#_node_generator(opts = {}) ⇒ Object
33 34 35 |
# File 'lib/easy_json_matcher/schema_generator.rb', line 33 def _node_generator(opts = {}) self.class.new opts: opts end |
#contains_node(key:, opts: {}) {|generator| ... } ⇒ Object
14 15 16 17 18 |
# File 'lib/easy_json_matcher/schema_generator.rb', line 14 def contains_node(key:, opts: {}) generator = _node_generator validator_opts(key, opts) yield generator if block_given? node.add_validator generator.generate_node end |
#generate_node ⇒ Object
37 38 39 |
# File 'lib/easy_json_matcher/schema_generator.rb', line 37 def generate_node node end |
#has_attribute(key:, opts: {}) ⇒ Object
20 21 22 |
# File 'lib/easy_json_matcher/schema_generator.rb', line 20 def has_attribute(key:, opts: {}) node.add_validator(_create_validator(validator_opts(key, opts))) end |
#register(schema_name:) ⇒ Object
41 42 43 |
# File 'lib/easy_json_matcher/schema_generator.rb', line 41 def register(schema_name:) EasyJSONMatcher.add_schema(name: schema_name, schema: generate_node) end |
#validator_opts(key, opts) ⇒ Object
24 25 26 27 |
# File 'lib/easy_json_matcher/schema_generator.rb', line 24 def validator_opts(key, opts) opts[:key] = key opts end |