class Hooks::TaggedHook(T)

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.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new(hook : Hooks::Hook(T), tags : Array(String)) #

[View source]

Instance Method Detail

def add(handler : Handler(T)) : String #

Registers a new handler to the hook by appending it to the existing queue using a Proc.


[View source]
def can_trigger_on?(event_tags : Array(String)) : Bool #

Checks if the current TaggedHook can be triggered with the provided event data tags.


[View source]
def hook : Hook(T) #

[View source]
def hook=(hook : Hook(T)) #

[View source]
def pre_add(handler : Handler(T)) : String #

Registers a new handler to the hook by prepending it to the existing queue using a Proc.


[View source]
def tags : Array(String) #

[View source]
def tags=(tags : Array(String)) #

[View source]
def trigger(*args, **options) #

[View source]
def trigger(*args, **options, &) #

[View source]