Class: Warren::App::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/warren/app/config.rb

Overview

Handles the initial creation of the configuration object

Constant Summary collapse

TEMPLATE =

We keep the template as plain text as it allows us to add comments

"# By default the development environment just logs the message and\n# payload. If you wish to enable broadcasting in development mode,\n# the easiest way to do so is to set the ENV WARREN_TYPE.\n# For example\n# `WARREN_TYPE=broadcast bundle exec rails s`\n# This will override the setting in warren.yml\ndevelopment:\n  type: log\n  # Log mode does not actually use this configuration, but\n  # it is provided for convenience when broadcast mode is enabled.\n  # The provided settings are the default options of RabbitMQ\n  # DO NOT commit sensitive information in this file. Instead you may\n  # use the WARREN_CONNECTION_URI environmental variable\n  config:\n    server:\n      host: localhost\n      port: 5672\n      username: guest\n      password: guest\n      vhost: %<vhost>s\n      frame_max: 0\n      heartbeat: 30\n    exchange: %<exchange>s\n    routing_key_prefix: development\n# The test environment sets up a test message handler, which lets\n# you make assertions about which messages have been sent.\n# See: https://rubydoc.info/gems/sanger_warren/Warren/Handler/Test\ntest:\n  type: test\n  config:\n    routing_key_prefix: test\n# You are encouraged to use the WARREN_CONNECTION_URI environmental\n# variable to configure your production environment. Under no\n# circumstances should you commit sensitive information in the file.\n"

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(shell, path:, exchange: nil) ⇒ Config

Generates a new warren.yml file at #path. Usually invoked via the ‘warren config` cli command

Parameters:

  • shell (Thor::Shell::Basic)

    Thor shell instance for user interaction

  • path (String)

    The path to the warren.yml file.

  • exchange (String) (defaults to: nil)

    The exchange to connect to



67
68
69
70
71
# File 'lib/warren/app/config.rb', line 67

def initialize(shell, path:, exchange: nil)
  @shell = shell
  @path = path
  @exchange = exchange
end

Class Method Details

.invoke(shell, path:, exchange: nil) ⇒ Void

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.

Parameters:

  • shell (Thor::Shell::Basic)

    Thor shell instance for feedback

  • path (String)

    Path to the ‘warren.yml` file

  • exchange (String, nil) (defaults to: nil)

    Name of the exchange to use, if passed in from CLI

Returns:

  • (Void)


55
56
57
# File 'lib/warren/app/config.rb', line 55

def self.invoke(shell, path:, exchange: nil)
  new(shell, path: path, exchange: exchange).invoke
end

Instance Method Details

#invokeVoid

Create a new configuration yaml file at #path using sensible defaults and the provided #exchange. If #exchange is nil, prompts the user

Returns:

  • (Void)


79
80
81
82
83
84
85
86
# 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