Module: Daddy::Cucumber::Diff
- Defined in:
- lib/daddy/cucumber/diff.rb
Instance Method Summary collapse
- #diff(file_a, file_b, options = {}) ⇒ Object
- #git_diff(file, options = {}) ⇒ Object
- #git_diff_name(*includes) ⇒ Object
- #show(file, options = {}) ⇒ Object
Instance Method Details
#diff(file_a, file_b, options = {}) ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/daddy/cucumber/diff.rb', line 24 def diff(file_a, file_b, = {}) a = File.read(file_a) b = File.read(file_b) diff = format_diff(Differ.diff(a, b)) show_filename(file_a, ) puts "<pre>#{diff}</pre>" end |
#git_diff(file, options = {}) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/daddy/cucumber/diff.rb', line 7 def git_diff(file, = {}) [:as] ||= 'edit' git = Daddy::Git.new a = File.read(file).gsub(/[<>]/, '<' => '<', '>' => '>') b = git.show_previous(file, true).gsub(/[<>]/, '<' => '<', '>' => '>') diff = format_diff(Differ.diff(a, b), ) show_filename(file, ) puts "<pre>#{diff}</pre>" end |
#git_diff_name(*includes) ⇒ Object
19 20 21 22 |
# File 'lib/daddy/cucumber/diff.rb', line 19 def git_diff_name(*includes) git = Daddy::Git.new puts '<pre>' + git.git_diff_name(*includes) + '</pre>' end |
#show(file, options = {}) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/daddy/cucumber/diff.rb', line 33 def show(file, = {}) show_filename(file, ) lines = File.readlines(file) if [:from] and [:to] from = [:from] - 1 to = [:to] - 1 lines = lines[from..to] elsif [:from] from = [:from] - 1 lines = lines[from..-1] elsif [:to] to = [:to] - 1 lines = lines[0..to] end lines = lines.join.gsub(/[<>]/, '<' => '<', '>' => '>') puts "<pre>#{lines}</pre>" end |