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: f24c09b316cf269199b54b3de06e3d5f27529c46b8ab34f015a8bb1ce42799f0
4
- data.tar.gz: e59f9b4e7e880f6313c5af6f33c59d9b87cd2a2b37cb247ea551a1a3556acaad
3
+ metadata.gz: 5dfe0f7c2161415227cf683ae6c01eaec3b4c24356a0d30a432a22496de10419
4
+ data.tar.gz: dd942c7df38f70c0c92198382a96416e50b58bca364c40245cd0db9fc189b4ef
5
5
  SHA512:
6
- metadata.gz: 6a27c05cabeb588bbccd1e4d0341106575c1f702d970906ee800bc8747cbbad41d53d456cfe53c2725d86d9d6181c17cde734565a0a127bf71918c6a5b4d6e0b
7
- data.tar.gz: fede1fe07b011d998c2962bc77c5c27cd28b3235d144f440dfb518f8c00184138fe6fcf355160ae98eb79ddce81e29f72c900543d128cc85d13c7f394501cd82
6
+ metadata.gz: 9a2a87e92a736a141ce78251ffa90f1d00ede4630541aca87188a595913f4279083a61465c9a49489c0e3aab9e53981567ba32d3d5d645dfdd6a6d93bcc5df88
7
+ data.tar.gz: 0faa213105f681e07078b94e3472563b3718a144ac0ad7ba7c39673f3cca2815f9200ce13f27d87f469ab3c132eb09a025058cf589adc9d8fcad62eb943b0c3b
@@ -7,6 +7,8 @@ class Roda
7
7
  # allows for easily defining hash matchers:
8
8
  #
9
9
  # class App < Roda
10
+ # plugin :hash_matcher
11
+ #
10
12
  # hash_matcher(:foo) do |v|
11
13
  # params['foo'] == v
12
14
  # end
@@ -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
@@ -11,7 +11,7 @@ class Roda
11
11
  #
12
12
  # Example:
13
13
  #
14
- # plugin :multi_route
14
+ # plugin :named_routes
15
15
  #
16
16
  # route('foo') do |r|
17
17
  # r.is 'bar' do
@@ -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 # submitted as strings (or a hash/array containing
11
- # strings). In most # cases it makes sense to explicitly convert the parameter to the
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
@@ -4,7 +4,7 @@ class Roda
4
4
  RodaMajorVersion = 3
5
5
 
6
6
  # The minor version of Roda, updated for new feature releases of Roda.
7
- RodaMinorVersion = 95
7
+ RodaMinorVersion = 97
8
8
 
9
9
  # The patch version of Roda, updated only for bug fixes from the last
10
10
  # feature release.
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.95.0
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