class Pluggaloid::HandlerTag

リスナをまとめて管理するプラグイン

Pluggaloid::Listener や、 Pluggaloid::Filter をまとめて扱うための仕組み。 Pluggaloid::Plugin#add_event などの引数 tags: に、このインスタンスを設定する。

インスタンスの作成

Pluggaloid::Plugin#handler_tag を使って生成する。 Pluggaloid::HandlerTagplugin: 引数には、レシーバ(Pluggaloid::Plugin)が渡される。 Pluggaloid::HandlerTag は、このプラグインの中でだけ使える。複数のプラグインのリスナ をまとめて管理することはできない。

リスナにタグをつける

Pluggaloid::Plugin#add_event または Pluggaloid::Plugin#add_event_filtertags: 引数にこれのインスタンスを渡す。

このタグがついたListenerやFilterを取得する

Enumerable をincludeしていて、リスナやフィルタを取得することができる。 また、

を対象にした Enumerator を取得することができる

このタグがついたリスナを全てdetachする

Pluggaloid::Plugin#detach の第一引数に Pluggaloid::HandlerTag の インスタンスを渡すことで、そのHandlerTagがついたListener、Filterは全てデタッチ される

Public Class Methods

new(plugin:, **kwrest) click to toggle source

Args

name:

タグの名前(String | nil)

Calls superclass method Pluggaloid::Identity.new
# File lib/pluggaloid/handler_tag.rb, line 42
def initialize(plugin,, **kwrest)
  super(**kwrest)
  @plugin = plugin
end

Public Instance Methods

each() click to toggle source

このTagがついている Pluggaloid::ListenerPluggaloid::Filter を全て列挙する

Return

Enumerable

# File lib/pluggaloid/handler_tag.rb, line 50
def each
  if block_given?
    Enumerator.new do |y|
      listeners{|x| y << x }
      filters{|x| y << x }
    end.each(&Proc.new)
  else
    Enumerator.new do |y|
      listeners{|x| y << x }
      filters{|x| y << x }
    end
  end
end
filters() click to toggle source

このTagがついている Pluggaloid::Filter を全て列挙する

Return

Enumerable

# File lib/pluggaloid/handler_tag.rb, line 78
def filters
  if block_given?
    filters.each(&Proc.new)
  else
    @plugin.to_enum(:filters).lazy.select{|l| l.tags.include?(self) }
  end
end
listeners() click to toggle source

このTagがついている Pluggaloid::Listener を全て列挙する

Return

Enumerable

# File lib/pluggaloid/handler_tag.rb, line 67
def listeners
  if block_given?
    listeners.each(&Proc.new)
  else
    @plugin.to_enum(:listeners).lazy.select{|l| l.tags.include?(self) }
  end
end