class JsonOutputCombiner

Constants

KEYS_TO_COMBINE

Public Class Methods

new(output) click to toggle source
# File lib/rspec-rcv/handler.rb, line 85
def initialize(output)
  @output = output
end

Public Instance Methods

combine() click to toggle source
# File lib/rspec-rcv/handler.rb, line 89
def combine
  compact_compare_output(@output, key: "")
end

Private Instance Methods

combine_results(a, b) click to toggle source
# File lib/rspec-rcv/handler.rb, line 97
def combine_results(a, b)
  KEYS_TO_COMBINE.each do |key|
    a[key] += b[key]
  end
end
compact_compare_output(output, key:) click to toggle source
# File lib/rspec-rcv/handler.rb, line 103
def compact_compare_output(output, key:)
  result = { update: [], append: [], remove: [] }
  return result unless output.is_a?(Hash)

  KEYS_TO_COMBINE.each do |combine_key|
    output.fetch(combine_key, {}).each do |update_key, nested_output|
      new_key = "#{key}#{key.empty? ? '' : '.'}#{update_key}"
      result[combine_key] << new_key
      nested_result = compact_compare_output(nested_output, key: new_key)
      combine_results(result, nested_result)
    end
  end

  result
end