class Warren::App::Config
Handles the initial creation of the configuration object
Constants
- TEMPLATE
We keep the template as plain text as it allows us to add comments
Attributes
The exchange to connect to
The path to the config file
Public Class Methods
Triggers the configuration task. Primarily called by the Thor CLI. Will either use arguments passed in from the command line, or prompt the user for them if missing.
@param shell [Thor::Shell::Basic] Thor shell instance for feedback @param path [String] Path to the `warren.yml` file @param exchange [String, nil] Name of the exchange to use, if passed in from CLI
@return [Void]
# File lib/warren/app/config.rb, line 55 def self.invoke(shell, path:, exchange: nil) new(shell, path: path, exchange: exchange).invoke end
Generates a new warren.yml file at {#path}. Usually invoked via the `warren config` cli command
@param shell [Thor::Shell::Basic] Thor shell instance for user interaction @param path [String] The path to the warren.yml file. @param exchange [String] The exchange to connect to
# File lib/warren/app/config.rb, line 67 def initialize(shell, path:, exchange: nil) @shell = shell @path = path @exchange = exchange end
Public Instance Methods
Create a new configuration yaml file at {#path} using sensible defaults and the provided {#exchange}. If {#exchange} is nil, prompts the user
@return [Void]
# File lib/warren/app/config.rb, line 79 def invoke return unless check_file? @exchange ||= ask_exchange # Update our exchange before we do anything File.open(@path, 'w') do |file| file.write payload end end
Private Instance Methods
# File lib/warren/app/config.rb, line 105 def ask_exchange @shell.ask 'Specify an exchange: ' end
# File lib/warren/app/config.rb, line 99 def check_file? return true unless File.exist?(@path) @shell.yes? "#{@path} exists. Overwrite (Y/N)? " end
# File lib/warren/app/config.rb, line 95 def payload format(TEMPLATE, exchange: @exchange, vhost: '/') end