hanami-events-cloud_pubsub 3.2.1 → 3.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cedb970c9a8160f1d3b1e1c41dd87b5bfb8d35cb29872694af944110f681b7fc
4
- data.tar.gz: 277273b17749ba058a545f1caadc3819688964c9fccaaf34a1774b7445f4b86f
3
+ metadata.gz: de5b89251e969ff280f708bfe2453b6f182b3bca5e50bfd98b9e8be372123562
4
+ data.tar.gz: d71ccf32872fae21acb045a8786b7935f051f92a25ff47ad6ff1340a0c88d44a
5
5
  SHA512:
6
- metadata.gz: 2f76c43c7a07b590e9c9f6b7e8839d5ab37266c4b353099bfc1a872308db646c5a4421a3185c13e20d55a80e7a67242fac975824b29de4f0afee51a6af1e2d6f
7
- data.tar.gz: af41acad939eabcf399b7f7936b54a99f173a00da497991929de64ebb00dbd3b0da8f48f917dfc1f8b818227671744631b6d6e260c4706c4a901086d479d1f1f
6
+ metadata.gz: 7740508a3898f859a59fbb39377bb2d6977ec06f48cf2671d177aa647c355945b50209a3b0b3c6815d1222424df7d998a83bb9402b0918118636c8fe053776fb
7
+ data.tar.gz: dd52a0e85056371712d695c6a2fd9650c49d5dfdaaff2c2afdf41cced04e61b2a12633eb2ee185eaa23dd15c40dcbfebef021ec92e14cdcdfa985de5951e7edd
@@ -11,13 +11,12 @@ module Hanami
11
11
  #
12
12
  # @api private
13
13
  class CloudPubsub
14
- attr_reader :subscribers, :listeners, :topic_registry, :middleware
14
+ attr_reader :listeners, :topic_registry, :middleware
15
15
 
16
16
  def initialize(params)
17
17
  @pubsub = params[:pubsub]
18
18
  @logger = params[:logger] || Logger.new($stdout)
19
19
  @listen = params[:listen] || false
20
- @subscribers = Concurrent::Array.new
21
20
  @listeners = Concurrent::Array.new
22
21
  @serializer_type = params.fetch(:serializer, :json).to_sym
23
22
  @topic_registry = {}
@@ -61,10 +60,9 @@ module Hanami
61
60
  logger.debug("Subscribed listener \"#{id}\" for event \"#{event_name}\"")
62
61
 
63
62
  sub = Hanami::Events::CloudPubsub::Subscriber.new(event_name, block, logger)
64
- @subscribers << sub
65
63
  topic = topic_for event_name
66
64
 
67
- register_listener(event_name, topic, namespaced_id, auto_ack, subscriber_opts)
65
+ register_listener(event_name, topic, namespaced_id, auto_ack, subscriber_opts, sub)
68
66
  end
69
67
 
70
68
  def flush_messages
@@ -76,11 +74,12 @@ module Hanami
76
74
 
77
75
  attr_reader :logger
78
76
 
79
- def register_listener(event_name, topic, subscriber_id, auto_ack, subscriber_opts)
77
+ # rubocop:disable Metrics/ParameterLists
78
+ def register_listener(event_name, topic, subscriber_id, auto_ack, subscriber_opts, sub)
80
79
  listener = ::Hanami::Events::CloudPubsub::Listener.new(
81
80
  subscriber_id: subscriber_id,
82
81
  event_name: event_name,
83
- handler: method(:call_subscribers),
82
+ handler: call_subscriber(sub),
84
83
  logger: logger,
85
84
  topic: topic,
86
85
  subscriber_opts: subscriber_opts,
@@ -91,14 +90,15 @@ module Hanami
91
90
  @listeners << listener
92
91
  listener.register
93
92
  end
93
+ # rubocop:enable Metrics/ParameterLists
94
94
 
95
- def call_subscribers(message)
96
- data = message.data
97
- payload = serializer.deserialize(data)
98
- event_name = message.attributes['event_name']
95
+ def call_subscriber(sub)
96
+ proc do |message|
97
+ data = message.data
98
+ payload = serializer.deserialize(data)
99
+ event_name = message.attributes['event_name']
99
100
 
100
- @subscribers.each do |subscriber|
101
- subscriber.call(event_name, payload, message)
101
+ sub.call(event_name, payload, message)
102
102
  end
103
103
  end
104
104
 
@@ -3,7 +3,7 @@
3
3
  module Hanami
4
4
  module Events
5
5
  module CloudPubsub
6
- VERSION = '3.2.1'
6
+ VERSION = '3.3.0'
7
7
  end
8
8
  end
9
9
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hanami-events-cloud_pubsub
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.2.1
4
+ version: 3.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ian Ker-Seymer