roda 3.96.0 → 3.97.0
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/lib/roda/plugins/hash_matcher.rb +2 -0
- data/lib/roda/plugins/map_matcher.rb +48 -0
- data/lib/roda/plugins/named_routes.rb +1 -1
- data/lib/roda/plugins/redirect_path.rb +1 -1
- data/lib/roda/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5dfe0f7c2161415227cf683ae6c01eaec3b4c24356a0d30a432a22496de10419
|
4
|
+
data.tar.gz: dd942c7df38f70c0c92198382a96416e50b58bca364c40245cd0db9fc189b4ef
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9a2a87e92a736a141ce78251ffa90f1d00ede4630541aca87188a595913f4279083a61465c9a49489c0e3aab9e53981567ba32d3d5d645dfdd6a6d93bcc5df88
|
7
|
+
data.tar.gz: 0faa213105f681e07078b94e3472563b3718a144ac0ad7ba7c39673f3cca2815f9200ce13f27d87f469ab3c132eb09a025058cf589adc9d8fcad62eb943b0c3b
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# frozen-string-literal: true
|
2
|
+
|
3
|
+
#
|
4
|
+
class Roda
|
5
|
+
module RodaPlugins
|
6
|
+
# The map_matcher plugin allows you to provide a string-keyed
|
7
|
+
# hash during route matching, and match any of the keys in the hash
|
8
|
+
# as the next segment in the request path, yielding the corresponding
|
9
|
+
# value in the hash:
|
10
|
+
#
|
11
|
+
# class App < Roda
|
12
|
+
# plugin :map_matcher
|
13
|
+
#
|
14
|
+
# map = { "foo" => "bar", "baz" => "quux" }.freeze
|
15
|
+
#
|
16
|
+
# route do
|
17
|
+
# r.get map: map do |v|
|
18
|
+
# v
|
19
|
+
# # GET /foo => bar
|
20
|
+
# # GET /baz => quux
|
21
|
+
# end
|
22
|
+
# end
|
23
|
+
# end
|
24
|
+
module MapMatcher
|
25
|
+
module RequestMethods
|
26
|
+
private
|
27
|
+
|
28
|
+
# Match only if the next segment in the path is one of the keys
|
29
|
+
# in the hash, and yield the value of the hash.
|
30
|
+
def match_map(hash)
|
31
|
+
rp = @remaining_path
|
32
|
+
if key = _match_class_String
|
33
|
+
if value = hash[@captures[-1]]
|
34
|
+
@captures[-1] = value
|
35
|
+
true
|
36
|
+
else
|
37
|
+
@remaining_path = rp
|
38
|
+
@captures.pop
|
39
|
+
false
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
register_plugin(:map_matcher, MapMatcher)
|
47
|
+
end
|
48
|
+
end
|
data/lib/roda/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: roda
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.97.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeremy Evans
|
@@ -234,6 +234,7 @@ files:
|
|
234
234
|
- lib/roda/plugins/link_to.rb
|
235
235
|
- lib/roda/plugins/mail_processor.rb
|
236
236
|
- lib/roda/plugins/mailer.rb
|
237
|
+
- lib/roda/plugins/map_matcher.rb
|
237
238
|
- lib/roda/plugins/match_affix.rb
|
238
239
|
- lib/roda/plugins/match_hook.rb
|
239
240
|
- lib/roda/plugins/match_hook_args.rb
|