Class: Emque::Consuming::Router::Mapping
- Inherits:
-
Object
- Object
- Emque::Consuming::Router::Mapping
- Defined in:
- lib/emque/consuming/router.rb
Instance Attribute Summary collapse
-
#consumer ⇒ Object
readonly
Returns the value of attribute consumer.
-
#middleware ⇒ Object
readonly
Returns the value of attribute middleware.
-
#topic ⇒ Object
readonly
Returns the value of attribute topic.
-
#workers ⇒ Object
readonly
Returns the value of attribute workers.
Instance Method Summary collapse
-
#initialize(mapping, &block) ⇒ Mapping
constructor
A new instance of Mapping.
- #map(map) ⇒ Object
- #middleware? ⇒ Boolean
- #route(type) ⇒ Object
- #use(callable) ⇒ Object
Constructor Details
#initialize(mapping, &block) ⇒ Mapping
Returns a new instance of Mapping.
65 66 67 68 69 70 71 72 73 74 |
# File 'lib/emque/consuming/router.rb', line 65 def initialize(mapping, &block) self.topic = mapping.keys.first self.workers = mapping.fetch(:workers, 1) self.consumer = mapping.values.first self.mapping = {} self.middleware = [] mapping.fetch(:middleware, []).map(&:use) self.instance_eval(&block) end |
Instance Attribute Details
#consumer ⇒ Object
Returns the value of attribute consumer.
63 64 65 |
# File 'lib/emque/consuming/router.rb', line 63 def consumer @consumer end |
#middleware ⇒ Object
Returns the value of attribute middleware.
63 64 65 |
# File 'lib/emque/consuming/router.rb', line 63 def middleware @middleware end |
#topic ⇒ Object
Returns the value of attribute topic.
63 64 65 |
# File 'lib/emque/consuming/router.rb', line 63 def topic @topic end |
#workers ⇒ Object
Returns the value of attribute workers.
63 64 65 |
# File 'lib/emque/consuming/router.rb', line 63 def workers @workers end |
Instance Method Details
#map(map) ⇒ Object
76 77 78 |
# File 'lib/emque/consuming/router.rb', line 76 def map(map) mapping.merge!(map) end |
#middleware? ⇒ Boolean
80 81 82 |
# File 'lib/emque/consuming/router.rb', line 80 def middleware? middleware.count > 0 end |
#route(type) ⇒ Object
84 85 86 |
# File 'lib/emque/consuming/router.rb', line 84 def route(type) mapping[type] end |
#use(callable) ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/emque/consuming/router.rb', line 88 def use(callable) unless callable.respond_to?(:call) and callable.arity == 1 raise( ConfigurationError, "#{self.class.name}#use must receive a callable object with an " + "arity of one." ) end middleware << callable end |