Class: Tasker::EventsGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/tasker/events_generator.rb

Instance Method Summary collapse

Instance Method Details

#create_config_directoryObject



14
15
16
17
# File 'lib/generators/tasker/events_generator.rb', line 14

def create_config_directory
  empty_directory 'config/tasker'
  empty_directory 'config/tasker/events'
end

#create_events_configObject



19
20
21
22
23
24
25
26
27
# File 'lib/generators/tasker/events_generator.rb', line 19

def create_events_config
  if options[:create_example]
    template 'custom_events.yml.erb', 'config/tasker/events/examples.yml'
    say 'Created config/tasker/events/examples.yml with example custom events', :green
  else
    create_file 'config/tasker/events/.keep', ''
    say 'Created config/tasker/events/ directory (add your event YAML files here)', :green
  end
end

#create_example_subscriberObject



29
30
31
32
33
34
# File 'lib/generators/tasker/events_generator.rb', line 29

def create_example_subscriber
  return unless options[:create_example]

  template 'custom_subscriber.rb.erb', 'app/subscribers/custom_events_subscriber.rb'
  say 'Created app/subscribers/custom_events_subscriber.rb', :green
end

#display_setup_instructionsObject



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/generators/tasker/events_generator.rb', line 36

def display_setup_instructions
  say <<~INSTRUCTIONS, :blue

    🎉 Tasker Events Setup Complete!

    📂 Default Event Location:
    Your custom events are loaded from: config/tasker/events/*.yml

    Next steps:
    1. Add more event files to config/tasker/events/ as needed
    2. Create subscribers in app/subscribers/ to handle events
    3. Use EventPublisher concern to publish custom events

    💡 Simple Organization:
    config/
      tasker/
        events/
          orders.yml       # order.created, order.cancelled
          payments.yml     # payment.attempted, payment.completed
          notifications.yml # notification.sent, notification.failed

    🔧 Advanced Configuration (if needed):
    For complex organizational needs, configure additional directories:

      Tasker::Configuration.configuration do |config|
        config.add_custom_events_directories(
          'vendor/gems/my_gem/events',
          'app/modules/billing/events'
        )
      end

    Example subscriber:
      class OrderEventsSubscriber < Tasker::Events::Subscribers::BaseSubscriber
        subscribe_to 'order.processed'

        def handle_order_processed(event)
          # Handle the event
        end
      end

    Example publishing:
      include Tasker::Concerns::EventPublisher
      publish_event('order.processed', { order_id: '123' })

    For more information, see the Tasker documentation.

  INSTRUCTIONS
end