Class: Jack::Config::Diff

Inherits:
Object
  • Object
show all
Defined in:
lib/jack/config/diff.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Diff

Returns a new instance of Diff.



5
6
7
8
9
10
# File 'lib/jack/config/diff.rb', line 5

def initialize(options={})
  @options = options
  @root = options[:root] || '.'
  @env_name = options[:env_name]
  @download = Jack::Config::Download.new(options)
end

Instance Attribute Details

#transmitObject (readonly)

Returns the value of attribute transmit.



4
5
6
# File 'lib/jack/config/diff.rb', line 4

def transmit
  @transmit
end

Instance Method Details

#cleanup_filesObject



29
30
31
32
# File 'lib/jack/config/diff.rb', line 29

def cleanup_files
  return false if @options[:dirty]
  @download.clean(mute=true)
end

#diff_commandObject



34
35
36
37
38
39
40
41
# File 'lib/jack/config/diff.rb', line 34

def diff_command
  return ENV['JACK_DIFF'] if ENV['JACK_DIFF']
  if system("type colordiff > /dev/null 2>&1")
    "colordiff"
  else
    "diff"
  end
end

#do_diff(current, local) ⇒ Object



18
19
20
21
22
23
24
25
26
27
# File 'lib/jack/config/diff.rb', line 18

def do_diff(current, local)
  UI.say "Comparing #{current} and #{local}"
  return if @options[:noop]
  sorter = YamlFormatter.new
  sorter.process(current)
  sorter.process(local)
  # need to use system so that the diff shows up properly in the terminal
  system(diff_command, @download.current_path, @download.local_config_path)
  puts ""
end

#runObject



12
13
14
15
16
# File 'lib/jack/config/diff.rb', line 12

def run
  @download.get_current_cfg
  do_diff(@download.current_path, @download.local_config_path)
  cleanup_files
end