routes_lazy_routes 0.2.0 → 0.3.0

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: b6e8fe43c0d0952ee2879a571fd73f2e01438f31c9000433c97d9263319eeac0
4
+ data.tar.gz: b685cac81ed7be0dccf6fb58a1a6e023a103b21839fecc906ec1745ab6602ad4
5
5
  SHA512:
6
- metadata.gz: b8869ac12f5faa11b76cdb5301c56dd88a1ec0904eb2edab3888e9ac47724bbe72bf85667aba7665f5262b34fca13ef5c04350f0b5ecea4da8cb632618bf8150
7
- data.tar.gz: c81344fc4c6f912554d5ea2aa5210690ba31dbbac0070584e7a50fc343bb3df6455f8847449fcd381f68c6084fd7db2e1ada4c4eb325c2d63fe3c07246892005
6
+ metadata.gz: f212b71f9b10cc35910813744f2053ebfadf88e090e964ecc124af5a2704aa52006d7d69ddf538757710c95878fa1527ee8886d9af8a039560a070f9fa268a86
7
+ data.tar.gz: 75e828ca879d28ff83f4ef41f4742ff196fc7dc14bec0ab5e8618240bef74ebb0c801b27a154a9b4f73f30dd7a58da4ef50ace22f9498eb5fb4ae223a9d902c8
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 `rails 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
@@ -4,12 +4,15 @@ 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 `load_tasks` has to be done very early, like before executing any initializer, so here it is
8
+ Rails::Application.prepend RoutesLazyRoutes::Application::TaskLoader
9
+
10
+ initializer :routes_lazy_routes, before: :add_routing_paths do
8
11
  RoutesLazyRoutes.arise!
9
12
 
10
13
  Rails.application.config.middleware.use LazyRoutesMiddleware
11
14
 
12
- Rails.application.extend RoutesLazyRoutes::Application
15
+ Rails.application.extend RoutesLazyRoutes::Application::LoadRunner
13
16
 
14
17
  ActiveSupport.on_load :action_dispatch_integration_test, run_once: true do
15
18
  RoutesLazyRoutes.eager_load!
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ namespace :routes_lazy_routes do
4
+ task :eager_load do
5
+ RoutesLazyRoutes.eager_load!
6
+ end
7
+ end
8
+
9
+ Rake::Task['routes'].enhance ['routes_lazy_routes:eager_load']
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RoutesLazyRoutes
4
- VERSION = '0.2.0'
4
+ VERSION = '0.3.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
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.3.0
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: 2020-12-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -59,6 +59,7 @@ files:
59
59
  - lib/routes_lazy_routes/lazy_routes_middleware.rb
60
60
  - lib/routes_lazy_routes/railtie.rb
61
61
  - lib/routes_lazy_routes/routes_reloader_wrapper.rb
62
+ - lib/routes_lazy_routes/tasks/routes_lazy_routes.rake
62
63
  - lib/routes_lazy_routes/version.rb
63
64
  - routes_lazy_routes.gemspec
64
65
  homepage: https://github.com/amatsuda/routes_lazy_routes