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::Get.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



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

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

#compute_diff(current, local) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/jack/config/diff.rb', line 19

def compute_diff(current, local)
  # the diff command returns 0 when there is no difference and returns 1 when there is a difference
  pretty_current_path = @download.current_path.sub(/.*\.elasticbeanstalk/,'.elasticbeanstalk')
  command = "#{diff_command} #{pretty_current_path} #{@download.local_config_path}"
  UI.say("=> #{command}")

  return if @options[:noop]
  sorter = YamlFormatter.new
  sorter.process(current)
  sorter.process(local)

  no_difference = system(command)
  !no_difference
end

#diff_commandObject



39
40
41
42
43
44
45
46
# File 'lib/jack/config/diff.rb', line 39

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

#runObject



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

def run
  @download.get_current_cfg
  difference = compute_diff(@download.current_path, @download.local_config_path)
  cleanup_files
  difference
end