roda 3.70.0 → 3.71.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0d8ea04ca767f8be110f6ba14d1fd877a389a2e733e2925020f2ac589f6a9571
4
- data.tar.gz: c9a2d26f41724c05ea1de5e8fb0058093e5fad34fb0c6479dd74badcfea67016
3
+ metadata.gz: d5460d6cecb4f9b9acfedd05f5b14793bb9aefa2df2a8c29c559da319df87ee4
4
+ data.tar.gz: 75c3c8803abef4e27cac592a88597e8f9cd098be39bf1d0c1b1192175fd1f8e2
5
5
  SHA512:
6
- metadata.gz: 288a793976f389dfa2fe8fd55fb649590748cbe7ebb9da48f351117bb93da33ceee5848077f53c73430fd943b6be5b69a6d189e8b7424fe9ec60892dbaacff56
7
- data.tar.gz: 3cad6d6823a2fbcd5534521b6e5fbcc7b85c04d1a80e9ca758cac6ab9b4b967a5f019b653de7d4de3c1d32069832f362fd2564ec219252b0f2dd8ccf1c0785c1
6
+ metadata.gz: 6efc49bb205012a7ce50bc3c300d924a149de33416a35870f11efed492251c331804b970c967e47a481b0ddb0a83507c5926c1dc32069941b4edd2bd56df09e5
7
+ data.tar.gz: 698b7e7daae4cd0712a20a1e3e274f7ba3cdb9068eefdeb3bb5f043f2d437cdd5dda961ce91d88794e22a8ca3ef5825e3f8bd3f92ff933eab772c352dd17c2ee
data/CHANGELOG CHANGED
@@ -1,3 +1,7 @@
1
+ = 3.71.0 (2023-08-14)
2
+
3
+ * Add match_hook_args plugin, similar to match_hooks but support matchers and block args as hook arguments (jeremyevans)
4
+
1
5
  = 3.70.0 (2023-07-12)
2
6
 
3
7
  * Add plain_hash_response_headers plugin, using a plain hash for response headers on Rack 3 for much better performance (jeremyevans)
@@ -0,0 +1,33 @@
1
+ = New Feature
2
+
3
+ * A match_hook_args plugin has been added. This is similar to the
4
+ existing match_hook plugin, but passes through the matchers and
5
+ block arguments (values yielded to the match block). Example:
6
+
7
+ plugin :match_hook_args
8
+
9
+ add_match_hook do |matchers, block_args|
10
+ logger.debug("matchers: #{matchers.inspect}. #{block_args.inspect} yielded.")
11
+ end
12
+
13
+ # Term is an implicit matcher used for terminating matches, and
14
+ # will be included in the array of matchers yielded to the match hook
15
+ # if a terminating match is used.
16
+ term = self.class::RodaRequest::TERM
17
+
18
+ route do |r|
19
+ r.root do
20
+ # for a request for /
21
+ # matchers: nil, block_args: nil
22
+ end
23
+
24
+ r.on 'a', ['b', 'c'], Integer do |segment, id|
25
+ # for a request for /a/b/1
26
+ # matchers: ["a", ["b", "c"], Integer], block_args: ["b", 1]
27
+ end
28
+
29
+ r.get 'd' do
30
+ # for a request for /d
31
+ # matchers: ["d", term], block_args: []
32
+ end
33
+ end
@@ -52,6 +52,9 @@ class Roda
52
52
  # using the +:content_type+ option:
53
53
  #
54
54
  # plugin :json, content_type: 'application/xml'
55
+ #
56
+ # This plugin depends on the custom_block_results plugin, and therefore does
57
+ # not support treating String, FalseClass, or NilClass values as JSON.
55
58
  module Json
56
59
  # Set the classes to automatically convert to JSON, and the serializer to use.
57
60
  def self.configure(app, opts=OPTS)
@@ -379,7 +379,7 @@ class Roda
379
379
  end
380
380
 
381
381
  # Perform the processing of mail for this request, first considering
382
- # routes defined via the the class-level +rcpt+ method, and then the
382
+ # routes defined via the class-level +rcpt+ method, and then the
383
383
  # normal routing tree passed in as the block.
384
384
  def process_mail(&block)
385
385
  if string_routes = opts[:mail_processor_string_routes]
@@ -4,7 +4,9 @@
4
4
  class Roda
5
5
  module RodaPlugins
6
6
  # The match_hook plugin adds hooks that are called upon a successful match
7
- # by any of the matchers.
7
+ # by any of the matchers. The hooks do not take any arguments. If you would
8
+ # like hooks that pass the arguments/matchers and values yielded to the route block,
9
+ # use the match_hook_args plugin.
8
10
  #
9
11
  # plugin :match_hook
10
12
  #
@@ -0,0 +1,93 @@
1
+ # frozen-string-literal: true
2
+
3
+ #
4
+ class Roda
5
+ module RodaPlugins
6
+ # The match_hook_args plugin adds hooks that are called upon a successful match
7
+ # by any of the matchers. It is similar to the match_hook plugin, but it allows
8
+ # for passing the matchers and block arguments for each match method.
9
+ #
10
+ # plugin :match_hook_args
11
+ #
12
+ # add_match_hook do |matchers, block_args|
13
+ # logger.debug("matchers: #{matchers.inspect}. #{block_args.inspect} yielded.")
14
+ # end
15
+ #
16
+ # # Term is an implicit matcher used for terminating matches, and
17
+ # # will be included in the array of matchers yielded to the match hook
18
+ # # if a terminating match is used.
19
+ # term = self.class::RodaRequest::TERM
20
+ #
21
+ # route do |r|
22
+ # r.root do
23
+ # # for a request for /
24
+ # # matchers: nil, block_args: nil
25
+ # end
26
+ #
27
+ # r.on 'a', ['b', 'c'], Integer do |segment, id|
28
+ # # for a request for /a/b/1
29
+ # # matchers: ["a", ["b", "c"], Integer], block_args: ["b", 1]
30
+ # end
31
+ #
32
+ # r.get 'd' do
33
+ # # for a request for /d
34
+ # # matchers: ["d", term], block_args: []
35
+ # end
36
+ # end
37
+ module MatchHookArgs
38
+ def self.configure(app)
39
+ app.opts[:match_hook_args] ||= []
40
+ end
41
+
42
+ module ClassMethods
43
+ # Freeze the array of hook methods when freezing the app
44
+ def freeze
45
+ opts[:match_hook_args].freeze
46
+ super
47
+ end
48
+
49
+ # Add a match hook that will be called with matchers and block args.
50
+ def add_match_hook(&block)
51
+ opts[:match_hook_args] << define_roda_method("match_hook_args", :any, &block)
52
+
53
+ if opts[:match_hook_args].length == 1
54
+ class_eval("alias _match_hook_args #{opts[:match_hook_args].first}", __FILE__, __LINE__)
55
+ else
56
+ class_eval("def _match_hook_args(v, a); #{opts[:match_hook_args].map{|m| "#{m}(v, a)"}.join(';')} end", __FILE__, __LINE__)
57
+ end
58
+
59
+ public :_match_hook_args
60
+
61
+ nil
62
+ end
63
+ end
64
+
65
+ module InstanceMethods
66
+ # Default empty method if no match hooks are defined.
67
+ def _match_hook_args(matchers, block_args)
68
+ end
69
+ end
70
+
71
+ module RequestMethods
72
+ private
73
+
74
+ # Call the match hook with matchers and block args if yielding to the block before yielding to the block.
75
+ def if_match(v)
76
+ super do |*a|
77
+ scope._match_hook_args(v, a)
78
+ yield(*a)
79
+ end
80
+ end
81
+
82
+ # Call the match hook with nil matchers and blocks before yielding to the block
83
+ def always
84
+ scope._match_hook_args(nil, nil)
85
+ super
86
+ end
87
+ end
88
+ end
89
+
90
+ register_plugin :match_hook_args, MatchHookArgs
91
+ end
92
+ end
93
+
@@ -346,7 +346,7 @@ class Roda
346
346
  end
347
347
 
348
348
  # The reason behind this error. If this error was caused by a conversion method,
349
- # this will be the the conversion method symbol. If this error was caused
349
+ # this will be the conversion method symbol. If this error was caused
350
350
  # because a value was missing, then it will be +:missing+. If this error was
351
351
  # caused because a value was not the correct type, then it will be +:invalid_type+.
352
352
  attr_accessor :reason
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 = 70
7
+ RodaMinorVersion = 71
8
8
 
9
9
  # The patch version of Roda, updated only for bug fixes from the last
10
10
  # feature release.
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: roda
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.70.0
4
+ version: 3.71.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Evans
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-07-12 00:00:00.000000000 Z
11
+ date: 2023-08-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack
@@ -244,6 +244,7 @@ extra_rdoc_files:
244
244
  - doc/release_notes/3.69.0.txt
245
245
  - doc/release_notes/3.7.0.txt
246
246
  - doc/release_notes/3.70.0.txt
247
+ - doc/release_notes/3.71.0.txt
247
248
  - doc/release_notes/3.8.0.txt
248
249
  - doc/release_notes/3.9.0.txt
249
250
  files:
@@ -321,6 +322,7 @@ files:
321
322
  - doc/release_notes/3.69.0.txt
322
323
  - doc/release_notes/3.7.0.txt
323
324
  - doc/release_notes/3.70.0.txt
325
+ - doc/release_notes/3.71.0.txt
324
326
  - doc/release_notes/3.8.0.txt
325
327
  - doc/release_notes/3.9.0.txt
326
328
  - lib/roda.rb
@@ -391,6 +393,7 @@ files:
391
393
  - lib/roda/plugins/mailer.rb
392
394
  - lib/roda/plugins/match_affix.rb
393
395
  - lib/roda/plugins/match_hook.rb
396
+ - lib/roda/plugins/match_hook_args.rb
394
397
  - lib/roda/plugins/middleware.rb
395
398
  - lib/roda/plugins/middleware_stack.rb
396
399
  - lib/roda/plugins/module_include.rb