Class: DiffJson::Diff

Inherits:
Object
  • Object
show all
Defined in:
lib/diff_json/diff.rb

Instance Method Summary collapse

Constructor Details

#initialize(old_json, new_json, **opts) ⇒ Diff

Returns a new instance of Diff.



3
4
5
6
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
# File 'lib/diff_json/diff.rb', line 3

def initialize(old_json, new_json, **opts)
  @old_json   = old_json
  @new_json   = new_json
  @opts       = {
    :debug              => false,
    :diff_count_filter  => {
      :only   => ['$**'],
      :except => []
    },
    :ignore_object_keys        => [],
    :generate_object_sub_diffs => {}
  }.merge(opts)
  @filtered = @opts[:diff_count_filter] != {
    :only   => ['$**'],
    :except => []
  }
  @diff = {
    :count => {
      :all    => 0,
      :insert => 0,
      :update => 0,
      :delete => 0,
      :move   => 0
    },
    :full_diff => {
      :old   => [],
      :new   => []
    },
    :sub_diffs => {}
  }

  calculate
end

Instance Method Details

#change_count(operation = :all) ⇒ Object



45
46
47
# File 'lib/diff_json/diff.rb', line 45

def change_count(operation = :all)
  return @diff[:count][operation] || 0
end

#diffObject



37
38
39
# File 'lib/diff_json/diff.rb', line 37

def diff
  return @diff[:full_diff]
end

#retrieve_output(output_type = :stdout, **output_opts) ⇒ Object



49
50
51
52
53
54
55
56
57
# File 'lib/diff_json/diff.rb', line 49

def retrieve_output(output_type = :stdout, **output_opts)
  case output_type
  when :stdout
  when :file
  when :html
    html_output = HtmlOutput.new(self, **output_opts)
    return html_output
  end
end

#sub_diffsObject



41
42
43
# File 'lib/diff_json/diff.rb', line 41

def sub_diffs
  return @diff[:sub_diffs]
end