Class: CodeChange

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

Overview

A CodeChange represents a difference between two sets of ruby code. It may contain child changes.

Constant Summary collapse

OPERATION_CHARS =
{
  :added   => "+",
  :removed => "-",
  :changed => "c",
  :moved   => "m"   #Not used yet
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(signature, operation, changes = []) ⇒ CodeChange

Returns a new instance of CodeChange.



15
16
17
18
19
# File 'lib/ruby_diff/code_comparison.rb', line 15

def initialize(signature, operation, changes=[])
  @signature = signature
  @operation = operation
  @changes   = changes
end

Instance Attribute Details

#changesObject (readonly)

Returns the value of attribute changes.



6
7
8
# File 'lib/ruby_diff/code_comparison.rb', line 6

def changes
  @changes
end

#operationObject (readonly)

Returns the value of attribute operation.



5
6
7
# File 'lib/ruby_diff/code_comparison.rb', line 5

def operation
  @operation
end

#signatureObject (readonly)

Returns the value of attribute signature.



4
5
6
# File 'lib/ruby_diff/code_comparison.rb', line 4

def signature
  @signature
end

Instance Method Details

#to_s(depth = 1) ⇒ Object



21
22
23
24
25
# File 'lib/ruby_diff/code_comparison.rb', line 21

def to_s(depth=1)
  this_change = "#{OPERATION_CHARS[self.operation]}#{"  "*depth}#{signature}"
  sub_changes = changes.map{|c| c.to_s(depth+1)}
  [this_change, sub_changes].flatten.join("\n")
end