Class: Pluggaloid::StreamGenerator
- Defined in:
- lib/pluggaloid/stream_generator.rb
Defined Under Namespace
Classes: Yielder
Constant Summary
Constants inherited from Handler
Instance Attribute Summary collapse
-
#accepted_hash ⇒ Object
readonly
Returns the value of attribute accepted_hash.
Attributes inherited from Handler
Attributes inherited from Identity
Instance Method Summary collapse
-
#detach ⇒ Object
このリスナを削除する ==== Return self.
-
#initialize(event, *specs, plugin:, **kwrest, &callback) ⇒ StreamGenerator
constructor
A new instance of StreamGenerator.
- #on_subscribed ⇒ Object
- #on_unsubscribed ⇒ Object
Methods inherited from Handler
#add_tag, #inspect, #remove_tag
Methods inherited from Identity
Constructor Details
#initialize(event, *specs, plugin:, **kwrest, &callback) ⇒ StreamGenerator
Returns a new instance of StreamGenerator.
8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/pluggaloid/stream_generator.rb', line 8 def initialize(event, *specs, plugin:, **kwrest, &callback) raise Pluggaloid::UndefinedStreamIndexError, 'To call generate(%{event}), it must define prototype arguments include `Pluggaloid::STREAM\'.' % {event: event.name} unless event.stream_index super(event, **kwrest) @callback = callback @specs = specs.freeze @accepted_hash = @event.argument_hash(specs, nil) @last_subscribe_state = @event.subscribe?(*@specs) @plugin = plugin subscribe_start if @last_subscribe_state @event.register_stream_generator(self) end |
Instance Attribute Details
#accepted_hash ⇒ Object (readonly)
Returns the value of attribute accepted_hash.
6 7 8 |
# File 'lib/pluggaloid/stream_generator.rb', line 6 def accepted_hash @accepted_hash end |
Instance Method Details
#detach ⇒ Object
このリスナを削除する
Return
self
38 39 40 41 42 43 |
# File 'lib/pluggaloid/stream_generator.rb', line 38 def detach @event.delete_stream_generator(self) @yielder&.die @yielder = nil self end |
#on_subscribed ⇒ Object
20 21 22 23 24 25 |
# File 'lib/pluggaloid/stream_generator.rb', line 20 def on_subscribed if !@last_subscribe_state @last_subscribe_state = true subscribe_start end end |
#on_unsubscribed ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/pluggaloid/stream_generator.rb', line 27 def on_unsubscribed subscribe_state = @event.subscribe_hash?(@accepted_hash) if @last_subscribe_state && !subscribe_state @last_subscribe_state = false subscribe_stop end end |