roda 3.95.0 → 3.96.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/redirect_path.rb +59 -0
- data/lib/roda/plugins/typecast_params.rb +2 -2
- 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: 5cd2f1819c84a5977f70830dd6188e00a2e93ba0002a7ab13108a3ac70b8fad4
|
4
|
+
data.tar.gz: 2c9ee53f9fc84598e40b33f6381e14727d568baf7f3bfb07b371565a2e439a92
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 74520bc003b12e9098b05fdbe22aaa4945d0d9964827ea1e1ec26c669b9f58dff3374cad123cde2bd16de87148f4d11754ed980f79ba40d12ba413ecf83a801c
|
7
|
+
data.tar.gz: 0a57700f09fb3a61b091dd9c6c4150637ac5f0f6c86d888c4426ab6e4f4f70dc809aa134368d943f41d47421d4b441048c5ef35ac33ccb47fe90095d6fa640bb
|
@@ -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 :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.96.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeremy Evans
|
@@ -268,6 +268,7 @@ files:
|
|
268
268
|
- lib/roda/plugins/r.rb
|
269
269
|
- lib/roda/plugins/recheck_precompiled_assets.rb
|
270
270
|
- lib/roda/plugins/redirect_http_to_https.rb
|
271
|
+
- lib/roda/plugins/redirect_path.rb
|
271
272
|
- lib/roda/plugins/relative_path.rb
|
272
273
|
- lib/roda/plugins/render.rb
|
273
274
|
- lib/roda/plugins/render_coverage.rb
|