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
15
16
17
18
19
20
# File 'lib/capistrano_banner/base.rb', line 12

def banner
  if @path.end_with? ".erb"
    require 'erb'
    template = File.read(@path)
    ERB.new(template).result
  else
    File.read(@path)
  end
end

#color(overwrite = nil) ⇒ Object



34
35
36
37
38
39
40
41
42
# File 'lib/capistrano_banner/base.rb', line 34

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



22
23
24
# File 'lib/capistrano_banner/base.rb', line 22

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

#pauseObject



26
27
28
# File 'lib/capistrano_banner/base.rb', line 26

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


48
49
50
51
52
53
54
55
# File 'lib/capistrano_banner/base.rb', line 48

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

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

#promptObject



30
31
32
# File 'lib/capistrano_banner/base.rb', line 30

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

#warning_color?(color) ⇒ Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/capistrano_banner/base.rb', line 44

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