Class: ConvoxInstaller::Config
- Inherits:
-
Object
- Object
- ConvoxInstaller::Config
- Defined in:
- lib/convox_installer/config.rb
Constant Summary collapse
- CONFIG_FILE =
File.("./.installer_config").freeze
- DEFAULT_PROMPTS =
[ { key: :stack_name, title: "Convox Stack Name", prompt: "Please enter a name for your Convox installation", default: "convox", }, { key: :aws_region, title: "AWS Region", default: "us-east-1", }, { key: :instance_type, title: "EC2 Instance Type", default: "t3.medium", }, { section: "Admin AWS Credentials", }, { key: :aws_access_key_id, title: "AWS Access Key ID", }, { key: :aws_secret_access_key, title: "AWS Secret Access Key", }, ].freeze
Instance Attribute Summary collapse
-
#config ⇒ Object
Returns the value of attribute config.
-
#highline ⇒ Object
Returns the value of attribute highline.
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#prompts ⇒ Object
Returns the value of attribute prompts.
Instance Method Summary collapse
- #config_keys ⇒ Object
-
#initialize(options = {}) ⇒ Config
constructor
A new instance of Config.
- #prompt_for_config ⇒ Object
- #show_config_summary ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Config
Returns a new instance of Config.
44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/convox_installer/config.rb', line 44 def initialize( = {}) @logger = Logger.new(STDOUT) logger.level = [:log_level] || Logger::INFO self.prompts = [:prompts] || DEFAULT_PROMPTS self.config = {} load_config_from_file load_config_from_env self.config = config.merge(([:config] || {}).symbolize_keys) self.highline = [:highline] || HighLine.new end |
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
12 13 14 |
# File 'lib/convox_installer/config.rb', line 12 def config @config end |
#highline ⇒ Object
Returns the value of attribute highline.
12 13 14 |
# File 'lib/convox_installer/config.rb', line 12 def highline @highline end |
#logger ⇒ Object
Returns the value of attribute logger.
12 13 14 |
# File 'lib/convox_installer/config.rb', line 12 def logger @logger end |
#prompts ⇒ Object
Returns the value of attribute prompts.
12 13 14 |
# File 'lib/convox_installer/config.rb', line 12 def prompts @prompts end |
Instance Method Details
#config_keys ⇒ Object
57 58 59 |
# File 'lib/convox_installer/config.rb', line 57 def config_keys prompts.map { |prompt| prompt[:key] }.compact.map(&:to_sym) end |
#prompt_for_config ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/convox_installer/config.rb', line 61 def prompt_for_config loop do prompts.each do |prompt| if prompt[:section] highline.say "\n#{prompt[:section]}" highline.say "============================================\n\n" end next unless prompt[:key] ask_prompt(prompt) end show_config_summary @completed_prompt = true highline.say "Please double check all of these configuration details." agree = highline.agree( "Would you like to start the Convox installation?" \ " (press 'n' to correct any settings)" ) break if agree highline.say "\n" end config end |
#show_config_summary ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/convox_installer/config.rb', line 90 def show_config_summary highline.say "\n============================================" highline.say " SUMMARY" highline.say "============================================\n\n" config_titles = prompts.map do |prompt| prompt[:title] || prompt[:key] end.compact max = config_titles.map(&:length).max prompts.each do |prompt| next if !prompt[:key] || prompt[:hidden] value = config[prompt[:key]] title = prompt[:title] || prompt[:key] padded_key = "#{title}:".ljust(max + 3) highline.say " #{padded_key} #{value}" end highline.say "\nWe've saved your configuration to: #{CONFIG_FILE}" highline.say "If anything goes wrong during the installation, " \ "you can restart the script to reload the config and continue.\n\n" end |