Class: Msgr::Route
- Inherits:
-
Object
- Object
- Msgr::Route
- Defined in:
- lib/msgr/route.rb
Constant Summary collapse
- MATCH_REGEXP =
/\A(?<consumer>\w+)#(?<action>\w+)\z/
Instance Attribute Summary collapse
-
#action ⇒ Object
readonly
Returns the value of attribute action.
-
#consumer ⇒ Object
readonly
Returns the value of attribute consumer.
-
#opts ⇒ Object
readonly
Returns the value of attribute opts.
Instance Method Summary collapse
- #accept?(_key, opts) ⇒ Boolean
- #add(key) ⇒ Object
-
#initialize(key, opts = {}) ⇒ Route
constructor
rubocop:disable Metrics/AbcSize rubocop:disable Metrics/MethodLength.
- #keys ⇒ Object (also: #routing_keys)
- #name ⇒ Object
- #prefetch ⇒ Object
Constructor Details
#initialize(key, opts = {}) ⇒ Route
rubocop:disable Metrics/AbcSize rubocop:disable Metrics/MethodLength
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/msgr/route.rb', line 11 def initialize(key, opts = {}) @opts = opts raise ArgumentError.new 'Missing `to` options.' unless @opts[:to] add key result = MATCH_REGEXP.match(opts[:to].strip.to_s) unless result raise ArgumentError.new \ "Invalid consumer format: #{opts[:to].strip.to_s.inspect}. " \ 'Must be `consumer_class#action`.' end @consumer = "#{result[:consumer].camelize}Consumer" @action = result[:action].underscore end |
Instance Attribute Details
#action ⇒ Object (readonly)
Returns the value of attribute action.
5 6 7 |
# File 'lib/msgr/route.rb', line 5 def action @action end |
#consumer ⇒ Object (readonly)
Returns the value of attribute consumer.
5 6 7 |
# File 'lib/msgr/route.rb', line 5 def consumer @consumer end |
#opts ⇒ Object (readonly)
Returns the value of attribute opts.
5 6 7 |
# File 'lib/msgr/route.rb', line 5 def opts @opts end |
Instance Method Details
#accept?(_key, opts) ⇒ Boolean
44 45 46 |
# File 'lib/msgr/route.rb', line 44 def accept?(_key, opts) self.opts == opts end |
#add(key) ⇒ Object
38 39 40 41 42 |
# File 'lib/msgr/route.rb', line 38 def add(key) raise ArgumentError.new 'Routing key required.' unless key.present? keys << key end |
#keys ⇒ Object Also known as: routing_keys
29 30 31 |
# File 'lib/msgr/route.rb', line 29 def keys @keys ||= [] end |
#name ⇒ Object
48 49 50 |
# File 'lib/msgr/route.rb', line 48 def name "msgr.consumer.#{consumer}.#{action}" end |
#prefetch ⇒ Object
34 35 36 |
# File 'lib/msgr/route.rb', line 34 def prefetch @opts[:prefetch] || 1 end |