Class: EasyJSONMatcher::ArrayGenerator
- Inherits:
-
Object
- Object
- EasyJSONMatcher::ArrayGenerator
- Defined in:
- lib/easy_json_matcher/array_generator.rb
Constant Summary collapse
- WHITELIST =
[:required, :not_required]
Instance Attribute Summary collapse
-
#array_validator ⇒ Object
readonly
Returns the value of attribute array_validator.
-
#content_opts ⇒ Object
readonly
Returns the value of attribute content_opts.
-
#opts ⇒ Object
readonly
Returns the value of attribute opts.
Instance Method Summary collapse
- #array_options_filter ⇒ Object
- #elements_should(be:) ⇒ Object
- #extract_opts(locals:, globals:) ⇒ Object
- #generate_array ⇒ Object
-
#initialize(local_opts:, global_opts:, **args) ⇒ ArrayGenerator
constructor
A new instance of ArrayGenerator.
- #override_local_values(locals:) ⇒ Object
Constructor Details
#initialize(local_opts:, global_opts:, **args) ⇒ ArrayGenerator
Returns a new instance of ArrayGenerator.
9 10 11 12 13 |
# File 'lib/easy_json_matcher/array_generator.rb', line 9 def initialize(local_opts:, global_opts:, **args) super(**args) @opts = extract_opts(locals: local_opts, globals: global_opts) @content_opts = [] end |
Instance Attribute Details
#array_validator ⇒ Object (readonly)
Returns the value of attribute array_validator.
7 8 9 |
# File 'lib/easy_json_matcher/array_generator.rb', line 7 def array_validator @array_validator end |
#content_opts ⇒ Object (readonly)
Returns the value of attribute content_opts.
7 8 9 |
# File 'lib/easy_json_matcher/array_generator.rb', line 7 def content_opts @content_opts end |
#opts ⇒ Object (readonly)
Returns the value of attribute opts.
7 8 9 |
# File 'lib/easy_json_matcher/array_generator.rb', line 7 def opts @opts end |
Instance Method Details
#array_options_filter ⇒ Object
27 28 29 |
# File 'lib/easy_json_matcher/array_generator.rb', line 27 def ->(opt) { WHITELIST.include?(opt) } end |
#elements_should(be:) ⇒ Object
19 20 21 |
# File 'lib/easy_json_matcher/array_generator.rb', line 19 def elements_should(be:) @content_opts = be end |
#extract_opts(locals:, globals:) ⇒ Object
23 24 25 |
# File 'lib/easy_json_matcher/array_generator.rb', line 23 def extract_opts(locals:, globals:) (globals.select(&) + locals).map(&override_local_values(locals: locals)) end |
#generate_array ⇒ Object
15 16 17 |
# File 'lib/easy_json_matcher/array_generator.rb', line 15 def generate_array array_validator.new(opts: opts, verify_content_as: content_opts) end |
#override_local_values(locals:) ⇒ Object
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/easy_json_matcher/array_generator.rb', line 31 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 |