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
- .border ⇒ Object
- .centre ⇒ Object
- .config ⇒ Object
- .cputs(msg, color) ⇒ Object
- .dot_icon ⇒ Object
- .print_content(content) ⇒ Object
- .print_crit(msg) ⇒ Object
- .print_dot(msg, color = :light_blue) ⇒ Object
- .print_header(msg, color = :blue) ⇒ Object
- .print_line(msg, color = :light_blue) ⇒ Object
- .print_message(msg, color = :light_blue) ⇒ Object
- .print_ok(msg) ⇒ Object
- .print_warning(msg) ⇒ Object
- .required_versions_re ⇒ Object
- .stack_icon ⇒ Object
- .supported_revisions ⇒ Object
- .tag ⇒ Object
- .terraform_binary ⇒ Object
Class Method Details
.border ⇒ Object
30 31 32 |
# File 'lib/terradactyl/common.rb', line 30 def border BORDER_CHAR * COLUMN_WIDTH end |
.centre ⇒ Object
34 35 36 |
# File 'lib/terradactyl/common.rb', line 34 def centre COLUMN_WIDTH / 2 end |
.config ⇒ Object
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_icon ⇒ Object
38 39 40 |
# File 'lib/terradactyl/common.rb', line 38 def dot_icon config.misc.utf8 ? '•' : '*' end |
.print_content(content) ⇒ Object
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 |
.print_crit(msg) ⇒ Object
46 47 48 |
# File 'lib/terradactyl/common.rb', line 46 def print_crit(msg) (msg, :light_red) end |
.print_dot(msg, color = :light_blue) ⇒ Object
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 |
.print_header(msg, color = :blue) ⇒ Object
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 |
.print_line(msg, color = :light_blue) ⇒ Object
70 71 72 73 |
# File 'lib/terradactyl/common.rb', line 70 def print_line(msg, color = :light_blue) string = " #{msg}" cputs(string, color) end |
.print_message(msg, color = :light_blue) ⇒ Object
75 76 77 78 79 |
# File 'lib/terradactyl/common.rb', line 75 def (msg, color = :light_blue) string = "#{stack_icon}[#{tag}] #{msg}" cputs(string, color) puts end |
.print_ok(msg) ⇒ Object
50 51 52 |
# File 'lib/terradactyl/common.rb', line 50 def print_ok(msg) (msg, :light_green) end |
.print_warning(msg) ⇒ Object
54 55 56 |
# File 'lib/terradactyl/common.rb', line 54 def print_warning(msg) (msg, :light_yellow) end |
.required_versions_re ⇒ Object
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_icon ⇒ Object
42 43 44 |
# File 'lib/terradactyl/common.rb', line 42 def stack_icon config.misc.utf8 ? ' 𝓣 ' : ' ||| ' end |
.supported_revisions ⇒ Object
14 15 16 |
# File 'lib/terradactyl/common.rb', line 14 def supported_revisions Terradactyl::Commands.constants.select { |c| c =~ /Rev/ }.sort end |
.tag ⇒ Object
26 27 28 |
# File 'lib/terradactyl/common.rb', line 26 def tag 'Terradactyl' end |
.terraform_binary ⇒ Object
22 23 24 |
# File 'lib/terradactyl/common.rb', line 22 def terraform_binary config.terraform.binary || %(terraform) end |