class EasyJSONMatcher::AttributeGenerator
Attributes
factory[R]
opts[R]
Public Class Methods
new(local_opts:, global_opts:, **args)
click to toggle source
Calls superclass method
# File lib/easy_json_matcher/attribute_generator.rb, line 7 def initialize(local_opts:, global_opts:, **args) super(**args) @opts = extract_opts(locals: local_opts, globals: global_opts) end
Public Instance Methods
extract_opts(locals:, globals:)
click to toggle source
# File lib/easy_json_matcher/attribute_generator.rb, line 16 def extract_opts(locals:, globals:) (globals.reject(&non_attribute_options_filter) + locals).map(&override_local_values(locals: locals)) end
generate_attribute()
click to toggle source
# File lib/easy_json_matcher/attribute_generator.rb, line 12 def generate_attribute chain_factory.get_chain(steps: opts) end
non_attribute_options_filter()
click to toggle source
TODO this method should whitelist the options, and the options should be in a constant
Remember to change extract_ops so that it uses globals.select afterwards
# File lib/easy_json_matcher/attribute_generator.rb, line 22 def non_attribute_options_filter non_attribute_options = [:strict] ->(opt) { non_attribute_options.include? opt } end
override_local_values(locals:)
click to toggle source
# File lib/easy_json_matcher/attribute_generator.rb, line 27 def override_local_values(locals:) conflicts = { required: :not_required } ->(opt) { if conflicts.keys.include? opt locals.include?(conflicts[opt]) ? conflicts[opt] : opt else opt end } end