Class: Pluggaloid::Subscriber

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

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, **kwrest, &callback) ⇒ Subscriber

Args

event

監視するEventのインスタンス

name:

名前(String | nil)

slug:

イベントリスナスラッグ(Symbol | nil)

tags:

Pluggaloid::HandlerTag|Array リスナのタグ

&callback

コールバック



14
15
16
17
18
19
20
# File 'lib/pluggaloid/subscriber.rb', line 14

def initialize(event, *specs, **kwrest, &callback)
  raise Pluggaloid::UndefinedStreamIndexError, 'To call subscribe(%{event}), it must define prototype arguments include `Pluggaloid::STREAM\'.' % {event: event.name} unless event.stream_index
  super(event, **kwrest)
  @callback = callback
  @accepted_hash = @event.argument_hash(specs, nil)
  event.add_listener(self)
end

Instance Attribute Details

#accepted_hashObject (readonly)

Returns the value of attribute accepted_hash.



6
7
8
# File 'lib/pluggaloid/subscriber.rb', line 6

def accepted_hash
  @accepted_hash
end

Instance Method Details

#call(*args) ⇒ Object

イベントを実行する

Args

stream

イベントの引数



25
26
27
# File 'lib/pluggaloid/subscriber.rb', line 25

def call(*args)
  @callback.call(args[@event.stream_index])
end

#detachObject

このリスナを削除する

Return

self



32
33
34
35
# File 'lib/pluggaloid/subscriber.rb', line 32

def detach
  @event.delete_subscriber(self)
  self
end