Module: Terradactyl::Common

Included in:
CLI, Stack, Stacks, StacksPlanFilterDefault
Defined in:
lib/terradactyl/common.rb

Constant Summary collapse

COLUMN_WIDTH =
80
BORDER_CHAR =
'#'

Class Method Summary collapse

Class Method Details

.borderObject



30
31
32
# File 'lib/terradactyl/common.rb', line 30

def border
  BORDER_CHAR * COLUMN_WIDTH
end

.centreObject



34
35
36
# File 'lib/terradactyl/common.rb', line 34

def centre
  COLUMN_WIDTH / 2
end

.configObject



18
19
20
# File 'lib/terradactyl/common.rb', line 18

def config
  @config ||= ConfigProject.instance
end

.cputs(msg, color) ⇒ Object



89
90
91
# File 'lib/terradactyl/common.rb', line 89

def cputs(msg, color)
  puts config.misc.disable_color ? msg : msg.send(color.to_s)
end

.dot_iconObject



38
39
40
# File 'lib/terradactyl/common.rb', line 38

def dot_icon
  config.misc.utf8 ? '' : '*'
end


58
59
60
61
62
63
# File 'lib/terradactyl/common.rb', line 58

def print_content(content)
  content.split("\n").each do |line|
    print_line line
  end
  puts
end


46
47
48
# File 'lib/terradactyl/common.rb', line 46

def print_crit(msg)
  print_message(msg, :light_red)
end


65
66
67
68
# File 'lib/terradactyl/common.rb', line 65

def print_dot(msg, color = :light_blue)
  string = "     #{dot_icon} #{msg}"
  cputs(string, color)
end


81
82
83
84
85
86
87
# File 'lib/terradactyl/common.rb', line 81

def print_header(msg, color = :blue)
  indent  = centre + msg.size / 2 - 1
  content = format("#%#{indent}s", "#{tag} | #{msg}")
  string  = [border, content, border].join("\n")
  cputs(string, color)
  puts
end


70
71
72
73
# File 'lib/terradactyl/common.rb', line 70

def print_line(msg, color = :light_blue)
  string = "     #{msg}"
  cputs(string, color)
end


75
76
77
78
79
# File 'lib/terradactyl/common.rb', line 75

def print_message(msg, color = :light_blue)
  string = "#{stack_icon}[#{tag}] #{msg}"
  cputs(string, color)
  puts
end


50
51
52
# File 'lib/terradactyl/common.rb', line 50

def print_ok(msg)
  print_message(msg, :light_green)
end


54
55
56
# File 'lib/terradactyl/common.rb', line 54

def print_warning(msg)
  print_message(msg, :light_yellow)
end

.required_versions_reObject



10
11
12
# File 'lib/terradactyl/common.rb', line 10

def required_versions_re
  /(?<assignment>(?:\n\s)*required_version\s+=\s+)(?<value>".*?")/m
end

.stack_iconObject



42
43
44
# File 'lib/terradactyl/common.rb', line 42

def stack_icon
  config.misc.utf8 ? '  𝓣  ' : '  |||  '
end

.supported_revisionsObject



14
15
16
# File 'lib/terradactyl/common.rb', line 14

def supported_revisions
  Terradactyl::Commands.constants.select { |c| c =~ /Rev/ }.sort
end

.tagObject



26
27
28
# File 'lib/terradactyl/common.rb', line 26

def tag
  'Terradactyl'
end

.terraform_binaryObject



22
23
24
# File 'lib/terradactyl/common.rb', line 22

def terraform_binary
  config.terraform.binary || %(terraform)
end