Class: Tasker::Events::Catalog

Inherits:
Object
  • Object
show all
Defined in:
lib/tasker/events/catalog.rb

Overview

Event Catalog provides discovery and documentation for all Tasker events

This class enables developers to explore and understand the event system with runtime introspection, payload schemas, and usage examples.

All metadata is now sourced from Constants::EventDefinitions to ensure a single source of truth between registration and documentation.

Usage: # Browse all available events Tasker::Events.catalog

# Get details about a specific event Tasker::Events.event_info('task.completed')

# List events by category Tasker::Events.task_events Tasker::Events.step_events

Defined Under Namespace

Classes: CatalogPrinter, CustomEventRegistrar, ExamplePayloadGenerator

Class Method Summary collapse

Class Method Details

.catalogHash

Get complete event catalog with descriptions and schemas Now reads directly from EventDefinitions for consistency

Returns:

  • (Hash)

    Complete event catalog



31
32
33
# File 'lib/tasker/events/catalog.rb', line 31

def catalog
  @catalog ||= build_catalog_from_definitions
end

.complete_catalogHash

Get complete catalog including custom events

Returns:

  • (Hash)

    All events (system + custom)



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/tasker/events/catalog.rb', line 77

def complete_catalog
  system_catalog = catalog
  custom_events_data = Tasker::Events::CustomRegistry.instance.custom_events

  # Format custom events to match system catalog structure
  formatted_custom = custom_events_data.transform_values do |event|
    {
      name: event[:name],
      category: event[:category],
      description: event[:description],
      fired_by: event[:fired_by],
      payload_schema: {}, # MVP: no schema validation yet
      example_payload: {} # MVP: no examples yet
    }
  end

  system_catalog.merge(formatted_custom)
end

.custom_eventsHash

Get only custom events

Returns:

  • (Hash)

    Custom events with metadata



99
100
101
# File 'lib/tasker/events/catalog.rb', line 99

def custom_events
  complete_catalog.select { |_, event| event[:category] == 'custom' }
end

.event_info(event_name) ⇒ Hash?

Get information about a specific event

Parameters:

  • event_name (String, Symbol)

    The event name

Returns:

  • (Hash, nil)

    Event information or nil if not found



39
40
41
42
43
44
# File 'lib/tasker/events/catalog.rb', line 39

def event_info(event_name)
  definition = Tasker::Constants::EventDefinitions.find_by(constant: event_name.to_s)
  return nil unless definition

  format_event_info(definition)
end

.events_by_namespace(namespace) ⇒ Hash

Get events by namespace (e.g., 'order', 'payment')

Parameters:

  • namespace (String)

    Event namespace

Returns:

  • (Hash)

    Events in namespace



118
119
120
# File 'lib/tasker/events/catalog.rb', line 118

def events_by_namespace(namespace)
  complete_catalog.select { |name, _| name.start_with?("#{namespace}.") }
end

.observability_eventsHash

Get all observability events

Returns:

  • (Hash)

    Observability events with documentation



70
71
72
# File 'lib/tasker/events/catalog.rb', line 70

def observability_events
  catalog.select { |_, event| event[:category] == 'observability' }
end

This method returns an undefined value.

Pretty print the catalog for console exploration

Parameters:

  • output (IO) (defaults to: nil)

    Output destination (defaults to $stdout in development/test, Rails.logger in production)



135
136
137
# File 'lib/tasker/events/catalog.rb', line 135

def print_catalog(output: nil)
  CatalogPrinter.print(complete_catalog, output)
end

.register_custom_event(event_name, metadata = {}) ⇒ void

This method returns an undefined value.

Register a custom event (called by BaseSubscriber)

Parameters:

  • event_name (String)

    The custom event name

  • metadata (Hash) (defaults to: {})

    Optional metadata about the event



127
128
129
# File 'lib/tasker/events/catalog.rb', line 127

def register_custom_event(event_name,  = {})
  CustomEventRegistrar.register(event_name, , self)
end

.search_events(query) ⇒ Hash

Search events by name or description

Parameters:

  • query (String)

    Search query

Returns:

  • (Hash)

    Matching events



107
108
109
110
111
112
# File 'lib/tasker/events/catalog.rb', line 107

def search_events(query)
  complete_catalog.select do |name, event|
    name.downcase.include?(query.downcase) ||
      event[:description].downcase.include?(query.downcase)
  end
end

.step_eventsHash

Get all step-related events

Returns:

  • (Hash)

    Step events with documentation



56
57
58
# File 'lib/tasker/events/catalog.rb', line 56

def step_events
  catalog.select { |_, event| event[:category] == 'step' }
end

.task_eventsHash

Get all task-related events

Returns:

  • (Hash)

    Task events with documentation



49
50
51
# File 'lib/tasker/events/catalog.rb', line 49

def task_events
  catalog.select { |_, event| event[:category] == 'task' }
end

.workflow_eventsHash

Get all workflow orchestration events

Returns:

  • (Hash)

    Workflow events with documentation



63
64
65
# File 'lib/tasker/events/catalog.rb', line 63

def workflow_events
  catalog.select { |_, event| event[:category] == 'workflow' }
end