Class: CapistranoBanner::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/capistrano_banner/base.rb

Instance Method Summary collapse

Constructor Details

#initialize(stage, path) ⇒ Base

Returns a new instance of Base.



6
7
8
9
10
# File 'lib/capistrano_banner/base.rb', line 6

def initialize(stage, path)
  @stage = stage
  @path = path
  @ui = HighLine.new
end

Instance Method Details



12
13
14
# File 'lib/capistrano_banner/base.rb', line 12

def banner
  File.read(@path)
end

#color(overwrite = nil) ⇒ Object



28
29
30
31
32
33
34
35
36
# File 'lib/capistrano_banner/base.rb', line 28

def color(overwrite = nil)
  return overwrite if overwrite

  case @stage
  when :production ; :red
  when :staging    ; :yellow
  else :green      ; :green
  end
end

#color_banner(color) ⇒ Object



16
17
18
# File 'lib/capistrano_banner/base.rb', line 16

def color_banner(color)
  Term::ANSIColor.send(color, Term::ANSIColor.bold(banner))
end

#pauseObject



20
21
22
# File 'lib/capistrano_banner/base.rb', line 20

def pause
  exit unless @ui.agree(prompt)
end


42
43
44
45
46
47
48
49
# File 'lib/capistrano_banner/base.rb', line 42

def print_banner(options)
  c = color(options[:color])
  puts color_banner(c)

  if !options[:force] && (warning_color?(c) || options[:pause])
    pause
  end
end

#promptObject



24
25
26
# File 'lib/capistrano_banner/base.rb', line 24

def prompt
  "This is #{Term::ANSIColor.send(color, @stage.to_s)} stage. Are you ready? (y/N) >"
end

#warning_color?(color) ⇒ Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/capistrano_banner/base.rb', line 38

def warning_color?(color)
  color == :red
end