Class: Solidstats::Generators::InstallGenerator

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

Overview

This generator installs Solidstats routes in the host application

This will:

  1. Add the Solidstats routes to the host application’s config/routes.rb

  2. Show a helpful README with next steps

Examples:

$ rails generate solidstats:install

Instance Method Summary collapse

Instance Method Details

#add_routesObject



17
18
19
20
21
22
23
24
25
# File 'lib/generators/solidstats/install/install_generator.rb', line 17

def add_routes
  route_code = "  # Solidstats Routes (development only)\n  mount Solidstats::Engine => \"/solidstats\" if Rails.env.development?\n  RUBY\n\n  route route_code\n  say_status :routes, \"Mounting Solidstats engine at /solidstats (development environment only)\", :green\nend\n"

#check_dependenciesObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/generators/solidstats/install_generator.rb', line 31

def check_dependencies
  say "🔍 Checking dependencies...", :green

  # Check Rails version
  rails_version = Rails::VERSION::STRING
  if Gem::Version.new(rails_version) < Gem::Version.new("6.1.0")
    say "❌ Rails #{rails_version} is not supported. Minimum version: 6.1.0", :red
    exit 1
  end
  say "✅ Rails #{rails_version} supported", :green

  # Check ViewComponent
  begin
    require "view_component"
    say "✅ ViewComponent #{ViewComponent::VERSION} detected", :green
  rescue LoadError
    say "❌ ViewComponent not found. Please add it to your Gemfile:", :red
    say "gem 'view_component'", :yellow
    exit 1
  end
end

#check_environmentObject



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/generators/solidstats/install_generator.rb', line 19

def check_environment
  unless Rails.env.development?
    say "⚠️  Warning: Solidstats is designed for development environments only.", :yellow
    say "Current environment: #{Rails.env}", :yellow

    unless yes? "Continue installation anyway? (y/n)"
      say "Installation cancelled.", :red
      exit 1
    end
  end
end

#configure_assetsObject



68
69
70
71
72
73
74
75
# File 'lib/generators/solidstats/install_generator.rb', line 68

def configure_assets
  say "📦 Configuring assets...", :green

  say "  ✅ Using inline asset delivery (no configuration needed)", :blue
  say "  📝 Assets are automatically included via helper methods", :blue

  say "✅ Asset configuration complete", :green
end

#create_initializerObject



77
78
79
80
81
82
# File 'lib/generators/solidstats/install_generator.rb', line 77

def create_initializer
  say "⚙️  Creating initializer...", :green

  template "initializer.rb", "config/initializers/solidstats.rb"
  say "✅ Created config/initializers/solidstats.rb", :green
end

#mount_engineObject



53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/generators/solidstats/install_generator.rb', line 53

def mount_engine
  return if options[:skip_routes]

  say "🛤️  Mounting Solidstats engine...", :green

  route_content = "  mount Solidstats::Engine => '/solidstats' if Rails.env.development?"

  if File.read("config/routes.rb").include?("Solidstats::Engine")
    say "⚠️  Solidstats engine already mounted in routes.rb", :yellow
  else
    route route_content
    say "✅ Engine mounted at /solidstats (development only)", :green
  end
end

#show_installation_completeObject



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/generators/solidstats/install_generator.rb', line 84

def show_installation_complete
  say "\n🎉 Solidstats installation complete!", :green
  say "━" * 50, :green

  say "\n📍 Next steps:", :cyan
  say "1. Start your Rails server: rails server", :white
  say "2. Visit: http://localhost:3000/solidstats", :white
  say "3. Customize settings in config/initializers/solidstats.rb", :white

  say "\n💡 Asset Delivery:", :cyan
  say "  • CSS and JavaScript are automatically inlined", :white
  say "  • No asset pipeline configuration needed", :white
  say "  • Works with any Rails asset setup", :white

  say "\n📚 Documentation: https://github.com/your-org/solidstats", :cyan
  say "━" * 50, :green
end

#show_readmeObject



27
28
29
# File 'lib/generators/solidstats/install/install_generator.rb', line 27

def show_readme
  readme "README" if behavior == :invoke
end