Class: SmartDiff
- Inherits:
-
Object
- Object
- SmartDiff
- Defined in:
- lib/smart_diff.rb
Instance Attribute Summary (collapse)
-
- (Object) code_one
Returns the value of attribute code_one.
-
- (Object) code_two
Returns the value of attribute code_two.
-
- (Object) file_one
Returns the value of attribute file_one.
-
- (Object) file_two
Returns the value of attribute file_two.
-
- (Object) node_diff
Returns the value of attribute node_diff.
Instance Method Summary (collapse)
-
- (java.util.ArrayList<DeepDiff>) diff
Create a diff of the two AST objects.
-
- (SmartDiff) initialize(file_one, file_two)
constructor
Create a SmartDiff object which will create diff of two source files based on AST generated by JRubyParser.
-
- (org.jrubyparser.Node) parse(code_to_parse, file_name)
Parse the source into an abstract syntax tree.
-
- (String) read(file_name)
Read the source code into a string.
Constructor Details
- (SmartDiff) initialize(file_one, file_two)
Create a SmartDiff object which will create diff of two source files based on AST generated by JRubyParser.
19 20 21 22 23 |
# File 'lib/smart_diff.rb', line 19 def initialize(file_one, file_two) @file_one = file_one @file_two = file_two @node_diff = diff() end |
Instance Attribute Details
- (Object) code_one
Returns the value of attribute code_one
8 9 10 |
# File 'lib/smart_diff.rb', line 8 def code_one @code_one end |
- (Object) code_two
Returns the value of attribute code_two
8 9 10 |
# File 'lib/smart_diff.rb', line 8 def code_two @code_two end |
- (Object) file_one
Returns the value of attribute file_one
8 9 10 |
# File 'lib/smart_diff.rb', line 8 def file_one @file_one end |
- (Object) file_two
Returns the value of attribute file_two
8 9 10 |
# File 'lib/smart_diff.rb', line 8 def file_two @file_two end |
- (Object) node_diff
Returns the value of attribute node_diff
8 9 10 |
# File 'lib/smart_diff.rb', line 8 def node_diff @node_diff end |
Instance Method Details
- (java.util.ArrayList<DeepDiff>) diff
Create a diff of the two AST objects.
58 59 60 61 62 63 64 65 66 67 |
# File 'lib/smart_diff.rb', line 58 def diff() @code_one = read(@file_one) @code_two = read(@file_two) if @code_one && @code_two nodeA = parse(@code_one, @file_one) nodeB = parse(@code_two, @file_two) nd = org.jrubyparser.util.diff.NodeDiff.new(nodeA, @code_one, nodeB, @code_two) nd.deep_diff end end |
- (org.jrubyparser.Node) parse(code_to_parse, file_name)
Parse the source into an abstract syntax tree.
49 50 51 |
# File 'lib/smart_diff.rb', line 49 def parse(code_to_parse, file_name) JRubyParser.parse(code_to_parse, { :filename => file_name }) end |
- (String) read(file_name)
Read the source code into a string.
32 33 34 35 36 37 38 39 |
# File 'lib/smart_diff.rb', line 32 def read(file_name) path = Pathname.new(file_name). if path.exist? File.read path else raise "#{path} not found. Check the path." end end |