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

exchange[R]

The exchange to connect to

path[R]

The path to the config file

Public Class Methods

invoke(shell, path:, exchange: nil) click to toggle source

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
new(shell, path:, exchange: nil) click to toggle source

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

invoke() click to toggle source

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

ask_exchange() click to toggle source
# File lib/warren/app/config.rb, line 105
def ask_exchange
  @shell.ask 'Specify an exchange: '
end
check_file?() click to toggle source
# 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
payload() click to toggle source
# File lib/warren/app/config.rb, line 95
def payload
  format(TEMPLATE, exchange: @exchange, vhost: '/')
end