Class: Tasker::Generators::SubscriberGenerator

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

Instance Method Summary collapse

Instance Method Details

#create_spec_fileObject



29
30
31
32
33
34
35
36
37
# File 'lib/generators/tasker/subscriber_generator.rb', line 29

def create_spec_file
  return unless defined?(RSpec)

  if options[:metrics]
    template 'metrics_subscriber_spec.rb.erb', File.join('spec', 'subscribers', "#{file_name}_subscriber_spec.rb")
  else
    template 'subscriber_spec.rb.erb', File.join('spec', 'subscribers', "#{file_name}_subscriber_spec.rb")
  end
end

#create_subscriber_fileObject



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

def create_subscriber_file
  if options[:metrics]
    template 'metrics_subscriber.rb.erb', File.join(options[:directory], "#{file_name}_subscriber.rb")
  else
    template 'subscriber.rb.erb', File.join(options[:directory], "#{file_name}_subscriber.rb")
  end
end

#show_usage_instructionsObject



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
# File 'lib/generators/tasker/subscriber_generator.rb', line 39

def show_usage_instructions
  say "\n#{set_color('Subscriber created successfully!', :green)}"

  if options[:metrics]
    say "\n#{set_color('Metrics subscriber features:', :cyan)}"
    say '  - Built-in helper methods for extracting timing, error, and performance metrics'
    say '  - Automatic tag generation for categorization'
    say '  - Examples for StatsD, DataDog, Prometheus, and other metrics systems'
    say '  - Safe numeric value extraction with defaults'
  end

  say "\nTo register your subscriber, add this to an initializer:"
  say set_color("  #{class_name}Subscriber.subscribe(Tasker::Events::Publisher.instance)", :cyan)

  if options[:events].any?
    say "\nYour subscriber will handle these events:"
    options[:events].each do |event|
      method_name = "handle_#{event.tr('.', '_')}"
      say set_color("  #{event} -> #{method_name}", :yellow)
    end
  end

  say "\nAvailable events can be viewed with:"
  say set_color('  Tasker::Events.catalog.keys', :cyan)

  return unless options[:metrics]

  say "\n#{set_color('Metrics collection examples:', :green)}"
  say '  - Task completion rates and durations'
  say '  - Error categorization and retry patterns'
  say '  - Performance monitoring and resource usage'
  say '  - Business metrics with proper tagging'
end