class Hooks::TaggedHook(T)
- Hooks::TaggedHook(T)
- Reference
- Object
Overview
A hook that filters events based on tag matching
# Create handlers with different tag filters
base = Hook(TaggedEvent).new
admin_hook = TaggedHook(TaggedEvent).new(base, ["admin"])
user_hook = TaggedHook(TaggedEvent).new(base, ["user"])
# Add handlers for different event types
admin_hook.add(Handler(TaggedEvent).new { |event| handle_admin_event(event) })
user_hook.add(Handler(TaggedEvent).new { |event| handle_user_event(event) })
# Events only trigger matching handlers
event = TaggedEvent.new(tags: ["admin"])
admin_hook.trigger(event) # Triggers admin handlers only
Defined in:
hooks/tagged.crConstructors
Instance Method Summary
-
#add(handler : Handler(T)) : String
Registers a new handler to the hook by appending it to the existing queue using a Proc.
-
#can_trigger_on?(event_tags : Array(String)) : Bool
Checks if the current TaggedHook can be triggered with the provided event data tags.
- #hook : Hook(T)
- #hook=(hook : Hook(T))
-
#pre_add(handler : Handler(T)) : String
Registers a new handler to the hook by prepending it to the existing queue using a Proc.
- #tags : Array(String)
- #tags=(tags : Array(String))
- #trigger(*args, **options)
- #trigger(*args, **options, &)
Constructor Detail
Instance Method Detail
Registers a new handler to the hook by appending it to the existing queue using a Proc.
def can_trigger_on?(event_tags : Array(String)) : Bool
#
Checks if the current TaggedHook can be triggered with the provided event data tags.
Registers a new handler to the hook by prepending it to the existing queue using a Proc.