Class: ConvoxInstaller::Config
- Inherits:
-
Object
- Object
- ConvoxInstaller::Config
- Defined in:
- lib/convox_installer/config.rb
Constant Summary collapse
- CONFIG_FILE =
File.('./.installer_config.json').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' }, # Short random ID used to ensure that resources are always unique { key: :random_id, value: -> { SecureRandom.hex(4) }, hidden: true } ].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.
Class Method Summary collapse
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.
50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/convox_installer/config.rb', line 50 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 |
Class Method Details
.config_file_exists? ⇒ Boolean
122 123 124 |
# File 'lib/convox_installer/config.rb', line 122 def self.config_file_exists? File.exist?(CONFIG_FILE) end |
.read_config_file ⇒ Object
126 127 128 |
# File 'lib/convox_installer/config.rb', line 126 def self.read_config_file File.read(CONFIG_FILE) end |
Instance Method Details
#config_keys ⇒ Object
63 64 65 |
# File 'lib/convox_installer/config.rb', line 63 def config_keys prompts.map { |prompt| prompt[:key] }.compact.map(&:to_sym) end |
#prompt_for_config ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/convox_installer/config.rb', line 67 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.' break if ENV['AUTOSTART_CONVOX_INSTALLATION'] 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
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/convox_installer/config.rb', line 99 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 |