class EasyJSONMatcher::NodeGenerator
Attributes
array_opts[R]
attribute_opts[R]
global_opts[R]
node_opts[R]
validators[R]
Public Class Methods
new(opts: [], global_opts: [], **args)
click to toggle source
Calls superclass method
# File lib/easy_json_matcher/node_generator.rb, line 10 def initialize(opts: [], global_opts: [], **args) super(**args) @validators = {} @node_opts = extract_opts(local: opts, global: global_opts) @global_opts = global_opts end
Public Instance Methods
contains_array(key:, opts: [], &block)
click to toggle source
# File lib/easy_json_matcher/node_generator.rb, line 33 def contains_array(key:, opts: [], &block) validator = array_generator.new(local_opts: opts, global_opts: global_opts) validator.instance_eval &block if block_given? validators[key] = validator.generate_array end
contains_node(key:, opts: [], &block)
click to toggle source
# File lib/easy_json_matcher/node_generator.rb, line 27 def contains_node(key:, opts: [], &block) generator = self.class.new(opts: opts, global_opts: global_opts) generator.instance_eval &block if block_given? validators[key] = generator.generate_node end
extract_opts(local:, global:)
click to toggle source
# File lib/easy_json_matcher/node_generator.rb, line 44 def extract_opts(local:, global:) conflicts = { required: :not_required } global.map do |opt| if conflicts.keys.include? opt local.include?(conflicts[opt]) ? conflicts[opt] : opt else opt end end end
generate_node()
click to toggle source
# File lib/easy_json_matcher/node_generator.rb, line 17 def generate_node strict = node_opts.delete(:strict) node.new(opts: node_opts, strict: strict, validators: validators) end
has_attribute(key:, opts: [])
click to toggle source
# File lib/easy_json_matcher/node_generator.rb, line 22 def has_attribute(key:, opts: []) validator = attribute_generator.new(local_opts: opts, global_opts: global_opts) validators[key] = validator.generate_attribute end
has_schema(key:, name:)
click to toggle source
# File lib/easy_json_matcher/node_generator.rb, line 39 def has_schema(key:, name:) schema = schema_library.get_schema(name: name) validators[key] = schema end