Class: Wukong::Deploy::Differ
- Inherits:
-
Object
- Object
- Wukong::Deploy::Differ
- Defined in:
- lib/wukong-deploy/templater/differ.rb
Instance Attribute Summary collapse
-
#existing_content ⇒ Object
Returns the value of attribute existing_content.
-
#new_content ⇒ Object
Returns the value of attribute new_content.
Instance Method Summary collapse
- #always_replace? ⇒ Boolean
- #diff ⇒ Object
- #get_response ⇒ Object
-
#initialize(new_content, existing_content) ⇒ Differ
constructor
A new instance of Differ.
- #never_replace? ⇒ Boolean
- #replace? ⇒ Boolean
- #resolve! ⇒ Object
- #show_diff ⇒ Object
- #show_help ⇒ Object
Constructor Details
#initialize(new_content, existing_content) ⇒ Differ
Returns a new instance of Differ.
10 11 12 13 |
# File 'lib/wukong-deploy/templater/differ.rb', line 10 def initialize new_content, existing_content self.new_content = new_content self.existing_content = existing_content end |
Instance Attribute Details
#existing_content ⇒ Object
Returns the value of attribute existing_content.
8 9 10 |
# File 'lib/wukong-deploy/templater/differ.rb', line 8 def existing_content @existing_content end |
#new_content ⇒ Object
Returns the value of attribute new_content.
7 8 9 |
# File 'lib/wukong-deploy/templater/differ.rb', line 7 def new_content @new_content end |
Instance Method Details
#always_replace? ⇒ Boolean
19 20 21 |
# File 'lib/wukong-deploy/templater/differ.rb', line 19 def always_replace? @always_replace end |
#diff ⇒ Object
43 44 45 |
# File 'lib/wukong-deploy/templater/differ.rb', line 43 def diff @diff = Diffy::Diff.new(new_content, existing_content, :allow_empty_diff => true, :diff => "-U 5", :include_diff_info => true) end |
#get_response ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/wukong-deploy/templater/differ.rb', line 65 def get_response STDOUT.write ' Overwrite? (enter "h" for help) [YNynqdh]: ' begin response = STDIN.readline.chomp.strip rescue EOFError, Interrupt => e exit(1) end case when response =~ /^(y|n|Y|N)/ response when response =~ /^q/i exit(1) when response =~ /^d/i show_diff get_response when response =~ /^h/i show_help get_response else get_response end end |
#never_replace? ⇒ Boolean
23 24 25 |
# File 'lib/wukong-deploy/templater/differ.rb', line 23 def never_replace? @never_replace end |
#replace? ⇒ Boolean
15 16 17 |
# File 'lib/wukong-deploy/templater/differ.rb', line 15 def replace? @replace end |
#resolve! ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/wukong-deploy/templater/differ.rb', line 27 def resolve! response = get_response case response when /^y/ @replace = true when /^Y/ @replace = true @always_replace = true when /^n/ @replace = false when /^N/ @replace = false @never_replace = true end end |
#show_diff ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/wukong-deploy/templater/differ.rb', line 47 def show_diff puts '' diff.each do |line| puts " #{line}" end puts '' end |
#show_help ⇒ Object
55 56 57 58 59 60 61 62 63 |
# File 'lib/wukong-deploy/templater/differ.rb', line 55 def show_help puts " Y - yes, overwrite this file and all other conflicts" puts " y - yes, overwrite this file" puts " N - no, skip this file and all other conflicts" puts " n - no, skip this file" puts " d - diff, show the differences between the existing file and the new file" puts " q - quit, abort" puts " h - help, show this help" end |