Class: Gcpc::Publisher::Engine
- Inherits:
-
Object
- Object
- Gcpc::Publisher::Engine
- Defined in:
- lib/gcpc/publisher/engine.rb,
lib/gcpc/publisher/engine/batch_engine.rb,
lib/gcpc/publisher/engine/chained_interceptor.rb
Defined Under Namespace
Classes: BatchEngine, ChainedInterceptor
Instance Attribute Summary collapse
-
#topic ⇒ Object
readonly
Returns the value of attribute topic.
Instance Method Summary collapse
-
#initialize(topic:, interceptors:) ⇒ Engine
constructor
A new instance of Engine.
- #publish(data, attributes = {}) ⇒ Object
- #publish_async(data, attributes = {}, &block) ⇒ Object
- #publish_batch(&block) {|batch_engine| ... } ⇒ Object
Constructor Details
#initialize(topic:, interceptors:) ⇒ Engine
Returns a new instance of Engine.
9 10 11 12 13 |
# File 'lib/gcpc/publisher/engine.rb', line 9 def initialize(topic:, interceptors:) @topic = topic interceptors = interceptors.map { |i| (i.class == Class) ? i.new : i } @interceptor = ChainedInterceptor.new(interceptors) end |
Instance Attribute Details
#topic ⇒ Object (readonly)
Returns the value of attribute topic.
15 16 17 |
# File 'lib/gcpc/publisher/engine.rb', line 15 def topic @topic end |
Instance Method Details
#publish(data, attributes = {}) ⇒ Object
19 20 21 22 23 24 25 26 |
# File 'lib/gcpc/publisher/engine.rb', line 19 def publish(data, attributes = {}) d = data.dup a = attributes.dup @interceptor.intercept!(d, a) do |dd, aa| do_publish(dd, aa) end end |
#publish_async(data, attributes = {}, &block) ⇒ Object
37 38 39 40 41 42 43 44 |
# File 'lib/gcpc/publisher/engine.rb', line 37 def publish_async(data, attributes = {}, &block) d = data.dup a = attributes.dup @interceptor.intercept!(d, a) do |dd, aa| do_publish_async(dd, aa, &block) end end |
#publish_batch(&block) {|batch_engine| ... } ⇒ Object
29 30 31 32 33 |
# File 'lib/gcpc/publisher/engine.rb', line 29 def publish_batch(&block) batch_engine = BatchEngine.new(topic: @topic, interceptor: @interceptor) yield batch_engine batch_engine.flush end |