Class: Pluggaloid::Subscriber
- Defined in:
- lib/pluggaloid/subscriber.rb
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
-
#call(*args) ⇒ Object
イベントを実行する ==== Args [stream] イベントの引数.
-
#detach ⇒ Object
このリスナを削除する ==== Return self.
-
#initialize(event, *specs, **kwrest, &callback) ⇒ Subscriber
constructor
Args [event] 監視するEventのインスタンス [name:] 名前(String | nil) [slug:] イベントリスナスラッグ(Symbol | nil) [tags:] Pluggaloid::HandlerTag|Array リスナのタグ [&callback] コールバック.
Methods inherited from Handler
#add_tag, #inspect, #remove_tag
Methods inherited from Identity
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_hash ⇒ Object (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 |
#detach ⇒ Object
このリスナを削除する
Return
self
32 33 34 35 |
# File 'lib/pluggaloid/subscriber.rb', line 32 def detach @event.delete_subscriber(self) self end |