Module: Daddy::Cucumber::Diff

Defined in:
lib/daddy/cucumber/diff.rb

Instance Method Summary collapse

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, options = {})
  a = File.read(file_a)
  b = File.read(file_b)
  diff = format_diff(Differ.diff(a, b))

  show_filename(file_a, options)
  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, options = {})
  options[:as] ||= 'edit'

  git = Daddy::Git.new
  a = File.read(file).gsub(/[<>]/, '<' => '&lt;', '>' => '&gt;')
  b = git.show_previous(file, true).gsub(/[<>]/, '<' => '&lt;', '>' => '&gt;')
  diff = format_diff(Differ.diff(a, b), options)

  show_filename(file, options)
  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, options = {})
  show_filename(file, options)

  lines = File.readlines(file)

  if options[:from] and options[:to]
    from = options[:from] - 1
    to = options[:to] - 1
    lines = lines[from..to]
  elsif options[:from]
    from = options[:from] - 1
    lines = lines[from..-1]
  elsif options[:to]
    to = options[:to] - 1
    lines = lines[0..to]
  end

  lines = lines.join.gsub(/[<>]/, '<' => '&lt;', '>' => '&gt;')
  puts "<pre>#{lines}</pre>"

end