Class: Fitting::Doc::CombinationOneOf
Instance Attribute Summary
#json_schema, #logs, #type
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
#debug_report, #initialize
Methods inherited from Step
#mark_enum, #mark_required, #new_index_offset, #next, #nocover!, #range, #report, #to_hash, #valid?
Instance Method Details
#cover!(log) ⇒ Object
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
# File 'lib/fitting/doc/combination_one_of.rb', line 24
def cover!(log)
if JSON::Validator.fully_validate(@json_schema, log.body) == []
@step_cover_size += 1
@logs.push(log.body)
errors = @next_steps.inject([]) do |sum, combination|
sum.push(combination.cover!(log))
end.flatten.compact
return if @next_steps.size == 0
return unless @next_steps.size == errors.size
error_message = ""
errors.each do |error|
error_message += "combination: #{error[:combination]}\n"\
"combination type: #{error[:type]}\n"\
"combination json-schema: #{::JSON.pretty_generate(error[:json_schema])}\n"\
"combination error #{::JSON.pretty_generate(error[:error])}\n"\
"combination body #{::JSON.pretty_generate(error[:body])}\n"
end
end
end
|
#index_offset ⇒ Object
56
57
58
|
# File 'lib/fitting/doc/combination_one_of.rb', line 56
def index_offset
YAML.dump(@json_schema['properties']).split("\n").size + YAML.dump(@json_schema['required']).split("\n").size
end
|
#initialize_combinations(combination, json_schema) ⇒ Object
10
11
12
13
14
15
16
17
18
19
20
21
22
|
# File 'lib/fitting/doc/combination_one_of.rb', line 10
def initialize_combinations(combination, json_schema)
combinations = Fitting::Cover::JSONSchemaEnum.new(@json_schema).combi
if combinations.size > 1
combinations.each do |comb|
@next_steps.push(CombinationEnum.new(comb[0], "#{comb[1][0]}", "#{comb[1][1]}", json_schema))
end
end
combinations = Fitting::Cover::JSONSchema.new(@json_schema).combi
combinations.each do |comb|
@next_steps.push(CombinationOptional.new(comb[0], "#{type}.#{comb[1][0]}", "#{combination}.#{comb[1][1]}", json_schema))
end
end
|
#mark_range(index, res) ⇒ Object
49
50
51
52
53
54
|
# File 'lib/fitting/doc/combination_one_of.rb', line 49
def mark_range(index, res)
res[index + 1] = @step_cover_size
if @json_schema && @json_schema["required"]
mark_required(index + 1, res, @json_schema)
end
end
|