Class: CodeComparison

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_diff/code_comparison.rb

Overview

Compares two sets of parsed CodeObjects. A CodeComparison Expects sets of CodeObjects hashed by their signature.

Instance Method Summary collapse

Constructor Details

#initialize(old_signatures, new_signatures) ⇒ CodeComparison

Returns a new instance of CodeComparison.



31
32
33
34
# File 'lib/ruby_diff/code_comparison.rb', line 31

def initialize(old_signatures, new_signatures)
  @old = old_signatures
  @new = new_signatures
end

Instance Method Details

#changesObject

Returns the set of changes.



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/ruby_diff/code_comparison.rb', line 37

def changes
  changes = []
  seen = Set.new
  @old.each do |sig, code_object|
    seen << sig
    if other_code_object = @new[sig]
      if code_object != other_code_object
        changes << changed(sig, code_object, sig, other_code_object)
      end
    else
      changes << removal(sig, code_object)
    end
  end
  
  @new.each do |sig, code_object|
    if !seen.include?(sig)
      changes << addition(sig, code_object)
    end
  end
  
  changes
end