Class: EasyJSONMatcher::AttributeGenerator
- Inherits:
-
Object
- Object
- EasyJSONMatcher::AttributeGenerator
- Defined in:
- lib/easy_json_matcher/attribute_generator.rb
Instance Attribute Summary collapse
-
#factory ⇒ Object
readonly
Returns the value of attribute factory.
-
#opts ⇒ Object
readonly
Returns the value of attribute opts.
Instance Method Summary collapse
- #extract_opts(locals:, globals:) ⇒ Object
- #generate_attribute ⇒ Object
-
#initialize(local_opts:, global_opts:, **args) ⇒ AttributeGenerator
constructor
A new instance of AttributeGenerator.
-
#non_attribute_options_filter ⇒ Object
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.
- #override_local_values(locals:) ⇒ Object
Constructor Details
#initialize(local_opts:, global_opts:, **args) ⇒ AttributeGenerator
Returns a new instance of AttributeGenerator.
7 8 9 10 |
# 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 |
Instance Attribute Details
#factory ⇒ Object (readonly)
Returns the value of attribute factory.
5 6 7 |
# File 'lib/easy_json_matcher/attribute_generator.rb', line 5 def factory @factory end |
#opts ⇒ Object (readonly)
Returns the value of attribute opts.
5 6 7 |
# File 'lib/easy_json_matcher/attribute_generator.rb', line 5 def opts @opts end |
Instance Method Details
#extract_opts(locals:, globals:) ⇒ Object
16 17 18 |
# File 'lib/easy_json_matcher/attribute_generator.rb', line 16 def extract_opts(locals:, globals:) (globals.reject(&) + locals).map(&override_local_values(locals: locals)) end |
#generate_attribute ⇒ Object
12 13 14 |
# File 'lib/easy_json_matcher/attribute_generator.rb', line 12 def generate_attribute chain_factory.get_chain(steps: opts) end |
#non_attribute_options_filter ⇒ Object
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
22 23 24 25 |
# File 'lib/easy_json_matcher/attribute_generator.rb', line 22 def = [:strict] ->(opt) { .include? opt } end |
#override_local_values(locals:) ⇒ Object
27 28 29 30 31 32 33 34 35 36 |
# 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 |