Class: Warren::App::ExchangeConfig

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

Overview

Generate configuration for the various exchange types

Constant Summary collapse

EXCHANGE_PROMPT =
<<~TYPE
  Add an exchange binding:
    (d)irect
    (f)anout
    (t)opic
    (h)eaders
    (n)one - Stop adding bindings
TYPE

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(shell) ⇒ ExchangeConfig

Returns a new instance of ExchangeConfig.



46
47
48
49
# File 'lib/warren/app/exchange_config.rb', line 46

def initialize(shell)
  @shell = shell
  @bindings = []
end

Instance Attribute Details

#bindingsArray (readonly)

Returns An array of all binding configurations.

Returns:

  • (Array)

    An array of all binding configurations



17
18
19
# File 'lib/warren/app/exchange_config.rb', line 17

def bindings
  @bindings
end

Class Method Details

.ask(shell) ⇒ Array<Hash>

Prompts the user to configure multiple queue bindings and returns the bindings array.

Parameters:

  • shell (Thor::Shell::Basic)

    A thor shell object for user communication

Returns:

  • (Array<Hash>)

    A configuration array



27
28
29
# File 'lib/warren/app/exchange_config.rb', line 27

def self.ask(shell)
  ExchangeConfig.new(shell).tap(&:gather_bindings).bindings
end

.default_dead_letter(name) ⇒ Object



69
70
71
# File 'lib/warren/app/exchange_config.rb', line 69

def self.default_dead_letter(name)
  new(nil).add_binding('fanout', name, {})
end

.parse(shell, bindings) ⇒ Array<Hash>

Extracts the binding configuration from the command line parameters

Parameters:

  • shell (Array<String>)

    The binding configuration parameters

Returns:

  • (Array<Hash>)

    A configuration array



38
39
40
41
42
43
44
# File 'lib/warren/app/exchange_config.rb', line 38

def self.parse(shell, bindings)
  return if bindings.nil?

  ExchangeConfig.new(shell).tap do |config|
    config.parse(bindings)
  end.bindings
end

Instance Method Details

#add_binding(type, name, options) ⇒ Object



73
74
75
# File 'lib/warren/app/exchange_config.rb', line 73

def add_binding(type, name, options)
  @bindings << config(type, name, options)
end

#gather_bindingsObject



51
52
53
54
55
56
57
58
59
60
61
# File 'lib/warren/app/exchange_config.rb', line 51

def gather_bindings
  loop do
    case ask_exchange_type
    when 'd' then ask_direct_binding
    when 'f' then ask_fanout_binding
    when 't' then ask_topic_binding
    when 'h' then ask_header_binding
    when 'n' then break
    end
  end
end

#parse(bindings) ⇒ Object



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

def parse(bindings)
  bindings.each do |binding|
    add_cli_binding(*binding.split(':'))
  end
end