Class: Pluggaloid::StreamGenerator

Inherits:
Handler show all
Defined in:
lib/pluggaloid/stream_generator.rb

Defined Under Namespace

Classes: Yielder

Constant Summary

Constants inherited from Handler

Handler::Lock

Instance Attribute Summary collapse

Attributes inherited from Handler

#tags

Attributes inherited from Identity

#name, #slug

Instance Method Summary collapse

Methods inherited from Handler

#add_tag, #inspect, #remove_tag

Methods inherited from Identity

#inspect

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_hashObject (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

#detachObject

このリスナを削除する

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_subscribedObject



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_unsubscribedObject



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