Class: Hanami::Events::CloudPubsub::Subscriber Private

Inherits:
Subscriber
  • Object
show all
Defined in:
lib/hanami/events/cloud_pubsub/subscriber.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Subscriber class for calling subscriber blocks, with extra support for passing the raw message.

Since:

  • 0.1.0

Instance Method Summary collapse

Constructor Details

#initialize(event_name, handler, logger = nil, data_struct_class = nil) ⇒ Subscriber

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Subscriber.

Since:

  • 0.1.0



13
14
15
16
# File 'lib/hanami/events/cloud_pubsub/subscriber.rb', line 13

def initialize(event_name, handler, logger = nil, data_struct_class = nil)
  super
  @handler = handler
end

Instance Method Details

#call(event_name, payload, message) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 0.1.0



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/hanami/events/cloud_pubsub/subscriber.rb', line 18

def call(event_name, payload, message)
  return unless @pattern_matcher.match?(event_name)

  data_object = @data_struct_class ? @data_struct_class.new(payload) : payload

  if @handler.arity == 2
    @handler.call(data_object, message)
  else
    @handler.call(data_object)
  end
end