Class: OmniEvent::Generators::InstallGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Includes:
Rails::Generators::Migration
Defined in:
lib/generators/omni_event/install_generator.rb

Instance Method Summary collapse

Instance Method Details

#copy_migrationsObject



12
13
14
# File 'lib/generators/omni_event/install_generator.rb', line 12

def copy_migrations
  rake "omni_event:install:migrations"
end

#create_initializerObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/generators/omni_event/install_generator.rb', line 16

def create_initializer
  create_file "config/initializers/omni_event.rb", <<~RUBY
    OmniEvent.configure do |config|
      # ── Monitoring ────────────────────────────────────────────────────────────
      config.new_relic_enabled    = false
      config.new_relic_api_key    = ENV['NEW_RELIC_KEY']
      config.new_relic_account_id = ENV['NEW_RELIC_ACCOUNT_ID']

      # ── Processing ────────────────────────────────────────────────────────────
      config.process_async  = true   # set false to process synchronously
      config.retention_days = 30

      # ── Custom log types ──────────────────────────────────────────────────────
      # Define your domain-specific action types here.
      config.custom_log_types = {
        system_info:  0,
        system_error: 1
      }

      # ── Processor registry ────────────────────────────────────────────────────
      # Map each OmniEvent::Notifier name to its processor class.
      #
      #   config.processors = {
      #     "Siscomex" => SiscomexProcessor,
      #     "DHL"      => DHLWebhookProcessor
      #   }
      config.processors = {}
    end
  RUBY
end

#create_local_modelsObject



47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/generators/omni_event/install_generator.rb', line 47

def create_local_models
  create_file "app/models/log.rb", <<~RUBY
    class Log < OmniEvent::Log
      # Add custom scopes, validations or methods here.
    end
  RUBY

  create_file "app/models/webhook_event.rb", <<~RUBY
    class WebhookEvent < OmniEvent::WebhookEvent
    end
  RUBY
end

#display_post_install_messageObject



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/generators/omni_event/install_generator.rb', line 60

def display_post_install_message
  puts ""
  puts "=" * 64
  puts " OmniEvent #{OmniEvent::VERSION} installed successfully!"
  puts ""
  puts " Next steps:"
  puts " 1. rails db:migrate"
  puts " 2. Configure config/initializers/omni_event.rb"
  puts " 3. Mount the engine in config/routes.rb:"
  puts "      mount OmniEvent::Engine => '/omni_events'"
  puts " 4. Create a Notifier:"
  puts "      OmniEvent::Notifier.create!(name: 'My Partner')"
  puts " 5. Register a processor in the initializer:"
  puts "      config.processors = { 'My Partner' => MyProcessor }"
  puts "=" * 64
end