lib/google_pubsub_enhancer/publisher.rb in google-pubsub-enhancer-0.1.1 vs lib/google_pubsub_enhancer/publisher.rb in google-pubsub-enhancer-0.1.2
- old
+ new
@@ -3,20 +3,18 @@
def initialize(app, opts={})
@app = app
@short_topic_name = opts[:short_topic_name] || raise
@full_topic_name = GooglePubsubEnhancer.name_by('topics',@short_topic_name)
@messages_key = opts[:messages] || raise
+ @google_cloud_pubsub ||= Google::Cloud::Pubsub.new
end
def call(env)
- google_cloud_pubsub.publish(@full_topic_name) do |publisher|
+ @google_cloud_pubsub.publish(@full_topic_name) do |publisher|
[*env[@messages_key]].each do |m|
publisher.publish(m)
end
end
@app.call(env)
end
- def google_cloud_pubsub
- Google::Cloud::Pubsub.new
- end
end