roda 3.95.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
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
|
@@ -0,0 +1,59 @@
|
|
1
|
+
# frozen-string-literal: true
|
2
|
+
|
3
|
+
#
|
4
|
+
class Roda
|
5
|
+
module RodaPlugins
|
6
|
+
# The redirect_path plugin builds on top of the path plugin,
|
7
|
+
# and allows the +r.redirect+ method to be passed a non-string
|
8
|
+
# object that will be passed to +path+, and redirect to the
|
9
|
+
# result of +path+.
|
10
|
+
#
|
11
|
+
# In the second argument, you can provide a suffix to the
|
12
|
+
# generated path. However, in this case you cannot provide a
|
13
|
+
# non-default redirect status in the same call).
|
14
|
+
#
|
15
|
+
# Example:
|
16
|
+
#
|
17
|
+
# Foo = Struct.new(:id)
|
18
|
+
# foo = Foo.new(1)
|
19
|
+
#
|
20
|
+
# plugin :redirect_path
|
21
|
+
# path Foo do |foo|
|
22
|
+
# "/foo/#{foo.id}"
|
23
|
+
# end
|
24
|
+
#
|
25
|
+
# route do |r|
|
26
|
+
# r.get "example" do
|
27
|
+
# # redirects to /foo/1
|
28
|
+
# r.redirect(foo)
|
29
|
+
# end
|
30
|
+
#
|
31
|
+
# r.get "suffix-example" do
|
32
|
+
# # redirects to /foo/1/status
|
33
|
+
# r.redirect(foo, "/status")
|
34
|
+
# end
|
35
|
+
# end
|
36
|
+
module RedirectPath
|
37
|
+
def self.load_dependencies(app)
|
38
|
+
app.plugin :path
|
39
|
+
end
|
40
|
+
|
41
|
+
module RequestMethods
|
42
|
+
def redirect(path=default_redirect_path, status=default_redirect_status)
|
43
|
+
if String === path
|
44
|
+
super
|
45
|
+
else
|
46
|
+
path = scope.path(path)
|
47
|
+
if status.is_a?(String)
|
48
|
+
super(path + status)
|
49
|
+
else
|
50
|
+
super
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
register_plugin(:redirect_path, RedirectPath)
|
58
|
+
end
|
59
|
+
end
|
@@ -7,8 +7,8 @@ class Roda
|
|
7
7
|
module RodaPlugins
|
8
8
|
# The typecast_params plugin allows for type conversion of submitted parameters.
|
9
9
|
# Submitted parameters should be considered untrusted input, and in standard use
|
10
|
-
# with browsers, parameters are
|
11
|
-
# strings). In most
|
10
|
+
# with browsers, parameters are submitted as strings (or a hash/array containing
|
11
|
+
# strings). In most cases it makes sense to explicitly convert the parameter to the
|
12
12
|
# desired type. While this can be done via manual conversion:
|
13
13
|
#
|
14
14
|
# val = request.params['key'].to_i
|
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
|
@@ -268,6 +269,7 @@ files:
|
|
268
269
|
- lib/roda/plugins/r.rb
|
269
270
|
- lib/roda/plugins/recheck_precompiled_assets.rb
|
270
271
|
- lib/roda/plugins/redirect_http_to_https.rb
|
272
|
+
- lib/roda/plugins/redirect_path.rb
|
271
273
|
- lib/roda/plugins/relative_path.rb
|
272
274
|
- lib/roda/plugins/render.rb
|
273
275
|
- lib/roda/plugins/render_coverage.rb
|