Class: Fitting::Doc::CombinationEnum
- Inherits:
-
CombinationStep
- Object
- Step
- CombinationStep
- Fitting::Doc::CombinationEnum
- Defined in:
- lib/fitting/doc/combination_enum.rb
Instance Attribute Summary
Attributes inherited from CombinationStep
Attributes inherited from Step
#index_after, #index_before, #index_medium, #next_steps, #res_after, #res_before, #res_medium, #step_cover_size, #step_key
Instance Method Summary collapse
Methods inherited from CombinationStep
#debug_report, #initialize, #initialize_combinations
Methods inherited from Step
#index_offset, #mark_enum, #mark_range, #mark_required, #new_index_offset, #next, #nocover!, #range, #to_hash, #valid?
Constructor Details
This class inherits a constructor from Fitting::Doc::CombinationStep
Instance Method Details
#cover!(log) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/fitting/doc/combination_enum.rb', line 7 def cover!(log) error = JSON::Validator.fully_validate(@json_schema, log.body) if error == [] @step_cover_size += 1 @logs.push(log.body) nil else bodies = custom_body(log.body) errors = [] bodies.each do |body| error = JSON::Validator.fully_validate(@json_schema, body) if error == [] @step_cover_size += 1 @logs.push(body) nil else errors.push( { combination: @step_key, type: @type, json_schema: @json_schema, error: error, body: body }) end end if errors.size == bodies.size errors else nil end end end |
#custom_body(body) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/fitting/doc/combination_enum.rb', line 63 def custom_body(body) bodies = [] keys = find_keys if keys != [] if keys.size == 1 if body[keys[0]].size == 1 return body else body[keys[0]].each do |bb| new_body = body.dup new_body.delete(keys[0]) bodies.push(new_body.merge(keys[0] => bb)) end end end return bodies end [body] end |
#find_keys ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/fitting/doc/combination_enum.rb', line 42 def find_keys new_keys = [] if YAML.dump(@json_schema).include?("array") res = @json_schema @step_key.split('.').each do |key| if res[key].class == Hash && res[key] != nil if res[key].class == Hash && res[key]['type'] == 'array' new_keys.push(key) return new_keys else if key != 'properties' new_keys.push(key) end res = res[key] end end end end [] end |
#report(res, index) ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/fitting/doc/combination_enum.rb', line 83 def report(res, index) @index_before = index @res_before = [] + res @index_medium = index @res_medium = [] + res combinations = @step_key.split('.') elements = YAML.dump(@source_json_schema).split("\n")[1..-1] res_index = 0 element_index = 0 elements.each_with_index do |element, i| if element.include?(combinations[element_index]) element_index += 1 end if combinations.size == element_index res_index = i break end end res[res_index + index] = @step_cover_size @index_after = res_index + index @res_after = [] + res [res, index] end |