class Pluggaloid::Handler
イベントのListenerやFilterのスーパクラス。 イベントに関連付けたり、タグを付けたりできる
Constants
- Lock
Attributes
Public Class Methods
new(event, tags: [], **kwrest)
click to toggle source
Args¶ ↑
- event
-
監視するEventのインスタンス
- name:
-
名前(String | nil)
- slug:
-
ハンドラスラッグ(Symbol | nil)
- tags:
-
Pluggaloid::HandlerTag|Array リスナのタグ
- &callback
-
コールバック
Calls superclass method
Pluggaloid::Identity.new
# File lib/pluggaloid/handler.rb, line 16 def initialize(event, tags: [], **kwrest) raise Pluggaloid::TypeError, "Argument `event' must be instance of Pluggaloid::Event, but given #{event.class}." unless event.is_a? Pluggaloid::Event super(**kwrest) @event = event _tags = tags.is_a?(Pluggaloid::HandlerTag) ? [tags] : Array(tags) _tags.each{|t| raise "#{t} is not a Pluggaloid::HandlerTag" unless t.is_a?(Pluggaloid::HandlerTag) } @tags = Set.new(_tags).freeze end
Public Instance Methods
add_tag(tag)
click to toggle source
# File lib/pluggaloid/handler.rb, line 25 def add_tag(tag) raise Pluggaloid::TypeError, "Argument `tag' must be instance of Pluggaloid::HandlerTag, but given #{tag.class}." unless tag.is_a? Pluggaloid::HandlerTag Lock.synchronize do @tags = Set.new([tag, *@tags]).freeze end self end
inspect()
click to toggle source
# File lib/pluggaloid/handler.rb, line 41 def inspect "#<#{self.class} event: #{@event.name.inspect}, slug: #{slug.inspect}, name: #{name.inspect}>" end
remove_tag(tag)
click to toggle source
# File lib/pluggaloid/handler.rb, line 33 def remove_tag(tag) Lock.synchronize do @tags -= tag @tags.freeze end self end