Class: EzLogsAgent::Generators::InstallGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/ez_logs_agent/install/install_generator.rb

Instance Method Summary collapse

Instance Method Details

#create_initializer_fileObject



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/generators/ez_logs_agent/install/install_generator.rb', line 36

def create_initializer_file
  initializer_path = File.join(destination_root, "config/initializers/ez_logs_agent.rb")

  if File.exist?(initializer_path)
    say "⚠️  Initializer already exists at config/initializers/ez_logs_agent.rb", :yellow
    say "   Skipping creation to avoid overwriting your existing configuration.", :yellow
    say "\n"
    return
  end

  template "ez_logs_agent.rb.tt", "config/initializers/ez_logs_agent.rb"
  say "\n"
  say "✅ Created config/initializers/ez_logs_agent.rb", :green
  say "\n"
end

#detect_environmentObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/generators/ez_logs_agent/install/install_generator.rb', line 20

def detect_environment
  @sidekiq_detected = defined?(Sidekiq)
  @activejob_detected = defined?(ActiveJob)
  @activerecord_detected = defined?(ActiveRecord)
  @devise_detected = defined?(Devise)

  say "Detected Components:", :cyan
  rails_version = defined?(Rails::VERSION::STRING) ? Rails::VERSION::STRING : "unknown"
  say "  • Rails #{rails_version}"
  say "  • Sidekiq #{Sidekiq::VERSION}", :green if @sidekiq_detected
  say "  • ActiveJob", :green if @activejob_detected && !@sidekiq_detected
  say "  • ActiveRecord", :green if @activerecord_detected
  say "  • Devise", :green if @devise_detected
  say "\n"
end

#show_next_stepsObject



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
84
85
86
87
88
89
90
91
# File 'lib/generators/ez_logs_agent/install/install_generator.rb', line 52

def show_next_steps
  say "=" * 70, :cyan
  say "  Next Steps", :cyan
  say "=" * 70, :cyan
  say "\n"

  say "1. Get your API key from EzLogs:", :bold
  say "   → Log in to your EzLogs dashboard"
  say "   → Go to Settings → API Keys"
  say "   → Create a new API key for this application\n\n"

  say "2. Configure the agent:", :bold
  say "   → Open config/initializers/ez_logs_agent.rb"
  say "   → Set your server_url (e.g., https://app.ezlogs.io)"
  say "   → Set your project_token (the API key from step 1)\n\n"

  if @devise_detected
    say "3. Enable actor tracking (optional but recommended):", :bold
    say "   → Uncomment the actor_from_request block"
    say "   → The Devise example is already configured for you\n\n"
  else
    say "3. Enable actor tracking (optional):", :bold
    say "   → Uncomment the actor_from_request block in the initializer"
    say "   → Customize it for your authentication system\n\n"
  end

  say "4. Test the connection:", :bold
  say "   → Run: rails ez_logs_agent:test_connection"
  say "   → This verifies your configuration is correct\n\n"

  say "5. Restart your Rails server:", :bold
  say "   → The agent will start capturing events automatically"
  say "   → Check your EzLogs dashboard to see activity\n\n"

  say "=" * 70, :cyan
  say "\n"

  say "Need help? Check the README or visit https://docs.ezlogs.io", :cyan
  say "\n"
end

#show_welcome_messageObject



12
13
14
15
16
17
18
# File 'lib/generators/ez_logs_agent/install/install_generator.rb', line 12

def show_welcome_message
  say "\n"
  say "=" * 70, :green
  say "  EzLogs Agent Installation", :green
  say "=" * 70, :green
  say "\n"
end