File tree Expand file tree Collapse file tree 3 files changed +43
-2
lines changed
Expand file tree Collapse file tree 3 files changed +43
-2
lines changed Original file line number Diff line number Diff line change 1- === master
1+ === 3.97.0 (2025-10-13)
22
33* Add map_matcher plugin, for matching next segment in request path to a hash key, yielding hash value (jeremyevans)
44
Original file line number Diff line number Diff line change 1+ = New Features
2+
3+ * A map_matcher plugin has been added, for matching the next segment
4+ in the request path to a hash key, yielding the hash value. This
5+ allows for a better approach for metaprogramming routes.
6+
7+ When dealing with many similar routes, it is common to use a hash
8+ keyed by route segment, and then match against an array of the keys:
9+
10+ map = {
11+ 'album' => Album,
12+ 'artist' => Artist,
13+ # ...
14+ }.freeze
15+
16+ keys = map.keys.freeze
17+
18+ route do |r|
19+ r.on "type", keys do |key|
20+ value = map[key]
21+ # ...
22+ end
23+ end
24+
25+ For large maps, this approach is suboptimal, since the array matcher
26+ will iterate over each element in the array, checking whether it
27+ matches.
28+
29+ The map_matcher plugin allows for:
30+
31+ plugin :map_matcher
32+
33+ route do |r|
34+ r.on "type", map: map do |value|
35+ # ...
36+ end
37+ end
38+
39+ This gets the next route segment and checks whether it is a key in
40+ the map, instead of iterating over an array of hash keys, so it is
41+ more efficient for large maps. It also results in simpler code.
Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ class Roda
44 RodaMajorVersion = 3
55
66 # The minor version of Roda, updated for new feature releases of Roda.
7- RodaMinorVersion = 96
7+ RodaMinorVersion = 97
88
99 # The patch version of Roda, updated only for bug fixes from the last
1010 # feature release.
You can’t perform that action at this time.
0 commit comments