Class: Clamour::Subscription

Inherits:
Object
  • Object
show all
Defined in:
lib/clamour/subscription.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(configuration = Clamour.configuration, registry = Clamour.registry) ⇒ Subscription

Returns a new instance of Subscription.

Parameters:



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

#configurationClamour::Configuration (readonly)



3
4
5
# File 'lib/clamour/subscription.rb', line 3

def configuration
  @configuration
end

#loggerLogger (readonly)

Returns:

  • (Logger)


6
7
8
# File 'lib/clamour/subscription.rb', line 6

def logger
  @logger
end

#registryClamour::Registry (readonly)

Returns:



9
10
11
# File 'lib/clamour/subscription.rb', line 9

def registry
  @registry
end

Instance Method Details

#busObject



33
34
35
# File 'lib/clamour/subscription.rb', line 33

def bus
  @bus ||= Clamour::Bus.new(configuration)
end

#performObject



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

Parameters:

  • type (String)
  • attributes (Hash)


27
28
29
30
31
# File 'lib/clamour/subscription.rb', line 27

def route(type, attributes)
  registry.route(type) do |handler_class, message_class|
    handler_class.perform(message_class.new(attributes), self)
  end
end