roda 3.68.0 → 3.69.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: faad040bd1e251d705afbfe6ced40794aa2f135658168c85603a6c8a83a497be
4
- data.tar.gz: 6e1d78ffdf0442835a754e54fc6216d8f668f3d0cb8e9c5635c1a582b17d5746
3
+ metadata.gz: 2871ec8db3a18a77238fdae1aeb786c7a7eb93f14b0827428fab1b07f6e7bee8
4
+ data.tar.gz: 75db2ec79978055f407c2270cfd9119782322402c2c536a504fbfc08f4fedac7
5
5
  SHA512:
6
- metadata.gz: a663960b5f5c5391a44102b1b255fbb5546f241c2386b6fdbe8a5050f434407332f239eb0c862ab877de239ec1b4ea39c4f9202c488672a846c5f8eabaef6379
7
- data.tar.gz: 508fa08ad66e1b11b5abc552345067fc2517aeb10ea060c6298a337b44db453c5daf35a0bbafe399dd9167286fd9ea35c07d75c340f640a6198beb52367352d5
6
+ metadata.gz: 1ca4fdcac9bcba88309b8ccb4315ea2243530b08313135f97a643b81600b98821521fbbe08e9c7ab757732887326e8af492f0f3e883a3f54e7be73f0811d19e6
7
+ data.tar.gz: 6b313eecbd4f62d07bca53fa23db2325b4f53f3faf55344c86d8f543ff92c5dcba94235f963582ce227d3602e3ea8633e981393ef6aedcbe20fb8152e6409c08
data/CHANGELOG CHANGED
@@ -1,3 +1,7 @@
1
+ = 3.69.0 (2023-06-13)
2
+
3
+ * Allow symbol_matcher in symbol_matchers plugin to take a block to allow type conversion (jeremyevans)
4
+
1
5
  = 3.68.0 (2023-05-11)
2
6
 
3
7
  * Make Roda.run in multi_run plugin accept blocks to allow autoloading the apps to dispatch to (jeremyevans)
@@ -0,0 +1,33 @@
1
+ = New Feature
2
+
3
+ * The symbol_matcher method in the symbol_matchers plugin now
4
+ supports a block to allow for type conversion of matched
5
+ segments:
6
+
7
+ symbol_matcher(:date, /(\d\d\d\d)-(\d\d)-(\d\d)/) do |y, m, d|
8
+ [Date.new(y.to_i, m.to_i, d.to_i)]
9
+ end
10
+
11
+ route do |r|
12
+ r.on :date do |date|
13
+ # date is an instance of Date
14
+ end
15
+ end
16
+
17
+ As shown above, the block should return an array of objects to yield
18
+ to the match block.
19
+
20
+ If you have a segment match the passed regexp, but decide during block
21
+ processing that you do not want to treat it as a match, you can have the
22
+ block return nil or false. This is useful if you want to make sure you
23
+ are using valid data:
24
+
25
+ symbol_matcher(:date, /(\d\d\d\d)-(\d\d)-(\d\d)/) do |y, m, d|
26
+ y = y.to_i
27
+ m = m.to_i
28
+ d = d.to_i
29
+ [Date.new(y, m, d)] if Date.valid_date?(y, m, d)
30
+ end
31
+
32
+ When providing a block when using the symbol_matchers method, that
33
+ symbol may not work with the params_capturing plugin.
@@ -33,7 +33,7 @@ class Roda
33
33
  # block return nil or false. This is useful if you want to make sure you
34
34
  # are using valid data:
35
35
  #
36
- # class_matcher(Date, /(\dd\d)-(\d\d)-(\d\d)/) do |y, m, d|
36
+ # class_matcher(Date, /(\d\d\d\d)-(\d\d)-(\d\d)/) do |y, m, d|
37
37
  # y = y.to_i
38
38
  # m = m.to_i
39
39
  # d = d.to_i
@@ -37,6 +37,35 @@ class Roda
37
37
  #
38
38
  # If using this plugin with the params_capturing plugin, this plugin should
39
39
  # be loaded first.
40
+ #
41
+ # You can provide a block when calling +symbol_matcher+, and it will be called
42
+ # for all matches to allow for type conversion. The block must return an
43
+ # array:
44
+ #
45
+ # symbol_matcher(:date, /(\d\d\d\d)-(\d\d)-(\d\d)/) do |y, m, d|
46
+ # [Date.new(y.to_i, m.to_i, d.to_i)]
47
+ # end
48
+ #
49
+ # route do |r|
50
+ # r.on :date do |date|
51
+ # # date is an instance of Date
52
+ # end
53
+ # end
54
+ #
55
+ # If you have a segment match the passed regexp, but decide during block
56
+ # processing that you do not want to treat it as a match, you can have the
57
+ # block return nil or false. This is useful if you want to make sure you
58
+ # are using valid data:
59
+ #
60
+ # symbol_matcher(:date, /(\d\d\d\d)-(\d\d)-(\d\d)/) do |y, m, d|
61
+ # y = y.to_i
62
+ # m = m.to_i
63
+ # d = d.to_i
64
+ # [Date.new(y, m, d)] if Date.valid_date?(y, m, d)
65
+ # end
66
+ #
67
+ # However, if providing a block to the symbol_matchers plugin, the symbol may
68
+ # not work with the params_capturing plugin.
40
69
  module SymbolMatchers
41
70
  def self.load_dependencies(app)
42
71
  app.plugin :_symbol_regexp_matchers
@@ -50,9 +79,10 @@ class Roda
50
79
 
51
80
  module ClassMethods
52
81
  # Set the regexp to use for the given symbol, instead of the default.
53
- def symbol_matcher(s, re)
82
+ def symbol_matcher(s, re, &block)
54
83
  meth = :"match_symbol_#{s}"
55
- self::RodaRequest.send(:define_method, meth){re}
84
+ array = [re, block].freeze
85
+ self::RodaRequest.send(:define_method, meth){array}
56
86
  self::RodaRequest.send(:private, meth)
57
87
  end
58
88
  end
@@ -67,8 +97,8 @@ class Roda
67
97
  meth = :"match_symbol_#{s}"
68
98
  if respond_to?(meth, true)
69
99
  # Allow calling private match methods
70
- re = send(meth)
71
- consume(self.class.cached_matcher(re){re})
100
+ re, block = send(meth)
101
+ consume(self.class.cached_matcher(re){re}, &block)
72
102
  else
73
103
  super
74
104
  end
@@ -80,7 +110,8 @@ class Roda
80
110
  meth = :"match_symbol_#{s}"
81
111
  if respond_to?(meth, true)
82
112
  # Allow calling private match methods
83
- send(meth)
113
+ re, = send(meth)
114
+ re
84
115
  else
85
116
  super
86
117
  end
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 = 68
7
+ RodaMinorVersion = 69
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.68.0
4
+ version: 3.69.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-05-11 00:00:00.000000000 Z
11
+ date: 2023-06-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack
@@ -241,6 +241,7 @@ extra_rdoc_files:
241
241
  - doc/release_notes/3.66.0.txt
242
242
  - doc/release_notes/3.67.0.txt
243
243
  - doc/release_notes/3.68.0.txt
244
+ - doc/release_notes/3.69.0.txt
244
245
  - doc/release_notes/3.7.0.txt
245
246
  - doc/release_notes/3.8.0.txt
246
247
  - doc/release_notes/3.9.0.txt
@@ -316,6 +317,7 @@ files:
316
317
  - doc/release_notes/3.66.0.txt
317
318
  - doc/release_notes/3.67.0.txt
318
319
  - doc/release_notes/3.68.0.txt
320
+ - doc/release_notes/3.69.0.txt
319
321
  - doc/release_notes/3.7.0.txt
320
322
  - doc/release_notes/3.8.0.txt
321
323
  - doc/release_notes/3.9.0.txt