Module: DiffJson

Defined in:
lib/diff_json/diff.rb,
lib/diff_json/output/html_output.rb,
lib/diff_json/output/undefined_value.rb

Defined Under Namespace

Classes: Diff, HtmlOutput, UndefinedValue

Class Method Summary collapse

Class Method Details

.diff(old_json, new_json, return_type, diff_opts = {}, output_opts = {}) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/diff_json/diff.rb', line 4

def self.diff(old_json, new_json, return_type, diff_opts = {}, output_opts = {})
  completed_diff = Diff.new(old_json, new_json, **diff_opts)

  return case return_type
  when :raw
    completed_diff
  when :patch
    patch_operations = []

    completed_diff.diff.each do |path, operations|
      operations.each do |op|
        patch_operations << op if [:add, :replace, :remove].include?(op[:op]) or (op[:op] == :move and path == op[:from])
      end
    end

    return patch_operations
  when :html
    HtmlOutput.new(completed_diff, **output_opts)
  end
end