Module: Daddy::Cucumber::Diff
- Defined in:
- lib/daddy/cucumber/helpers/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
38 39 40 41 42 43 44 45 |
# File 'lib/daddy/cucumber/helpers/diff.rb', line 38 def diff(file_a, file_b, = {}) a = File.read(file_a).gsub(/[<>]/, '<' => '<', '>' => '>') b = File.read(file_b).gsub(/[<>]/, '<' => '<', '>' => '>') 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 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/daddy/cucumber/helpers/diff.rb', line 7 def git_diff(file, = {}) [:as] = 'edit' unless .has_key?(:as) remote = .has_key?(:remote) ? [:remote] : true git = Daddy::Git.new if [:between] a = git.show_previous(file, :commit => [:between], :remote => remote) else a = File.read(file) end a = a.gsub(/[<>]/, '<' => '<', '>' => '>') if [:and] b = git.show_previous(file, :commit => [:and], :remote => remote) else b = git.show_previous(file, :remote => remote) end b = b.gsub(/[<>]/, '<' => '<', '>' => '>') diff = format_diff(Differ.diff(a, b), ) show_filename(file, ) puts "<pre>#{diff}</pre>" end |
#git_diff_name(*includes) ⇒ Object
33 34 35 36 |
# File 'lib/daddy/cucumber/helpers/diff.rb', line 33 def git_diff_name(*includes) git = Daddy::Git.new puts '<pre>' + git.git_diff_name(*includes) + '</pre>' end |
#show(file, options = {}) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/daddy/cucumber/helpers/diff.rb', line 47 def show(file, = {}) show_filename(file, ) if [:commit].present? git = Daddy::Git.new content = git.show_previous(file, :commit => [:commit], :remote => [:remote]) lines = content.split(/\r\n|\r|\n/).map{|line| line + "\n"} else lines = File.readlines(file) end 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 |