typelizer 0.13.0 → 0.13.1
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 +4 -4
- data/CHANGELOG.md +17 -1
- data/lib/typelizer/route_generator.rb +20 -26
- data/lib/typelizer/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 90a122983cb647f8c395b12c44b59217994cba0d61db2fb71b942d5bbeb21de7
|
|
4
|
+
data.tar.gz: 444b8aec0943fec8e53d041013ce5d1d5c0c51215184fe5a515a5cdd53de9714
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 1320f55fab8636e726a56494c4add8e746af0e06970a2e6ede1ae0b7e09daa3f7bb4a406533dd666d7bedbbe0aab90a2d70409b07af44e5260e10dc068217a05
|
|
7
|
+
data.tar.gz: 1db53aabce4064e857efb3385f370d07253617556c6859c12883354a1ff55066e2115edca9be535d3c8409e74a8e8ee16b6cd807f42f23bcc2eba6bfb2c75330
|
data/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,20 @@ and this project adheres to [Semantic Versioning].
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [0.13.1] - 2026-05-18
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- `routes.include` and `routes.exclude` now accept a `Proc` (or any callable responding to `#call`) in addition to `Regexp`. Predicates receive the route-info hash (`:path`, `:name`, `:controller`, `:action`, `:verb`, `:required_parts`, `:optional_parts`) and must return truthy to match. Heterogeneous arrays are supported. Useful when the URL path alone can't disambiguate routes — e.g. multiple feature areas mounted under different subdomain constraints that share paths, or filtering by HTTP verb / helper name. ([@pastpatryk])
|
|
15
|
+
|
|
16
|
+
```ruby
|
|
17
|
+
config.routes.include = ->(r) { r[:controller].to_s.start_with?("admin/") }
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
### Fixed
|
|
21
|
+
|
|
22
|
+
- Unnamed alias routes sharing `controller#action` with a named route (e.g. ActiveStorage representations) no longer inherit the named route's name. Name lookup now matches by `[controller, path]` instead of `[controller, action]`, so distinct paths produce distinct entries. ([@skryukov])
|
|
23
|
+
|
|
10
24
|
## [0.13.0] - 2026-05-01
|
|
11
25
|
|
|
12
26
|
### Added
|
|
@@ -495,6 +509,7 @@ and this project adheres to [Semantic Versioning].
|
|
|
495
509
|
[@nkriege]: https://github.com/nkriege
|
|
496
510
|
[@NOX73]: https://github.com/NOX73
|
|
497
511
|
[@okuramasafumi]: https://github.com/okuramasafumi
|
|
512
|
+
[@pastpatryk]: https://github.com/pastpatryk
|
|
498
513
|
[@patvice]: https://github.com/patvice
|
|
499
514
|
[@pgiblock]: https://github.com/pgiblock
|
|
500
515
|
[@PedroAugustoRamalhoDuarte]: https://github.com/PedroAugustoRamalhoDuarte
|
|
@@ -503,7 +518,8 @@ and this project adheres to [Semantic Versioning].
|
|
|
503
518
|
[@skryukov]: https://github.com/skryukov
|
|
504
519
|
[@ventsislaf]: https://github.com/ventsislaf
|
|
505
520
|
|
|
506
|
-
[Unreleased]: https://github.com/skryukov/typelizer/compare/v0.13.
|
|
521
|
+
[Unreleased]: https://github.com/skryukov/typelizer/compare/v0.13.1...HEAD
|
|
522
|
+
[0.13.1]: https://github.com/skryukov/typelizer/compare/v0.13.0...v0.13.1
|
|
507
523
|
[0.13.0]: https://github.com/skryukov/typelizer/compare/v0.12.0...v0.13.0
|
|
508
524
|
[0.12.0]: https://github.com/skryukov/typelizer/compare/v0.11.0...v0.12.0
|
|
509
525
|
[0.11.0]: https://github.com/skryukov/typelizer/compare/v0.10.0...v0.11.0
|
|
@@ -33,14 +33,14 @@ module Typelizer
|
|
|
33
33
|
Rails.application.reload_routes_unless_loaded
|
|
34
34
|
end
|
|
35
35
|
|
|
36
|
-
|
|
36
|
+
named_paths = build_named_paths(Rails.application.routes.named_routes)
|
|
37
37
|
|
|
38
38
|
routes = Rails.application.routes.routes.flat_map do |route|
|
|
39
39
|
app = route.app.app
|
|
40
40
|
if app.is_a?(Class) && app < Rails::Engine
|
|
41
41
|
collect_engine_routes(route, app) || []
|
|
42
42
|
else
|
|
43
|
-
build_route_info(route,
|
|
43
|
+
build_route_info(route, named_paths)
|
|
44
44
|
end
|
|
45
45
|
end.compact
|
|
46
46
|
|
|
@@ -51,50 +51,48 @@ module Typelizer
|
|
|
51
51
|
|
|
52
52
|
if config.include
|
|
53
53
|
patterns = Array(config.include)
|
|
54
|
-
routes = routes.select { |r| patterns.any? { |p|
|
|
54
|
+
routes = routes.select { |r| patterns.any? { |p| match_route?(r, p) } }
|
|
55
55
|
end
|
|
56
56
|
if config.exclude
|
|
57
57
|
patterns = Array(config.exclude)
|
|
58
|
-
routes = routes.reject { |r| patterns.any? { |p|
|
|
58
|
+
routes = routes.reject { |r| patterns.any? { |p| match_route?(r, p) } }
|
|
59
59
|
end
|
|
60
60
|
|
|
61
61
|
routes
|
|
62
62
|
end
|
|
63
63
|
|
|
64
|
-
def
|
|
65
|
-
|
|
66
|
-
|
|
64
|
+
def match_route?(route_info, pattern)
|
|
65
|
+
if pattern.respond_to?(:call)
|
|
66
|
+
pattern.call(route_info)
|
|
67
|
+
else
|
|
68
|
+
route_info[:path].match?(pattern)
|
|
69
|
+
end
|
|
70
|
+
end
|
|
67
71
|
|
|
68
|
-
|
|
72
|
+
def build_named_paths(named_routes, path_prefix: "")
|
|
73
|
+
named_routes.each_with_object(Set.new) do |(_name, route), paths|
|
|
69
74
|
controller = route.requirements[:controller]
|
|
70
75
|
action = route.requirements[:action]
|
|
71
76
|
next unless controller && action
|
|
72
77
|
|
|
73
|
-
|
|
74
|
-
prefixed_name = "#{name_prefix}#{name}"
|
|
75
|
-
name_by_action[[controller, action]] = prefixed_name
|
|
76
|
-
name_by_path[[controller, path]] = prefixed_name
|
|
78
|
+
paths << [controller, path_prefix + strip_format(route.path.spec.to_s)]
|
|
77
79
|
end
|
|
78
|
-
|
|
79
|
-
[name_by_action, name_by_path]
|
|
80
80
|
end
|
|
81
81
|
|
|
82
82
|
def strip_format(path)
|
|
83
83
|
path.sub(FORMAT_SUFFIX, "")
|
|
84
84
|
end
|
|
85
85
|
|
|
86
|
-
def build_route_info(route,
|
|
86
|
+
def build_route_info(route, named_paths)
|
|
87
87
|
controller = route.requirements[:controller]
|
|
88
88
|
action = route.requirements[:action]
|
|
89
89
|
|
|
90
90
|
path = strip_format(route.path.spec.to_s)
|
|
91
91
|
|
|
92
92
|
if controller.present? && action.present?
|
|
93
|
-
|
|
94
|
-
name = route.name ||
|
|
95
|
-
name ||= name_by_path[[controller, path]] ? action : nil
|
|
93
|
+
# Match by [controller, path] so unnamed aliases at distinct paths (e.g. ActiveStorage representations) don't inherit a sibling's name
|
|
94
|
+
name = route.name || (action if named_paths.include?([controller, path]))
|
|
96
95
|
elsif route.name.present?
|
|
97
|
-
has_own_name = true
|
|
98
96
|
name = route.name.to_s
|
|
99
97
|
controller = "_routes"
|
|
100
98
|
action = name
|
|
@@ -110,7 +108,7 @@ module Typelizer
|
|
|
110
108
|
|
|
111
109
|
{
|
|
112
110
|
name: name,
|
|
113
|
-
named:
|
|
111
|
+
named: !!route.name,
|
|
114
112
|
controller: controller,
|
|
115
113
|
action: action,
|
|
116
114
|
verb: verb,
|
|
@@ -125,14 +123,10 @@ module Typelizer
|
|
|
125
123
|
engine_name = mount_route.name
|
|
126
124
|
return unless engine_name
|
|
127
125
|
|
|
128
|
-
|
|
129
|
-
engine.routes.named_routes,
|
|
130
|
-
path_prefix: mount_prefix,
|
|
131
|
-
name_prefix: "#{engine_name}_"
|
|
132
|
-
)
|
|
126
|
+
named_paths = build_named_paths(engine.routes.named_routes, path_prefix: mount_prefix)
|
|
133
127
|
|
|
134
128
|
engine.routes.routes.filter_map do |engine_route|
|
|
135
|
-
info = build_route_info(engine_route,
|
|
129
|
+
info = build_route_info(engine_route, named_paths)
|
|
136
130
|
next unless info
|
|
137
131
|
info[:path] = mount_prefix + info[:path]
|
|
138
132
|
info
|
data/lib/typelizer/version.rb
CHANGED