Class: Warren::App::ExchangeConfig
- Inherits:
-
Object
- Object
- Warren::App::ExchangeConfig
- 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
-
#bindings ⇒ Array
readonly
An array of all binding configurations.
Class Method Summary collapse
-
.ask(shell) ⇒ Array<Hash>
Prompts the user to configure multiple queue bindings and returns the bindings array.
- .default_dead_letter(name) ⇒ Object
-
.parse(shell, bindings) ⇒ Array<Hash>
Extracts the binding configuration from the command line parameters.
Instance Method Summary collapse
- #add_binding(type, name, options) ⇒ Object
- #gather_bindings ⇒ Object
-
#initialize(shell) ⇒ ExchangeConfig
constructor
A new instance of ExchangeConfig.
- #parse(bindings) ⇒ Object
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
#bindings ⇒ Array (readonly)
Returns 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.
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
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, ) @bindings << config(type, name, ) end |
#gather_bindings ⇒ Object
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 |