class Pluggaloid::StreamGenerator
Attributes
accepted_hash[R]
Public Class Methods
new(event, *specs, plugin:, **kwrest, &callback)
click to toggle source
Calls superclass method
Pluggaloid::Handler::new
# File lib/pluggaloid/stream_generator.rb, line 7 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
Public Instance Methods
detach()
click to toggle source
on_subscribed()
click to toggle source
# File lib/pluggaloid/stream_generator.rb, line 19 def on_subscribed if !@last_subscribe_state @last_subscribe_state = true subscribe_start end end
on_unsubscribed()
click to toggle source
# File lib/pluggaloid/stream_generator.rb, line 26 def on_unsubscribed subscribe_state = @event.subscribe_hash?(@accepted_hash) if @last_subscribe_state && !subscribe_state @last_subscribe_state = false subscribe_stop end end
Private Instance Methods
subscribe_start()
click to toggle source
# File lib/pluggaloid/stream_generator.rb, line 46 def subscribe_start @tag = @plugin.handler_tag do @yielder = Yielder.new(@event, args: @specs) @callback.call(@yielder) end end
subscribe_stop()
click to toggle source
# File lib/pluggaloid/stream_generator.rb, line 53 def subscribe_stop @plugin.detach(@tag) @yielder.die @yielder = nil end