Class: Bundler::Diff::Tool

Inherits:
Object
  • Object
show all
Defined in:
lib/bundler/diff/tool.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#a_dirObject

Returns the value of attribute a_dir.



6
7
8
# File 'lib/bundler/diff/tool.rb', line 6

def a_dir
  @a_dir
end

#a_output_dirObject

Returns the value of attribute a_output_dir.



7
8
9
# File 'lib/bundler/diff/tool.rb', line 7

def a_output_dir
  @a_output_dir
end

#b_dirObject

Returns the value of attribute b_dir.



9
10
11
# File 'lib/bundler/diff/tool.rb', line 9

def b_dir
  @b_dir
end

#b_output_dirObject

Returns the value of attribute b_output_dir.



10
11
12
# File 'lib/bundler/diff/tool.rb', line 10

def b_output_dir
  @b_output_dir
end

Instance Method Details

#diff(a_path, b_path) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/bundler/diff/tool.rb', line 24

def diff(a_path, b_path)
  null = '/dev/null'

  command = ['diff -u']

  command_for_output = ['diff']

  if a_path
    command.concat [a_dir.join(a_path), '--label', Pathname('a').join(a_path)]
    command_for_output << a_output_dir.join(a_path)
  else
    command << null
    command_for_output << null
  end

  if b_path
    command.concat [b_dir.join(b_path), '--label', Pathname('b').join(b_path)]
    command_for_output << b_output_dir.join(b_path)
  else
    command << null
    command_for_output << null
  end

  output = `#{command.join(' ')}`

  return if output.empty?

  puts command_for_output.join(' ')
  puts output
end

#diff_entriesObject



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/bundler/diff/tool.rb', line 12

def diff_entries
  a_files = file_list(a_dir)
  b_files = file_list(b_dir)

  (a_files + b_files).uniq.sort.each do |path|
    a_path = a_files.include?(path) ? path : nil
    b_path = b_files.include?(path) ? path : nil

    diff(a_path, b_path)
  end
end