roda 3.48.0 → 3.49.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: 34691daba87a890b955df8a9c89ac11e3b5b2ce3ac4726b5d4dbd526aaa5c8ce
4
- data.tar.gz: e2d8399a4a17a432d39e531ef25db62028622bd258194e930ef3d2b55a722bb8
3
+ metadata.gz: 2d3b9688bae8b0013acedfc6a5bcb45c374e0a73fd30e56985f0ebeee942ef8c
4
+ data.tar.gz: acb8215250d1615f007a2ec01d2b6546376414d2fea23a4f2341af9efd951110
5
5
  SHA512:
6
- metadata.gz: 728e35715a74a04b373b3fa36fe8a7b81298de6d6c159de0ad95e654346e8c55d593d9ad4f067a0d8e1a569434085b333549efcc0467b28158332493b2ab8087
7
- data.tar.gz: ee4d3b86e0b15dae0126b6ad032cfbe3055e9a1010f3cd0cf2d847cfb12ca4910b61f0030baa3e94fac8ac52304ca60a2b7825f2080cf28d51579dfd3d8cefa6
6
+ metadata.gz: 3a5434bdcb6926d6c5e656c25b46e16b035ad54d74ed16bdc1cf46005b8ef605b3371a628cae52d65803064aa3d2eac8a56c2e8e1e55b6f3a82c04a74c636855
7
+ data.tar.gz: 9dc3773fae04325373adb8a7a57d52166bb65c238b959999adf6f6f17a3be29fcdedcea677eeeaaa84f6a01b5accb4aff2594817165b8a77a45106a3d4a9dea3
data/CHANGELOG CHANGED
@@ -1,3 +1,9 @@
1
+ = 3.49.0 (2021-10-13)
2
+
3
+ * Switch block_given? to defined?(yield) (jeremyevans)
4
+
5
+ * Automatically optimize remaining r.is/r.get/r.post calls with a single argument (jeremyevans)
6
+
1
7
  = 3.48.0 (2021-09-13)
2
8
 
3
9
  * Extract named_routes plugin from multi_route plugin (jeremyevans)
data/README.rdoc CHANGED
@@ -1109,7 +1109,8 @@ Roda's plugin system is based on the plugin system used by
1109
1109
  Roda fully supports the currently supported versions of Ruby (MRI) and JRuby. It may
1110
1110
  support unsupported versions of Ruby or JRuby, but such support may be dropped in any
1111
1111
  minor version if keeping it becomes a support issue. The minimum Ruby version
1112
- required to run the current version of Roda is 1.9.2.
1112
+ required to run the current version of Roda is 1.9.2, and the minimum JRuby version is
1113
+ 9.0.0.0.
1113
1114
 
1114
1115
  == License
1115
1116
 
@@ -0,0 +1,18 @@
1
+ = Improvements
2
+
3
+ * The r.is optimization added in 3.46.0 has been extended to optimize
4
+ all single argument calls. This results in the following speedups
5
+ based on argument type:
6
+
7
+ * Hash/Class matching: 20%
8
+ * Symbol matching: 25%
9
+ * Array matching: 35%
10
+ * Proc matching: 50%
11
+ * false/nil matching: 65%
12
+
13
+ * Roda now uses defined?(yield) instead of block_given? internally
14
+ for better performance on CRuby. defined?(yield) is faster as it is
15
+ built into the VM, while block_given? is a regular method and has
16
+ the overhead of calling a regular method. Note that defined?(yield)
17
+ is not implemented correctly on JRuby before 9.0.0.0, so this
18
+ release of Roda drops support for JRuby versions before 9.0.0.0.
@@ -156,7 +156,21 @@ class Roda
156
156
  always{yield(matchdata[1].to_i)}
157
157
  end
158
158
  else
159
- if_match(args << TERM, &block)
159
+ path = @remaining_path
160
+ captures = @captures.clear
161
+ meth = :"_match_class_#{matcher}"
162
+ if respond_to?(meth, true)
163
+ # Allow calling private methods, as match methods are generally private
164
+ if send(meth, &block) && @remaining_path.empty?
165
+ block_result(yield(*captures))
166
+ throw :halt, response.finish
167
+ else
168
+ @remaining_path = path
169
+ false
170
+ end
171
+ else
172
+ unsupported_matcher(matcher)
173
+ end
160
174
  end
161
175
  when Regexp
162
176
  if (matchdata = self.class.cached_matcher(matcher){matcher}.match(@remaining_path)) && matchdata.post_match.empty?
@@ -165,8 +179,32 @@ class Roda
165
179
  end
166
180
  when true
167
181
  always(&block) if @remaining_path.empty?
182
+ when false, nil
183
+ # nothing
168
184
  else
169
- if_match(args << TERM, &block)
185
+ path = @remaining_path
186
+ captures = @captures.clear
187
+
188
+ matched = case matcher
189
+ when Array
190
+ _match_array(matcher)
191
+ when Hash
192
+ _match_hash(matcher)
193
+ when Symbol
194
+ _match_symbol(matcher)
195
+ when Proc
196
+ matcher.call
197
+ else
198
+ unsupported_matcher(matcher)
199
+ end
200
+
201
+ if matched && @remaining_path.empty?
202
+ block_result(yield(*captures))
203
+ throw :halt, response.finish
204
+ else
205
+ @remaining_path = path
206
+ false
207
+ end
170
208
  end
171
209
  end
172
210
  end
@@ -75,8 +75,8 @@ class Roda
75
75
  def content_for(key, value=nil)
76
76
  append = opts[:append_content_for]
77
77
 
78
- if block_given? || value
79
- if block_given?
78
+ if defined?(yield) || value
79
+ if defined?(yield)
80
80
  outvar = render_opts[:template_opts][:outvar]
81
81
  buf_was = instance_variable_get(outvar)
82
82
 
@@ -278,7 +278,7 @@ class Roda
278
278
  Policy.new
279
279
  end
280
280
 
281
- yield policy if block_given?
281
+ yield policy if defined?(yield)
282
282
  policy.freeze
283
283
  end
284
284
 
@@ -287,7 +287,7 @@ class Roda
287
287
  # current content security policy.
288
288
  def content_security_policy
289
289
  policy = @_response.content_security_policy
290
- yield policy if block_given?
290
+ yield policy if defined?(yield)
291
291
  policy
292
292
  end
293
293
  end
@@ -72,7 +72,7 @@ class Roda
72
72
  end
73
73
 
74
74
  if mod
75
- raise RodaError, "can't provide both argument and block to response_module" if block_given?
75
+ raise RodaError, "can't provide both argument and block to response_module" if defined?(yield)
76
76
  klass.send(:include, mod)
77
77
  else
78
78
  if instance_variable_defined?(iv)
@@ -140,7 +140,7 @@ class Roda
140
140
  def multi_route(namespace=nil)
141
141
  on self.class.named_route_regexp(namespace) do |section|
142
142
  res = route(section, namespace)
143
- if block_given?
143
+ if defined?(yield)
144
144
  yield
145
145
  else
146
146
  res
@@ -91,7 +91,7 @@ class Roda
91
91
  # dispatch the request to the stored rack application.
92
92
  def multi_run
93
93
  on self.class.multi_run_regexp do |prefix|
94
- yield prefix if block_given?
94
+ yield prefix if defined?(yield)
95
95
  run scope.class.multi_run_apps[prefix]
96
96
  end
97
97
  end
@@ -34,7 +34,7 @@ class Roda
34
34
  # routing normally.
35
35
  def run(app, opts=OPTS)
36
36
  res = catch(:halt){super(app)}
37
- yield res if block_given?
37
+ yield res if defined?(yield)
38
38
  throw(:halt, res) unless opts[:not_found] == :pass && res[0] == 404
39
39
  end
40
40
  end
@@ -61,7 +61,7 @@ class Roda
61
61
  def shared(vars=nil)
62
62
  h = env['roda.shared'] ||= {}
63
63
 
64
- if block_given?
64
+ if defined?(yield)
65
65
  if vars
66
66
  begin
67
67
  env['roda.shared'] = h.merge(vars)
@@ -384,7 +384,7 @@ class Roda
384
384
 
385
385
  # Set or retrieve the response body. When a block is given,
386
386
  # evaluation is deferred until the body is needed.
387
- def body(value = (return @body unless block_given?; nil), &block)
387
+ def body(value = (return @body unless defined?(yield); nil), &block)
388
388
  if block
389
389
  @body = DelayedBody.new(&block)
390
390
  else
@@ -564,7 +564,7 @@ class Roda
564
564
  end
565
565
 
566
566
  v = @obj[key]
567
- v = yield if v.nil? && block_given?
567
+ v = yield if v.nil? && defined?(yield)
568
568
 
569
569
  begin
570
570
  sub = self.class.nest(v, Array(@nesting) + [key])
@@ -580,7 +580,7 @@ class Roda
580
580
  # Return the nested value for key. If there is no nested_value for +key+,
581
581
  # calls the block to return the value, or returns nil if there is no block given.
582
582
  def fetch(key)
583
- send(:[], key){return(yield if block_given?)}
583
+ send(:[], key){return(yield if defined?(yield))}
584
584
  end
585
585
 
586
586
  # Captures conversions inside the given block, and returns a hash of all conversions,
data/lib/roda/request.rb CHANGED
@@ -520,7 +520,7 @@ class Roda
520
520
  if matchdata = pattern.match(@remaining_path)
521
521
  @remaining_path = matchdata.post_match
522
522
  captures = matchdata.captures
523
- captures = yield(*captures) if block_given?
523
+ captures = yield(*captures) if defined?(yield)
524
524
  @captures.concat(captures)
525
525
  end
526
526
  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 = 48
7
+ RodaMinorVersion = 49
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.48.0
4
+ version: 3.49.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: 2021-09-13 00:00:00.000000000 Z
11
+ date: 2021-10-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack
@@ -219,6 +219,7 @@ extra_rdoc_files:
219
219
  - doc/release_notes/3.46.0.txt
220
220
  - doc/release_notes/3.47.0.txt
221
221
  - doc/release_notes/3.48.0.txt
222
+ - doc/release_notes/3.49.0.txt
222
223
  - doc/release_notes/3.5.0.txt
223
224
  - doc/release_notes/3.6.0.txt
224
225
  - doc/release_notes/3.7.0.txt
@@ -274,6 +275,7 @@ files:
274
275
  - doc/release_notes/3.46.0.txt
275
276
  - doc/release_notes/3.47.0.txt
276
277
  - doc/release_notes/3.48.0.txt
278
+ - doc/release_notes/3.49.0.txt
277
279
  - doc/release_notes/3.5.0.txt
278
280
  - doc/release_notes/3.6.0.txt
279
281
  - doc/release_notes/3.7.0.txt