hanami-router 2.1.0.rc3 → 2.2.0.beta1

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: e20f7326a54f71efcb3251ae1fd939bf9e7229d005e45a2ce65dc5d10551f7bd
4
- data.tar.gz: 1b3568b80c0742543a9706a86ae42600460b297887c9af9276949dbe1afd18c4
3
+ metadata.gz: 28c7b9e18ec6d45c9e7fd2d9cedbc4ca44eb2077829baedb18ed471d1147d162
4
+ data.tar.gz: c607b74ef445960c5619593616cbf937954cc8860f724a46e15e4759d0aa8c3d
5
5
  SHA512:
6
- metadata.gz: 155276f1b0f2b72d43ab2356e5c3896e78d5fe874e4bc38310fea442ab2987a388197ae2b564a9cf7bad911bb8ae1ceb1235dddf16f804385486eb962840d0f9
7
- data.tar.gz: c80a5864b520752a7cfc4c9f4ebebe18f5e865598a618b4f0ef1154642d18f49a711b4748e73a6a067521cc13d9af98e6d2cddc8ddc9f8a0d3871054e401fc65
6
+ metadata.gz: 50c7ba9aa1b9feb3320dfcfb85d5e9e8cc91820df0ec004f93919b5aa916f6fb6dfafb5fc7cb2261433eb7c41ffe7e4864938c8186d6451e737bcac434fd386d
7
+ data.tar.gz: e9151a70ca2545538ef23524a760355dd80fa0ca76b25cf1666504da3689475824c7289727d4f9c47aff2b5b3046821be18396d53929d493db69f382ab785886
data/CHANGELOG.md CHANGED
@@ -2,6 +2,23 @@
2
2
 
3
3
  Rack compatible HTTP router for Ruby
4
4
 
5
+ ## v2.2.0.beta1 - 2024-07-16
6
+
7
+ ### Changed
8
+
9
+ - Drop support for Ruby 3.0
10
+
11
+ ## v2.1.0 - 2024-02-27
12
+
13
+ ### Fixed
14
+
15
+ - [Pat Allan] Fix PATH_INFO and SCRIPT_NAME for Rack apps mounted at the root (keep the leading slash in PATH_INFO, and set SCRIPT_NAME to a blank string)
16
+ - [Pat Allan] Process glob routes and mounted apps together, so that the routes can be handled in the user-specified order (previously, a root-mounted app would handle routes even if matching globs were declared earlier)
17
+
18
+ ### Changed
19
+
20
+ - [Pat Allan] Pass keyword args through to middleware
21
+
5
22
  ## v2.1.0.rc3 - 2024-02-16
6
23
 
7
24
  ## v2.1.0.rc2 - 2023-11-08
data/README.md CHANGED
@@ -1,35 +1,27 @@
1
1
  # Hanami::Router
2
2
 
3
- Rack compatible, lightweight and fast HTTP Router for Ruby and [Hanami](http://hanamirb.org).
4
-
5
- ## Version
6
-
7
- **This branch contains the code for `hanami-router` 2.x.**
3
+ Rack compatible, lightweight, and fast HTTP Router for Ruby and [Hanami](http://hanamirb.org).
8
4
 
9
5
  ## Status
10
6
 
11
7
  [![Gem Version](https://badge.fury.io/rb/hanami-router.svg)](https://badge.fury.io/rb/hanami-router)
12
- [![CI](https://github.com/hanami/router/workflows/ci/badge.svg?branch=main)](https://github.com/hanami/router/actions?query=workflow%3Aci+branch%3Amain)
8
+ [![CI](https://github.com/hanami/router/actions/workflows/ci.yml/badge.svg)](https://github.com/hanami/router/actions?query=workflow%3Aci+branch%3Amain)
13
9
  [![Test Coverage](https://codecov.io/gh/hanami/router/branch/main/graph/badge.svg)](https://codecov.io/gh/hanami/router)
14
10
  [![Depfu](https://badges.depfu.com/badges/5f6b8e8fa3b0d082539f0b0f84d55960/overview.svg)](https://depfu.com/github/hanami/router?project=Bundler)
15
- [![Inline Docs](http://inch-ci.org/github/hanami/router.svg)](http://inch-ci.org/github/hanami/router)
16
11
 
17
12
  ## Contact
18
13
 
19
14
  * Home page: http://hanamirb.org
20
15
  * Mailing List: http://hanamirb.org/mailing-list
21
- * API Doc: http://rdoc.info/gems/hanami-router
16
+ * API Doc: http://rubydoc.info/gems/hanami-router
22
17
  * Bugs/Issues: https://github.com/hanami/router/issues
23
- * Support: http://stackoverflow.com/questions/tagged/hanami
24
18
  * Chat: http://chat.hanamirb.org
25
19
 
26
- ## Rubies
27
-
28
- __Hanami::Router__ supports Ruby (MRI) 3.0+
29
-
30
20
 
31
21
  ## Installation
32
22
 
23
+ __Hanami::Router__ supports Ruby (MRI) 3.1.+
24
+
33
25
  Add this line to your application's Gemfile:
34
26
 
35
27
  ```ruby
@@ -365,4 +357,4 @@ __Hanami::Router__ uses [Semantic Versioning 2.0.0](http://semver.org)
365
357
 
366
358
  ## Copyright
367
359
 
368
- Copyright © 2014 Hanami Team – Released under MIT License
360
+ Copyright © 2014–2024 Hanami Team – Released under MIT License
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
18
18
  spec.executables = []
19
19
  spec.require_paths = ["lib"]
20
20
  spec.metadata["rubygems_mfa_required"] = "true"
21
- spec.required_ruby_version = ">= 3.0"
21
+ spec.required_ruby_version = ">= 3.1"
22
22
 
23
23
  spec.add_dependency "rack", "~> 2.0"
24
24
  spec.add_dependency "mustermann", "~> 3.0"
@@ -21,8 +21,8 @@ module Hanami
21
21
  mapping.each do |path, stack|
22
22
  builder = Rack::Builder.new
23
23
 
24
- stack.each do |middleware, args, blk|
25
- builder.use(middleware, *args, &blk)
24
+ stack.each do |middleware, args, kwargs, blk|
25
+ builder.use(middleware, *args, **kwargs, &blk)
26
26
  end
27
27
 
28
28
  builder.run(router)
@@ -78,7 +78,7 @@ module Hanami
78
78
  # @since 0.5.0
79
79
  # @api private
80
80
  def initialize(env)
81
- super %(Cannot find routable endpoint for: #{env[::Rack::REQUEST_METHOD]} #{env[::Rack::PATH_INFO]})
81
+ super(%(Cannot find routable endpoint for: #{env[::Rack::REQUEST_METHOD]} #{env[::Rack::PATH_INFO]}))
82
82
  end
83
83
  end
84
84
  end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Hanami
4
+ class Router
5
+ class GlobbedPath
6
+ def initialize(http_method, path, to)
7
+ @http_method = http_method
8
+ @path = path
9
+ @to = to
10
+ end
11
+
12
+ def endpoint_and_params(env)
13
+ return [] unless @http_method == env[::Rack::REQUEST_METHOD]
14
+
15
+ if (match = @path.match(env[::Rack::PATH_INFO]))
16
+ [@to, match.named_captures]
17
+ else
18
+ []
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Hanami
4
+ class Router
5
+ class MountedPath
6
+ def initialize(prefix, app)
7
+ @prefix = prefix
8
+ @app = app
9
+ end
10
+
11
+ def endpoint_and_params(env)
12
+ return [] unless (match = @prefix.peek_match(env[::Rack::PATH_INFO]))
13
+
14
+ if @prefix.to_s == "/"
15
+ env[::Rack::SCRIPT_NAME] = EMPTY_STRING
16
+ else
17
+ env[::Rack::SCRIPT_NAME] = env[::Rack::SCRIPT_NAME].to_s + @prefix.to_s
18
+ env[::Rack::PATH_INFO] = env[::Rack::PATH_INFO].sub(@prefix.to_s, EMPTY_STRING)
19
+ env[::Rack::PATH_INFO] = DEFAULT_PREFIX if env[::Rack::PATH_INFO] == EMPTY_STRING
20
+ end
21
+
22
+ [@app, match.named_captures]
23
+ end
24
+ end
25
+ end
26
+ end
@@ -8,6 +8,6 @@ module Hanami
8
8
  #
9
9
  # @since 0.1.0
10
10
  # @api public
11
- VERSION = "2.1.0.rc3"
11
+ VERSION = "2.2.0.beta1"
12
12
  end
13
13
  end
data/lib/hanami/router.rb CHANGED
@@ -20,6 +20,8 @@ module Hanami
20
20
  require "hanami/router/block"
21
21
  require "hanami/router/route"
22
22
  require "hanami/router/url_helpers"
23
+ require "hanami/router/globbed_path"
24
+ require "hanami/router/mounted_path"
23
25
 
24
26
  # URL helpers for other Hanami integrations
25
27
  #
@@ -84,8 +86,7 @@ module Hanami
84
86
  @block_context = block_context
85
87
  @fixed = {}
86
88
  @variable = {}
87
- @globbed = {}
88
- @mounted = {}
89
+ @globs_and_mounts = []
89
90
  @blk = blk
90
91
  @inspector = inspector
91
92
  instance_eval(&blk) if blk
@@ -424,7 +425,7 @@ module Hanami
424
425
  path = prefixed_path(at)
425
426
  prefix = Segment.fabricate(path, **constraints)
426
427
 
427
- @mounted[prefix] = @resolver.call(path, app)
428
+ @globs_and_mounts << MountedPath.new(prefix, @resolver.call(path, app))
428
429
  if inspect?
429
430
  @inspector.add_route(Route.new(http_method: "*", path: at, to: app, constraints: constraints))
430
431
  end
@@ -619,31 +620,12 @@ module Hanami
619
620
  @variable[env[::Rack::REQUEST_METHOD]]&.find(env[::Rack::PATH_INFO])
620
621
  end
621
622
 
622
- # @since 2.0.0
623
- # @api private
624
- def globbed(env)
625
- @globbed[env[::Rack::REQUEST_METHOD]]&.each do |path, to|
626
- if (match = path.match(env[::Rack::PATH_INFO]))
627
- return [to, match.named_captures]
628
- end
629
- end
630
-
631
- nil
632
- end
633
-
634
- # @since 2.0.0
623
+ # @since 2.1.0
635
624
  # @api private
636
- def mounted(env)
637
- @mounted.each do |prefix, app|
638
- next unless (match = prefix.peek_match(env[::Rack::PATH_INFO]))
639
-
640
- # TODO: ensure compatibility with existing env[::Rack::SCRIPT_NAME]
641
- # TODO: cleanup this code
642
- env[::Rack::SCRIPT_NAME] = env[::Rack::SCRIPT_NAME].to_s + prefix.to_s
643
- env[::Rack::PATH_INFO] = env[::Rack::PATH_INFO].sub(prefix.to_s, EMPTY_STRING)
644
- env[::Rack::PATH_INFO] = DEFAULT_PREFIX if env[::Rack::PATH_INFO] == EMPTY_STRING
645
-
646
- return [app, match.named_captures]
625
+ def globbed_or_mounted(env)
626
+ @globs_and_mounts.each do |path|
627
+ result = path.endpoint_and_params(env)
628
+ return result unless result.empty?
647
629
  end
648
630
 
649
631
  nil
@@ -800,7 +782,7 @@ module Hanami
800
782
  endpoint = fixed(env)
801
783
  return [endpoint, {}] if endpoint
802
784
 
803
- variable(env) || mounted(env) || globbed(env)
785
+ variable(env) || globbed_or_mounted(env)
804
786
  end
805
787
 
806
788
  # @since 2.0.0
@@ -843,8 +825,7 @@ module Hanami
843
825
  # @since 2.0.0
844
826
  # @api private
845
827
  def add_globbed_route(http_method, path, to, constraints)
846
- @globbed[http_method] ||= []
847
- @globbed[http_method] << [Segment.fabricate(path, **constraints), to]
828
+ @globs_and_mounts << GlobbedPath.new(http_method, Segment.fabricate(path, **constraints), to)
848
829
  end
849
830
 
850
831
  # @since 2.0.0
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hanami-router
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0.rc3
4
+ version: 2.2.0.beta1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Luca Guidi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-02-16 00:00:00.000000000 Z
11
+ date: 2024-07-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack
@@ -169,7 +169,9 @@ files:
169
169
  - lib/hanami/router/errors.rb
170
170
  - lib/hanami/router/formatter/csv.rb
171
171
  - lib/hanami/router/formatter/human_friendly.rb
172
+ - lib/hanami/router/globbed_path.rb
172
173
  - lib/hanami/router/inspector.rb
174
+ - lib/hanami/router/mounted_path.rb
173
175
  - lib/hanami/router/node.rb
174
176
  - lib/hanami/router/params.rb
175
177
  - lib/hanami/router/prefix.rb
@@ -193,14 +195,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
193
195
  requirements:
194
196
  - - ">="
195
197
  - !ruby/object:Gem::Version
196
- version: '3.0'
198
+ version: '3.1'
197
199
  required_rubygems_version: !ruby/object:Gem::Requirement
198
200
  requirements:
199
201
  - - ">="
200
202
  - !ruby/object:Gem::Version
201
203
  version: '0'
202
204
  requirements: []
203
- rubygems_version: 3.5.6
205
+ rubygems_version: 3.5.9
204
206
  signing_key:
205
207
  specification_version: 4
206
208
  summary: Rack compatible HTTP router for Ruby and Hanami