File: listener.rb

package info (click to toggle)
ruby-pluggaloid 1.7.0-4
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 264 kB
  • sloc: ruby: 1,752; sh: 2; makefile: 2
file content (33 lines) | stat: -rw-r--r-- 885 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# -*- coding: utf-8 -*-
require 'securerandom'
require 'set'

class Pluggaloid::Listener < Pluggaloid::Handler
  # プラグインコールバックをこれ以上実行しない。
  def self.cancel!
    throw :plugin_exit, false end

  # ==== Args
  # [event] 監視するEventのインスタンス
  # [name:] 名前(String | nil)
  # [slug:] イベントリスナスラッグ(Symbol | nil)
  # [tags:] Pluggaloid::HandlerTag|Array リスナのタグ
  # [&callback] コールバック
  def initialize(event, **kwrest, &callback)
    super
    @callback = callback
    event.add_listener(self) end

  # イベントを実行する
  # ==== Args
  # [*args] イベントの引数
  def call(*args)
    @callback.call(*args, &self.class.method(:cancel!)) end

  # このリスナを削除する
  # ==== Return
  # self
  def detach
    @event.delete_listener(self)
    self end
end