Class: Clamour::Subscription
- Inherits:
-
Object
- Object
- Clamour::Subscription
- Defined in:
- lib/clamour/subscription.rb
Instance Attribute Summary collapse
- #configuration ⇒ Clamour::Configuration readonly
- #logger ⇒ Logger readonly
- #registry ⇒ Clamour::Registry readonly
Instance Method Summary collapse
- #bus ⇒ Object
-
#initialize(configuration = Clamour.configuration, registry = Clamour.registry) ⇒ Subscription
constructor
A new instance of Subscription.
- #perform ⇒ Object
- #route(type, attributes) ⇒ Object
Constructor Details
#initialize(configuration = Clamour.configuration, registry = Clamour.registry) ⇒ Subscription
Returns a new instance of Subscription.
12 13 14 15 16 |
# File 'lib/clamour/subscription.rb', line 12 def initialize(configuration = Clamour.configuration, registry = Clamour.registry) @configuration = configuration @logger = configuration.logger @registry = registry end |
Instance Attribute Details
#configuration ⇒ Clamour::Configuration (readonly)
3 4 5 |
# File 'lib/clamour/subscription.rb', line 3 def configuration @configuration end |
#logger ⇒ Logger (readonly)
6 7 8 |
# File 'lib/clamour/subscription.rb', line 6 def logger @logger end |
#registry ⇒ Clamour::Registry (readonly)
9 10 11 |
# File 'lib/clamour/subscription.rb', line 9 def registry @registry end |
Instance Method Details
#bus ⇒ Object
33 34 35 |
# File 'lib/clamour/subscription.rb', line 33 def bus @bus ||= Clamour::Bus.new(configuration) end |
#perform ⇒ Object
18 19 20 21 22 23 |
# File 'lib/clamour/subscription.rb', line 18 def perform bus.subscribe do |received_hash| type = received_hash[:_type] route(type, received_hash) end end |
#route(type, attributes) ⇒ Object
27 28 29 30 31 |
# File 'lib/clamour/subscription.rb', line 27 def route(type, attributes) registry.route(type) do |handler_class, | handler_class.perform(.new(attributes), self) end end |