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(attribute_factory: ValidationChainFactory, local_opts:, global_opts:) ⇒ 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(attribute_factory: ValidationChainFactory, local_opts:, global_opts:) ⇒ AttributeGenerator
Returns a new instance of AttributeGenerator.
6 7 8 9 |
# File 'lib/easy_json_matcher/attribute_generator.rb', line 6 def initialize(attribute_factory: ValidationChainFactory, local_opts:, global_opts:) @factory = attribute_factory @opts = extract_opts(locals: local_opts, globals: global_opts) end |
Instance Attribute Details
#factory ⇒ Object (readonly)
Returns the value of attribute factory.
4 5 6 |
# File 'lib/easy_json_matcher/attribute_generator.rb', line 4 def factory @factory end |
#opts ⇒ Object (readonly)
Returns the value of attribute opts.
4 5 6 |
# File 'lib/easy_json_matcher/attribute_generator.rb', line 4 def opts @opts end |
Instance Method Details
#extract_opts(locals:, globals:) ⇒ Object
15 16 17 |
# File 'lib/easy_json_matcher/attribute_generator.rb', line 15 def extract_opts(locals:, globals:) (globals.reject(&) + locals).map(&override_local_values(locals: locals)) end |
#generate_attribute ⇒ Object
11 12 13 |
# File 'lib/easy_json_matcher/attribute_generator.rb', line 11 def generate_attribute 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
21 22 23 24 |
# File 'lib/easy_json_matcher/attribute_generator.rb', line 21 def = [:strict] ->(opt) { .include? opt } end |
#override_local_values(locals:) ⇒ Object
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/easy_json_matcher/attribute_generator.rb', line 26 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 |