Class: Warren::App::ConsumerAdd

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

Overview

Handles the initial creation of the configuration object

Constant Summary collapse

SUBSCRIBER_NAMESPACE =

Default namespace for new Subscribers

%w[Warren Subscriber].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(shell, name, options) ⇒ ConsumerAdd

Create a consumer configuration object. Use #invoke to gather information and generate the config

Parameters:

  • shell (Thor::Shell::Basic)

    Thor shell instance for feedback

  • name (String)

    The name of the consumer

  • options (Hash)

    Hash of command line arguments from Thor

Options Hash (options):

  • :desc (String)

    Short description of consumer (for documentation)

  • :queue (String)

    Then name of the queue to bind to

  • :bindings (Array<String>)

    Array of binding in the format ‘<exchange_type>:<exchange_name>:<outing_key>,<routing_key>’



45
46
47
48
49
50
51
52
53
# File 'lib/warren/app/consumer_add.rb', line 45

def initialize(shell, name, options)
  @shell = shell
  @name = name
  @desc = options[:desc]
  @queue = options[:queue]
  @delay = options[:delay]
  @config = Warren::Config::Consumers.new(options[:path])
  @bindings = Warren::App::ExchangeConfig.parse(shell, options[:bindings])
end

Instance Attribute Details

#descObject (readonly)

Returns the value of attribute desc.



13
14
15
# File 'lib/warren/app/consumer_add.rb', line 13

def desc
  @desc
end

#nameObject (readonly)

Returns the value of attribute name.



13
14
15
# File 'lib/warren/app/consumer_add.rb', line 13

def name
  @name
end

#queueObject (readonly)

Returns the value of attribute queue.



13
14
15
# File 'lib/warren/app/consumer_add.rb', line 13

def queue
  @queue
end

Class Method Details

.invoke(shell, name, options) ⇒ ConsumerAdd

Add a consumer to the configuration file located at ‘options.path` Will prompt the user for input on the `shell` if information not provided upfront

Parameters:

  • shell (Thor::Shell::Basic)

    Thor shell instance for feedback

  • name (String)

    The name of the consumer

  • options (Hash)

    Hash of command line arguments from Thor

Options Hash (options):

  • :desc (String)

    Short description of consumer (for documentation)

  • :queue (String)

    Then name of the queue to bind to

  • :bindings (Array<String>)

    Array of binding in the format ‘<exchange_type>:<exchange_name>:<outing_key>,<routing_key>’

Returns:



30
31
32
# File 'lib/warren/app/consumer_add.rb', line 30

def self.invoke(shell, name, options)
  new(shell, name, options).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)


61
62
63
64
65
66
67
# File 'lib/warren/app/consumer_add.rb', line 61

def invoke
  check_name if @name # Check name before we gather facts, as its better to know we
  # might have an issue early.
  gather_facts
  write_configuration
  write_subscriber
end