Skip to content

Commit

Permalink
Deprecate rack_profiler:install in favour of rack_mini_profiler:insta…
Browse files Browse the repository at this point in the history
…ll (#550)

The gem's name and install generator should be the same.
  • Loading branch information
gmcgibbon committed Mar 28, 2023
1 parent edbcad3 commit 1d2f012
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -101,7 +101,7 @@ be loaded outright, and an attempt to re-initialize it manually will raise an ex
Then run the generator which will set up rack-mini-profiler in development:

```bash
bundle exec rails g rack_profiler:install
bundle exec rails g rack_mini_profiler:install
```

#### Rack Builder
Expand Down
9 changes: 9 additions & 0 deletions lib/generators/rack_mini_profiler/USAGE
@@ -0,0 +1,9 @@
Description:
Generates an initializer for rack-mini-profiler. Use an initializer when manually
requiring rack-mini-profiler in your application (using require: false in your Gemfile).

Example:
`bin/rails generate rack_mini_profiler:install`

This generates a an initializer that requires and initializes
rack-mini-profiler in development mode.
13 changes: 13 additions & 0 deletions lib/generators/rack_mini_profiler/install_generator.rb
@@ -0,0 +1,13 @@
# frozen_string_literal: true

module RackMiniProfiler
module Generators
class InstallGenerator < ::Rails::Generators::Base
source_root File.expand_path("templates", __dir__)

def create_initializer_file
copy_file "rack_mini_profiler.rb", "config/initializers/rack_mini_profiler.rb"
end
end
end
end
Expand Up @@ -3,6 +3,6 @@
if Rails.env.development?
require "rack-mini-profiler"

# initialization is skipped so trigger it
# The initializer was required late, so initialize it manually.
Rack::MiniProfilerRails.initialize!(Rails.application)
end
9 changes: 6 additions & 3 deletions lib/generators/rack_profiler/install_generator.rb
@@ -1,12 +1,15 @@
# frozen_string_literal: true

require "generators/rack_mini_profiler/install_generator"

module RackProfiler
module Generators
class InstallGenerator < ::Rails::Generators::Base
source_root File.expand_path("templates", __dir__)
class InstallGenerator < RackMiniProfiler::Generators::InstallGenerator
source_root File.expand_path("../rack_mini_profiler/templates", __dir__)

def create_initializer_file
copy_file "rack_profiler.rb", "config/initializers/rack_profiler.rb"
warn("bin/rails generate rack_profiler:install is deprecated. Please use rack_mini_profiler:install instead.")
super
end
end
end
Expand Down

0 comments on commit 1d2f012

Please sign in to comment.