Class: Pluggaloid::Listener

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

Constant Summary

Constants inherited from Handler

Handler::Lock

Instance Attribute Summary

Attributes inherited from Handler

#tags

Attributes inherited from Identity

#name, #slug

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Handler

#add_tag, #inspect, #remove_tag

Methods inherited from Identity

#inspect

Constructor Details

#initialize(event, **kwrest, &callback) ⇒ Listener

Args

event

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

name:

名前(String | nil)

slug:

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

tags:

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

&callback

コールバック



16
17
18
19
# File 'lib/pluggaloid/listener.rb', line 16

def initialize(event, **kwrest, &callback)
super
@callback = callback
event.add_listener(self) end

Class Method Details

.cancel!Object

プラグインコールバックをこれ以上実行しない。



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

def self.cancel!
throw :plugin_exit, false end

Instance Method Details

#call(*args) ⇒ Object

イベントを実行する

Args

*args

イベントの引数



24
25
# File 'lib/pluggaloid/listener.rb', line 24

def call(*args)
@callback.call(*args, &self.class.method(:cancel!)) end

#detachObject

このリスナを削除する

Return

self



30
31
32
# File 'lib/pluggaloid/listener.rb', line 30

def detach
@event.delete_listener(self)
self end