routes_lazy_routes 0.3.1 → 0.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8b8020bcd3fda43867d90592b8b2a273b64e599e5f11952df0d3f475f047acfd
4
- data.tar.gz: c4ba0b1fec98f499e56f6a1894b6e20de026b6b1691d314f0e14729dcca48a85
3
+ metadata.gz: e85956f13f735f04905cdde0cb540b18d8f79064d8b5931e7cf73cf5f5c16158
4
+ data.tar.gz: cac1dea4e88483c46924cfc072e4feb0186f7a5acdcfceba34b7b8b642709172
5
5
  SHA512:
6
- metadata.gz: 1991e3087a36eb71fac2ebb19f2b5f5ef08b45897dcd817bd54a5aebca25268e0f36e14617e0416a8f2a647aaeacaeff52643c6153627ced198725e39ba8047d
7
- data.tar.gz: 60392a385fc22a5a0e6c6808e09c23a73c887ebbfb02e44d1680ee4f66f064ef011d9dee2174e6f39b88724491b2c0063b69d614484c9850b10c8159204deb40
6
+ metadata.gz: f6d029f33d69f554a9047d2d74bd97c74e23c42351cb66ee6072346b7c78648d36c5951c033666759736904e7e5dc75f7aa46b0f9df12f903c69a515486d6509
7
+ data.tar.gz: 6b51f22fc94b59e007d65c7809dc0648fd4e877e064cc433e310f1cb981c11e91db3453ab0dd8a99d5d9f6b4aab69f2489798eefcc5801fdae9b17df3555e11e
@@ -1,33 +1,35 @@
1
1
  name: Ruby
2
2
 
3
- on: [push,pull_request]
3
+ on: [push, pull_request]
4
4
 
5
5
  jobs:
6
6
  build:
7
7
  strategy:
8
8
  matrix:
9
- include:
10
- - ruby-version: 2.7.2
11
- rails-version: '~> 5.2.4'
12
- - ruby-version: 2.7.2
13
- rails-version: '~> 6.0.3'
14
- - ruby-version: 2.7.2
15
- rails-version: '~> 6.1.0'
16
- - ruby-version: 3.0.0
17
- rails-version: '~> 6.0.3'
18
- - ruby-version: 3.0.0
19
- rails-version: '~> 6.1.0'
9
+ ruby_version: [ruby-head, '3.0', '2.7', '2.6']
10
+ rails_version: ['edge', '6.1', '6.0', '5.2']
11
+
12
+ exclude:
13
+ - ruby_version: ruby-head
14
+ rails_version: '6.0'
15
+ - ruby_version: ruby-head
16
+ rails_version: '5.2'
17
+ - ruby_version: '3.0'
18
+ rails_version: '5.2'
19
+ - ruby_version: '2.6'
20
+ rails_version: 'edge'
21
+
20
22
  runs-on: ubuntu-latest
23
+
24
+ env:
25
+ RAILS_VERSION: ${{ matrix.rails_version }}
26
+
21
27
  steps:
22
28
  - uses: actions/checkout@v2
23
- - name: Set up Ruby
24
- uses: ruby/setup-ruby@v1
29
+
30
+ - uses: ruby/setup-ruby@v1
25
31
  with:
26
- ruby-version: ${{ matrix.ruby-version }}
27
- - name: Run the default task
28
- run: |
29
- gem install bundler -v 2.2.0.rc.2
30
- bundle install
31
- bundle exec rake
32
- env:
33
- RAILS_VERSION: ${{ matrix.rails-version }}
32
+ ruby-version: ${{ matrix.ruby_version }}
33
+ bundler-cache: true
34
+
35
+ - run: bundle exec rake
data/Gemfile CHANGED
@@ -5,7 +5,11 @@ 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"]
8
+ if ENV['RAILS_VERSION'] == 'edge'
9
+ gem 'rails', git: 'https://github.com/rails/rails.git'
10
+ elsif ENV['RAILS_VERSION']
11
+ gem 'rails', "~> #{ENV['RAILS_VERSION']}.0"
12
+ end
9
13
 
10
14
  gem "rake", "~> 13.0"
11
15
 
data/README.md CHANGED
@@ -44,6 +44,17 @@ If you're bundling this in the production server, it'd be a good idea to throw a
44
44
 
45
45
  - And, as already explained, sending a request to the Rails server automatically runs `RoutesLazyRoutes.eager_load!` on the server.
46
46
 
47
+ - On the other hand, you need manually calling `RoutesLazyRoutes.eager_load!` inside your worker process (e.g. Sidekiq) to resolve named routes like the following:
48
+ ``` ruby
49
+ # config/initializers/sidekiq.rb
50
+ Sidekiq.configure_server do |config|
51
+ if defined?(RoutesLazyRoutes)
52
+ Rails.application.config.after_initialize do
53
+ RoutesLazyRoutes.eager_load!
54
+ end
55
+ end
56
+ end
57
+ ```
47
58
 
48
59
  ## Contributing
49
60
 
@@ -12,7 +12,7 @@ module RoutesLazyRoutes
12
12
  end
13
13
 
14
14
  module TaskLoader
15
- # A monkey-patch that loads our Rake task for enhancing `rails routes` after Rails loads all other tasks.
15
+ # A monkey-patch that loads our Rake task for enhancing `rake routes` after Rails loads all other tasks.
16
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
17
  # so enhancing Rails' Rake task from a gem this way seems impossible.
18
18
  def load_tasks(*)
@@ -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,9 +4,14 @@ require_relative 'application'
4
4
 
5
5
  module RoutesLazyRoutes
6
6
  class Railtie < ::Rails::Railtie
7
- # Extending `load_tasks` has to be done very early, like before executing any initializer, so here it is
7
+ # Extending the following modules have to be done very early, like before executing any initializer, so here it is
8
8
  Rails::Application.prepend RoutesLazyRoutes::Application::TaskLoader
9
9
 
10
+ if defined? Rails::Command::RoutesCommand
11
+ require_relative 'command/routes_command'
12
+ Rails::Command::RoutesCommand.prepend RoutesLazyRoutes::Command::RoutesCommand
13
+ end
14
+
10
15
  initializer :routes_lazy_routes, before: :add_routing_paths do
11
16
  RoutesLazyRoutes.arise!
12
17
 
@@ -2,7 +2,13 @@
2
2
 
3
3
  module RoutesLazyRoutes
4
4
  class RoutesReloaderWrapper
5
- delegate :paths, :eager_load=, :updated?, :route_sets, :external_routes, to: :@original_routes_reloader
5
+ delegate :paths,
6
+ :eager_load=,
7
+ :run_after_load_paths=,
8
+ :updated?,
9
+ :route_sets,
10
+ :external_routes,
11
+ to: :@original_routes_reloader
6
12
 
7
13
  def initialize(original_routes_reloader)
8
14
  @original_routes_reloader = original_routes_reloader
@@ -1,9 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- namespace :routes_lazy_routes do
4
- task :eager_load do
5
- RoutesLazyRoutes.eager_load!
3
+ if Rake::Task.task_defined?('routes')
4
+ namespace :routes_lazy_routes do
5
+ task :eager_load do
6
+ RoutesLazyRoutes.eager_load!
7
+ end
6
8
  end
7
- end
8
9
 
9
- Rake::Task['routes'].enhance ['routes_lazy_routes:eager_load']
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.3.1'
4
+ VERSION = '0.4.2'
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.3.1
4
+ version: 0.4.2
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-21 00:00:00.000000000 Z
11
+ date: 2021-10-07 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,6 +70,7 @@ 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
@@ -83,7 +98,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
83
98
  - !ruby/object:Gem::Version
84
99
  version: '0'
85
100
  requirements: []
86
- rubygems_version: 3.2.0
101
+ rubygems_version: 3.3.0.dev
87
102
  signing_key:
88
103
  specification_version: 4
89
104
  summary: A Rails routes lazy loader