routes_lazy_routes 0.2.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d328eaa59962f83c7d301afe8040f66b51b2c524fd59cde08ee68f49e5d2a478
4
- data.tar.gz: 16c074d69396f4205076238e56b4e7e1f6fedb38eff428d52454fe24173b2634
3
+ metadata.gz: b3a53d214d3a09b1d78449db704c5c01f161848c502e5db060d49445a27cbc44
4
+ data.tar.gz: 3a1f0142211703faa3e74d038500376f38886bc44c904e55796a456bbdcb5cbc
5
5
  SHA512:
6
- metadata.gz: b8869ac12f5faa11b76cdb5301c56dd88a1ec0904eb2edab3888e9ac47724bbe72bf85667aba7665f5262b34fca13ef5c04350f0b5ecea4da8cb632618bf8150
7
- data.tar.gz: c81344fc4c6f912554d5ea2aa5210690ba31dbbac0070584e7a50fc343bb3df6455f8847449fcd381f68c6084fd7db2e1ada4c4eb325c2d63fe3c07246892005
6
+ metadata.gz: 7d808c84a2d36a0ba6f0ae2bf292a157ae3912a052ccf4f8b6a557e7156591b58ddf1121dc73bcf9db32a8a363c69cf8d3ca71331acddbabc3b960785211db62
7
+ data.tar.gz: 2a9219db0ec56fa7a120d736824ddf63f53af888f1f0cbb959c80857d07f79a1d015dcef2de3f29fd9aedaaa42ce81662541f433acb7d4cf6869c514df421970
@@ -4,15 +4,30 @@ on: [push,pull_request]
4
4
 
5
5
  jobs:
6
6
  build:
7
+ strategy:
8
+ matrix:
9
+ include:
10
+ - ruby-version: 2.7.3
11
+ rails-version: '~> 5.2.4'
12
+ - ruby-version: 2.7.3
13
+ rails-version: '~> 6.0.3'
14
+ - ruby-version: 2.7.3
15
+ rails-version: '~> 6.1.0'
16
+ - ruby-version: 3.0.1
17
+ rails-version: '~> 6.0.3'
18
+ - ruby-version: 3.0.1
19
+ rails-version: '~> 6.1.0'
7
20
  runs-on: ubuntu-latest
8
21
  steps:
9
22
  - uses: actions/checkout@v2
10
23
  - name: Set up Ruby
11
24
  uses: ruby/setup-ruby@v1
12
25
  with:
13
- ruby-version: 3.0.0
26
+ ruby-version: ${{ matrix.ruby-version }}
14
27
  - name: Run the default task
15
28
  run: |
16
- gem install bundler -v 2.2.0.rc.2
29
+ gem install bundler
17
30
  bundle install
18
31
  bundle exec rake
32
+ env:
33
+ RAILS_VERSION: ${{ matrix.rails-version }}
data/Gemfile CHANGED
@@ -5,6 +5,8 @@ source "https://rubygems.org"
5
5
  # Specify your gem's dependencies in routes_lazy_routes.gemspec
6
6
  gemspec
7
7
 
8
+ gem "rails", ENV["RAILS_VERSION"] if ENV["RAILS_VERSION"]
9
+
8
10
  gem "rake", "~> 13.0"
9
11
 
10
12
  gem "minitest", "~> 5.0"
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  routes_lazy_routes is an evil Rails plugin that defers loading the whole bloody routes until the server gets the first request, so the app can spin up quickly. 🤘
4
4
 
5
- This voodoo gem is designed especially for you who are maintaining a Rails app that contains hundreds of routes that forces you to wait dozens of seconds per every `rails` command invocation.
5
+ This voodoo gem is designed especially for you who are maintaining a huge legacy Rails app that contains hundreds of routes that forces you to wait dozens of seconds per every `rails` command invocation.
6
6
 
7
7
 
8
8
  ## Installation
@@ -30,7 +30,7 @@ You have nothing to do with it. It should just work beneath the skin.
30
30
 
31
31
  ## Trade-off
32
32
 
33
- The first visitor of the server should sacrifice their time for the Rails process to load the routes.
33
+ The first visitor of the server should sacrifice their time for the Rails process to load the routes. First strike is deadly.
34
34
  If you're bundling this in the production server, it'd be a good idea to throw a jab to the server right after the deployment in order to warm up before accepting real client requests.
35
35
 
36
36
 
@@ -2,11 +2,24 @@
2
2
 
3
3
  module RoutesLazyRoutes
4
4
  module Application
5
- # We expect `Rails.application.eager_load!` to load all routes as well
6
- def eager_load!
7
- RoutesLazyRoutes.eager_load!
5
+ module LoadRunner
6
+ # We expect `Rails.application.eager_load!` to load all routes as well
7
+ def eager_load!
8
+ RoutesLazyRoutes.eager_load!
8
9
 
9
- super
10
+ super
11
+ end
12
+ end
13
+
14
+ module TaskLoader
15
+ # A monkey-patch that loads our Rake task for enhancing `rake routes` after Rails loads all other tasks.
16
+ # Just declaring our own `rake_tasks` in the railtie cannot achieve this, since calling each railtie's `rake_tasks` is done before requiring "rails/tasks",
17
+ # so enhancing Rails' Rake task from a gem this way seems impossible.
18
+ def load_tasks(*)
19
+ super
20
+
21
+ load "#{__dir__}/tasks/routes_lazy_routes.rake"
22
+ end
10
23
  end
11
24
  end
12
25
  end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RoutesLazyRoutes
4
+ module Command
5
+ module RoutesCommand
6
+ # A monkey-patch that eager_loads the routes right before running the `rails routes` command.
7
+ def require_environment!
8
+ super
9
+
10
+ RoutesLazyRoutes.eager_load!
11
+ end
12
+ end
13
+ end
14
+ end
@@ -4,12 +4,20 @@ require_relative 'application'
4
4
 
5
5
  module RoutesLazyRoutes
6
6
  class Railtie < ::Rails::Railtie
7
- initializer 'routes_lazy_routes', before: :add_routing_paths do
7
+ # Extending the following modules have to be done very early, like before executing any initializer, so here it is
8
+ Rails::Application.prepend RoutesLazyRoutes::Application::TaskLoader
9
+
10
+ if defined? Rails::Command::RoutesCommand
11
+ require_relative 'command/routes_command'
12
+ Rails::Command::RoutesCommand.prepend RoutesLazyRoutes::Command::RoutesCommand
13
+ end
14
+
15
+ initializer :routes_lazy_routes, before: :add_routing_paths do
8
16
  RoutesLazyRoutes.arise!
9
17
 
10
18
  Rails.application.config.middleware.use LazyRoutesMiddleware
11
19
 
12
- Rails.application.extend RoutesLazyRoutes::Application
20
+ Rails.application.extend RoutesLazyRoutes::Application::LoadRunner
13
21
 
14
22
  ActiveSupport.on_load :action_dispatch_integration_test, run_once: true do
15
23
  RoutesLazyRoutes.eager_load!
@@ -2,7 +2,7 @@
2
2
 
3
3
  module RoutesLazyRoutes
4
4
  class RoutesReloaderWrapper
5
- delegate :paths, :eager_load=, :updated?, :route_sets, to: :@original_routes_reloader
5
+ delegate :paths, :eager_load=, :updated?, :route_sets, :external_routes, to: :@original_routes_reloader
6
6
 
7
7
  def initialize(original_routes_reloader)
8
8
  @original_routes_reloader = original_routes_reloader
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ if Rake::Task.task_defined?('routes')
4
+ namespace :routes_lazy_routes do
5
+ task :eager_load do
6
+ RoutesLazyRoutes.eager_load!
7
+ end
8
+ end
9
+
10
+ Rake::Task['routes'].enhance ['routes_lazy_routes:eager_load']
11
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RoutesLazyRoutes
4
- VERSION = '0.2.0'
4
+ VERSION = '0.4.1'
5
5
  end
@@ -25,6 +25,7 @@ Gem::Specification.new do |spec|
25
25
  end
26
26
  spec.require_paths = ["lib"]
27
27
 
28
- spec.add_dependency 'rails'
28
+ spec.add_dependency 'railties'
29
+ spec.add_dependency 'actionpack'
29
30
  spec.add_development_dependency 'byebug'
30
31
  end
metadata CHANGED
@@ -1,17 +1,31 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: routes_lazy_routes
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Akira Matsuda
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-12-07 00:00:00.000000000 Z
11
+ date: 2021-04-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: rails
14
+ name: railties
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: actionpack
15
29
  requirement: !ruby/object:Gem::Requirement
16
30
  requirements:
17
31
  - - ">="
@@ -56,9 +70,11 @@ files:
56
70
  - bin/setup
57
71
  - lib/routes_lazy_routes.rb
58
72
  - lib/routes_lazy_routes/application.rb
73
+ - lib/routes_lazy_routes/command/routes_command.rb
59
74
  - lib/routes_lazy_routes/lazy_routes_middleware.rb
60
75
  - lib/routes_lazy_routes/railtie.rb
61
76
  - lib/routes_lazy_routes/routes_reloader_wrapper.rb
77
+ - lib/routes_lazy_routes/tasks/routes_lazy_routes.rake
62
78
  - lib/routes_lazy_routes/version.rb
63
79
  - routes_lazy_routes.gemspec
64
80
  homepage: https://github.com/amatsuda/routes_lazy_routes
@@ -82,7 +98,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
82
98
  - !ruby/object:Gem::Version
83
99
  version: '0'
84
100
  requirements: []
85
- rubygems_version: 3.2.0.rc.2
101
+ rubygems_version: 3.3.0.dev
86
102
  signing_key:
87
103
  specification_version: 4
88
104
  summary: A Rails routes lazy loader