Class: Tasker::Events::DefinitionLoader

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/tasker/events/definition_loader.rb

Overview

DefinitionLoader handles loading event metadata and state machine mappings from YAML files

This class provides a clean loader for event metadata (descriptions, schemas, etc.) and state machine transition mappings. The actual event constants are defined in constants.rb as the single source of truth.

Features:

  • Event metadata loading for runtime introspection

  • State machine transition mappings for declarative configuration

  • Support for custom application events and mappings

  • Hot reloading in development environments

Class Method Summary collapse

Class Method Details

.events_by_categoryHash

Get all events grouped by category for introspection

Returns:

  • (Hash)

    Events grouped by category (task, step, workflow, etc.)



71
72
73
74
75
76
77
78
79
80
81
# File 'lib/tasker/events/definition_loader.rb', line 71

def events_by_category
   = 
  grouped = Hash.new { |h, k| h[k] = {} }

  .each do |event_key, event_data|
    category = extract_category_from_key(event_key)
    grouped[category][event_key] = event_data
  end

  grouped
end

.find_event_metadata(constant_ref) ⇒ Hash?

Get event metadata for a specific constant

Parameters:

  • constant_ref (String)

    The constant reference or actual constant value

Returns:

  • (Hash, nil)

    Event metadata or nil if not found



58
59
60
61
62
63
64
65
66
# File 'lib/tasker/events/definition_loader.rb', line 58

def (constant_ref)
   = 

  # Try direct lookup first
  return [constant_ref] if [constant_ref]

  # Try reverse lookup by constant value
  .find { |_key, data| data['constant_ref'] == constant_ref }&.last
end

.load_event_metadataHash

Load all event metadata for introspection

Returns:

  • (Hash)

    Event metadata keyed by constant reference



25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/tasker/events/definition_loader.rb', line 25

def 
   = {}

  # Load system event metadata first
   = 
  .merge!()

  # Load custom event metadata from applications
   = 
  .merge!()

  
end

.load_state_machine_mappingsHash

Load state machine mappings from YAML

Returns:

  • (Hash)

    State machine mappings with task and step transitions



42
43
44
45
46
47
48
49
50
51
52
# File 'lib/tasker/events/definition_loader.rb', line 42

def load_state_machine_mappings
  yaml_file = File.join(tasker_config_path, 'system_events.yml')

  if File.exist?(yaml_file)
    yaml_data = YAML.load_file(yaml_file)
    yaml_data['state_machine_mappings'] || {}
  else
    Rails.logger.warn('Tasker: system_events.yml not found')
    {}
  end
end