Documentation for Roda (v3.71.0)
+Documentation for Roda (v3.72.0)
README (Introduction to Roda, start here if new)
@@ -126,6 +126,7 @@Plugins that Ship with Roda
Release Notes
A Modular, Scalable Ruby Framework
Currently at version 3.71.0
+Currently at version 3.72.0
class lib/roda/plugins/inject_erb.rb
Constants
The minor version of Roda
, updated for new feature releases of Roda
.
module lib/roda/plugins/inject_erb.rb
Classes and Modules
Public Instance methods
88 end 89 call_meth = meth 90 - 91 if (check_arity = opts.fetch(:check_arity, true)) && !block.lambda? - 92 required_args, optional_args, rest, keyword = _define_roda_method_arg_numbers(block) - 93 - 94 if keyword == :required && (expected_arity == 0 || expected_arity == 1) - 95 raise RodaError, "cannot use block with required keyword arguments when calling define_roda_method with expected arity #{expected_arity}" - 96 end - 97 - 98 case expected_arity - 99 when 0 -100 unless required_args == 0 -101 if check_arity == :warn -102 RodaPlugins.warn "Arity mismatch in block passed to define_roda_method. Expected Arity 0, but arguments required for #{block.inspect}" -103 end -104 b = block -105 block = lambda{instance_exec(&b)} # Fallback -106 end -107 when 1 -108 if required_args == 0 && optional_args == 0 && !rest -109 if check_arity == :warn -110 RodaPlugins.warn "Arity mismatch in block passed to define_roda_method. Expected Arity 1, but no arguments accepted for #{block.inspect}" -111 end -112 temp_method = roda_method_name("temp") -113 class_eval("def #{temp_method}(_) #{meth =~ /\A\w+\z/ ? "#{meth}_arity" : "send(:\"#{meth}_arity\")"} end", __FILE__, __LINE__) -114 alias_method meth, temp_method -115 undef_method temp_method -116 private meth -117 alias_method meth, meth -118 meth = :"#{meth}_arity" -119 elsif required_args > 1 -120 b = block -121 block = lambda{|r| instance_exec(r, &b)} # Fallback -122 end -123 when :any -124 if check_dynamic_arity = opts.fetch(:check_dynamic_arity, check_arity) -125 if keyword -126 # Complexity of handling keyword arguments using define_method is too high, -127 # Fallback to instance_exec in this case. -128 b = block -129 block = if RUBY_VERSION >= '2.7' -130 eval('lambda{|*a, **kw| instance_exec(*a, **kw, &b)}', nil, __FILE__, __LINE__) # Keyword arguments fallback -131 else -132 # :nocov: -133 lambda{|*a| instance_exec(*a, &b)} # Keyword arguments fallback -134 # :nocov: -135 end -136 else -137 arity_meth = meth -138 meth = :"#{meth}_arity" -139 end -140 end -141 else -142 raise RodaError, "unexpected arity passed to define_roda_method: #{expected_arity.inspect}" -143 end -144 end -145 -146 define_method(meth, &block) -147 private meth -148 alias_method meth, meth + 91 # RODA4: Switch to false # :warn in last Roda 3 version + 92 if (check_arity = opts.fetch(:check_arity, true)) && !block.lambda? + 93 required_args, optional_args, rest, keyword = _define_roda_method_arg_numbers(block) + 94 + 95 if keyword == :required && (expected_arity == 0 || expected_arity == 1) + 96 raise RodaError, "cannot use block with required keyword arguments when calling define_roda_method with expected arity #{expected_arity}" + 97 end + 98 + 99 case expected_arity +100 when 0 +101 unless required_args == 0 +102 if check_arity == :warn +103 RodaPlugins.warn "Arity mismatch in block passed to define_roda_method. Expected Arity 0, but arguments required for #{block.inspect}" +104 end +105 b = block +106 block = lambda{instance_exec(&b)} # Fallback +107 end +108 when 1 +109 if required_args == 0 && optional_args == 0 && !rest +110 if check_arity == :warn +111 RodaPlugins.warn "Arity mismatch in block passed to define_roda_method. Expected Arity 1, but no arguments accepted for #{block.inspect}" +112 end +113 temp_method = roda_method_name("temp") +114 class_eval("def #{temp_method}(_) #{meth =~ /\A\w+\z/ ? "#{meth}_arity" : "send(:\"#{meth}_arity\")"} end", __FILE__, __LINE__) +115 alias_method meth, temp_method +116 undef_method temp_method +117 private meth +118 alias_method meth, meth +119 meth = :"#{meth}_arity" +120 elsif required_args > 1 +121 if check_arity == :warn +122 RodaPlugins.warn "Arity mismatch in block passed to define_roda_method. Expected Arity 1, but multiple arguments required for #{block.inspect}" +123 end +124 b = block +125 block = lambda{|r| instance_exec(r, &b)} # Fallback +126 end +127 when :any +128 if check_dynamic_arity = opts.fetch(:check_dynamic_arity, check_arity) +129 if keyword +130 # Complexity of handling keyword arguments using define_method is too high, +131 # Fallback to instance_exec in this case. +132 b = block +133 block = if RUBY_VERSION >= '2.7' +134 eval('lambda{|*a, **kw| instance_exec(*a, **kw, &b)}', nil, __FILE__, __LINE__) # Keyword arguments fallback +135 else +136 # :nocov: +137 lambda{|*a| instance_exec(*a, &b)} # Keyword arguments fallback +138 # :nocov: +139 end +140 else +141 arity_meth = meth +142 meth = :"#{meth}_arity" +143 end +144 end +145 else +146 raise RodaError, "unexpected arity passed to define_roda_method: #{expected_arity.inspect}" +147 end +148 end 149 -150 if arity_meth -151 required_args, optional_args, rest, keyword = _define_roda_method_arg_numbers(instance_method(meth)) -152 max_args = required_args + optional_args -153 define_method(arity_meth) do |*a| -154 arity = a.length -155 if arity > required_args -156 if arity > max_args && !rest -157 if check_dynamic_arity == :warn -158 RodaPlugins.warn "Dynamic arity mismatch in block passed to define_roda_method. At most #{max_args} arguments accepted, but #{arity} arguments given for #{block.inspect}" -159 end -160 a = a.slice(0, max_args) -161 end -162 elsif arity < required_args -163 if check_dynamic_arity == :warn -164 RodaPlugins.warn "Dynamic arity mismatch in block passed to define_roda_method. #{required_args} args required, but #{arity} arguments given for #{block.inspect}" +150 define_method(meth, &block) +151 private meth +152 alias_method meth, meth +153 +154 if arity_meth +155 required_args, optional_args, rest, keyword = _define_roda_method_arg_numbers(instance_method(meth)) +156 max_args = required_args + optional_args +157 define_method(arity_meth) do |*a| +158 arity = a.length +159 if arity > required_args +160 if arity > max_args && !rest +161 if check_dynamic_arity == :warn +162 RodaPlugins.warn "Dynamic arity mismatch in block passed to define_roda_method. At most #{max_args} arguments accepted, but #{arity} arguments given for #{block.inspect}" +163 end +164 a = a.slice(0, max_args) 165 end -166 a.concat([nil] * (required_args - arity)) -167 end -168 -169 send(meth, *a) -170 end -171 private arity_meth -172 alias_method arity_meth, arity_meth -173 end -174 -175 call_meth -176 end +166 elsif arity < required_args +167 if check_dynamic_arity == :warn +168 RodaPlugins.warn "Dynamic arity mismatch in block passed to define_roda_method. #{required_args} args required, but #{arity} arguments given for #{block.inspect}" +169 end +170 a.concat([nil] * (required_args - arity)) +171 end +172 +173 send(meth, *a) +174 end +175 private arity_meth +176 alias_method arity_meth, arity_meth +177 end +178 +179 call_meth +180 endPublic Instance methods
[show source]# File lib/roda.rb -179 def expand_path(path, root=opts[:root]) -180 ::File.expand_path(path, root) -181 end+183 def expand_path(path, root=opts[:root]) +184 ::File.expand_path(path, root) +185 end
Public Instance methods
[show source]# File lib/roda.rb -190 def freeze -191 return self if frozen? -192 -193 unless opts[:subclassed] -194 # If the _roda_run_main_route instance method has not been overridden, -195 # make it an alias to _roda_main_route for performance -196 if instance_method(:_roda_run_main_route).owner == InstanceMethods -197 class_eval("alias _roda_run_main_route _roda_main_route") -198 end -199 self::RodaResponse.class_eval do -200 if instance_method(:set_default_headers).owner == ResponseMethods && -201 instance_method(:default_headers).owner == ResponseMethods -202 -203 private -204 -205 alias set_default_headers set_default_headers -206 def set_default_headers -207 @headers[RodaResponseHeaders::CONTENT_TYPE] ||= 'text/html' -208 end -209 end -210 end -211 -212 if @middleware.empty? && use_new_dispatch_api? -213 plugin :direct_call +194 def freeze +195 return self if frozen? +196 +197 unless opts[:subclassed] +198 # If the _roda_run_main_route instance method has not been overridden, +199 # make it an alias to _roda_main_route for performance +200 if instance_method(:_roda_run_main_route).owner == InstanceMethods +201 class_eval("alias _roda_run_main_route _roda_main_route") +202 end +203 self::RodaResponse.class_eval do +204 if instance_method(:set_default_headers).owner == ResponseMethods && +205 instance_method(:default_headers).owner == ResponseMethods +206 +207 private +208 +209 alias set_default_headers set_default_headers +210 def set_default_headers +211 @headers[RodaResponseHeaders::CONTENT_TYPE] ||= 'text/html' +212 end +213 end 214 end 215 -216 if ([:on, :is, :_verb, :_match_class_String, :_match_class_Integer, :_match_string, :_match_regexp, :empty_path?, :if_match, :match, :_match_class]).all?{|m| self::RodaRequest.instance_method(m).owner == RequestMethods} -217 plugin :_optimized_matching +216 if @middleware.empty? && use_new_dispatch_api? +217 plugin :direct_call 218 end -219 end -220 -221 build_rack_app -222 @opts.freeze -223 @middleware.freeze +219 +220 if ([:on, :is, :_verb, :_match_class_String, :_match_class_Integer, :_match_string, :_match_regexp, :empty_path?, :if_match, :match, :_match_class]).all?{|m| self::RodaRequest.instance_method(m).owner == RequestMethods} +221 plugin :_optimized_matching +222 end +223 end 224 -225 super -226 end+225 build_rack_app +226 @opts.freeze +227 @middleware.freeze +228 +229 super +230 end
Public Instance methods
[show source]# File lib/roda.rb -230 def include(*a) -231 res = super -232 def_roda_before -233 def_roda_after -234 res -235 end+234 def include(*a) +235 res = super +236 def_roda_before +237 def_roda_after +238 res +239 end
Public Instance methods
[show source]# File lib/roda.rb -239 def inherited(subclass) -240 raise RodaError, "Cannot subclass a frozen Roda class" if frozen? -241 -242 # Mark current class as having been subclassed, as some optimizations -243 # depend on the class not being subclassed -244 opts[:subclassed] = true +243 def inherited(subclass) +244 raise RodaError, "Cannot subclass a frozen Roda class" if frozen? 245 -246 super -247 subclass.instance_variable_set(:@inherit_middleware, @inherit_middleware) -248 subclass.instance_variable_set(:@middleware, @inherit_middleware ? @middleware.dup : []) -249 subclass.instance_variable_set(:@opts, opts.dup) -250 subclass.opts.delete(:subclassed) -251 subclass.opts.to_a.each do |k,v| -252 if (v.is_a?(Array) || v.is_a?(Hash)) && !v.frozen? -253 subclass.opts[k] = v.dup -254 end -255 end -256 if block = @raw_route_block -257 subclass.route(&block) -258 end -259 -260 request_class = Class.new(self::RodaRequest) -261 request_class.roda_class = subclass -262 request_class.match_pattern_cache = RodaCache.new -263 subclass.const_set(:RodaRequest, request_class) -264 -265 response_class = Class.new(self::RodaResponse) -266 response_class.roda_class = subclass -267 subclass.const_set(:RodaResponse, response_class) -268 end+246 # Mark current class as having been subclassed, as some optimizations +247 # depend on the class not being subclassed +248 opts[:subclassed] = true +249 +250 super +251 subclass.instance_variable_set(:@inherit_middleware, @inherit_middleware) +252 subclass.instance_variable_set(:@middleware, @inherit_middleware ? @middleware.dup : []) +253 subclass.instance_variable_set(:@opts, opts.dup) +254 subclass.opts.delete(:subclassed) +255 subclass.opts.to_a.each do |k,v| +256 if (v.is_a?(Array) || v.is_a?(Hash)) && !v.frozen? +257 subclass.opts[k] = v.dup +258 end +259 end +260 if block = @raw_route_block +261 subclass.route(&block) +262 end +263 +264 request_class = Class.new(self::RodaRequest) +265 request_class.roda_class = subclass +266 request_class.match_pattern_cache = RodaCache.new +267 subclass.const_set(:RodaRequest, request_class) +268 +269 response_class = Class.new(self::RodaResponse) +270 response_class.roda_class = subclass +271 subclass.const_set(:RodaResponse, response_class) +272 end
Public Instance methods
[show source]# File lib/roda.rb -279 def plugin(plugin, *args, &block) -280 raise RodaError, "Cannot add a plugin to a frozen Roda class" if frozen? -281 plugin = RodaPlugins.load_plugin(plugin) if plugin.is_a?(Symbol) -282 raise RodaError, "Invalid plugin type: #{plugin.class.inspect}" unless plugin.is_a?(Module) -283 -284 if !plugin.respond_to?(:load_dependencies) && !plugin.respond_to?(:configure) && (!args.empty? || block) -285 # RODA4: switch from warning to error -286 RodaPlugins.warn("Plugin #{plugin} does not accept arguments or a block, but arguments or a block was passed when loading this. This will raise an error in Roda 4.") -287 end -288 -289 plugin.load_dependencies(self, *args, &block) if plugin.respond_to?(:load_dependencies) -290 include(plugin::InstanceMethods) if defined?(plugin::InstanceMethods) -291 extend(plugin::ClassMethods) if defined?(plugin::ClassMethods) -292 self::RodaRequest.send(:include, plugin::RequestMethods) if defined?(plugin::RequestMethods) -293 self::RodaRequest.extend(plugin::RequestClassMethods) if defined?(plugin::RequestClassMethods) -294 self::RodaResponse.send(:include, plugin::ResponseMethods) if defined?(plugin::ResponseMethods) -295 self::RodaResponse.extend(plugin::ResponseClassMethods) if defined?(plugin::ResponseClassMethods) -296 plugin.configure(self, *args, &block) if plugin.respond_to?(:configure) -297 @app = nil -298 end+283 def plugin(plugin, *args, &block) +284 raise RodaError, "Cannot add a plugin to a frozen Roda class" if frozen? +285 plugin = RodaPlugins.load_plugin(plugin) if plugin.is_a?(Symbol) +286 raise RodaError, "Invalid plugin type: #{plugin.class.inspect}" unless plugin.is_a?(Module) +287 +288 if !plugin.respond_to?(:load_dependencies) && !plugin.respond_to?(:configure) && (!args.empty? || block) +289 # RODA4: switch from warning to error +290 RodaPlugins.warn("Plugin #{plugin} does not accept arguments or a block, but arguments or a block was passed when loading this. This will raise an error in Roda 4.") +291 end +292 +293 plugin.load_dependencies(self, *args, &block) if plugin.respond_to?(:load_dependencies) +294 include(plugin::InstanceMethods) if defined?(plugin::InstanceMethods) +295 extend(plugin::ClassMethods) if defined?(plugin::ClassMethods) +296 self::RodaRequest.send(:include, plugin::RequestMethods) if defined?(plugin::RequestMethods) +297 self::RodaRequest.extend(plugin::RequestClassMethods) if defined?(plugin::RequestClassMethods) +298 self::RodaResponse.send(:include, plugin::ResponseMethods) if defined?(plugin::ResponseMethods) +299 self::RodaResponse.extend(plugin::ResponseClassMethods) if defined?(plugin::ResponseClassMethods) +300 plugin.configure(self, *args, &block) if plugin.respond_to?(:configure) +301 @app = nil +302 end
Public Instance methods
[show source]# File lib/roda.rb -316 def route(&block) -317 unless block -318 RodaPlugins.warn "no block passed to Roda.route" -319 return -320 end -321 -322 @raw_route_block = block -323 @route_block = block = convert_route_block(block) -324 @rack_app_route_block = block = rack_app_route_block(block) -325 public define_roda_method(:_roda_main_route, 1, &block) -326 @app = nil -327 end+320 def route(&block) +321 unless block +322 RodaPlugins.warn "no block passed to Roda.route" +323 return +324 end +325 +326 @raw_route_block = block +327 @route_block = block = convert_route_block(block) +328 @rack_app_route_block = block = rack_app_route_block(block) +329 public define_roda_method(:_roda_main_route, 1, &block) +330 @app = nil +331 end
Public Instance methods
[show source]# File lib/roda.rb -206 def set_default_headers -207 @headers[RodaResponseHeaders::CONTENT_TYPE] ||= 'text/html' -208 end+210 def set_default_headers +211 @headers[RodaResponseHeaders::CONTENT_TYPE] ||= 'text/html' +212 end
Public Instance methods
[show source]# File lib/roda.rb -333 def use(*args, &block) -334 @middleware << [args, block].freeze -335 @app = nil -336 end+337 def use(*args, &block) +338 @middleware << [args, block].freeze +339 @app = nil +340 end
Public Class methods
[show source]# File lib/roda.rb -485 def initialize(env) -486 klass = self.class -487 @_request = klass::RodaRequest.new(self, env) -488 @_response = klass::RodaResponse.new -489 end+489 def initialize(env) +490 klass = self.class +491 @_request = klass::RodaRequest.new(self, env) +492 @_response = klass::RodaResponse.new +493 end
Public Instance methods
@@ -108,13 +108,13 @@Public Instance methods
[show source]# File lib/roda.rb -493 def _roda_handle_main_route -494 catch(:halt) do -495 r = @_request -496 r.block_result(_roda_run_main_route(r)) -497 @_response.finish -498 end -499 end+497 def _roda_handle_main_route +498 catch(:halt) do +499 r = @_request +500 r.block_result(_roda_run_main_route(r)) +501 @_response.finish +502 end +503 end
Public Instance methods
[show source]# File lib/roda.rb -503 def _roda_handle_route -504 catch(:halt) do -505 @_request.block_result(yield) -506 @_response.finish -507 end -508 end+507 def _roda_handle_route +508 catch(:halt) do +509 @_request.block_result(yield) +510 @_response.finish +511 end +512 end
Public Instance methods
[show source]# File lib/roda.rb -512 def _roda_main_route(_) -513 end+516 def _roda_main_route(_) +517 end
Public Instance methods
[show source]# File lib/roda.rb -517 def _roda_run_main_route(r) -518 _roda_main_route(r) -519 end+521 def _roda_run_main_route(r) +522 _roda_main_route(r) +523 end
Public Instance methods
[show source]# File lib/roda.rb -522 def call(&block) -523 # RODA4: Remove -524 catch(:halt) do -525 r = @_request -526 r.block_result(instance_exec(r, &block)) # Fallback -527 @_response.finish -528 end -529 end+526 def call(&block) +527 # RODA4: Remove +528 catch(:halt) do +529 r = @_request +530 r.block_result(instance_exec(r, &block)) # Fallback +531 @_response.finish +532 end +533 end
Public Instance methods
[show source]# File lib/roda.rb -539 def env -540 @_request.env -541 end+543 def env +544 @_request.env +545 end
Public Instance methods
[show source]# File lib/roda.rb -550 def opts -551 self.class.opts -552 end+554 def opts +555 self.class.opts +556 end
Public Instance methods
[show source]# File lib/roda.rb -566 def session -567 @_request.session -568 end+570 def session +571 @_request.session +572 end
module +Roda::RodaPlugins::InvalidRequestBody +
+ +The invalid_request_body plugin allows for custom handling of invalid request bodies. Roda
uses Rack for parsing request bodies, so by default, any invalid request bodies would result in Rack raising an exception, and the exception could change for different reasons the request body is invalid. This plugin overrides RodaRequest#POST (which parses parameters from request bodies), and if parsing raises an exception, it allows for custom behavior.
If you want to treat an invalid request body as the submission of no parameters, you can use the :empty_hash argument when loading the plugin:
+ +plugin :invalid_request_body, :empty_hash ++ +
If you want to return a empty 400 (Bad Request) response if an invalid request body is submitted, you can use the :empty_400 argument when loading the plugin:
+ +plugin :invalid_request_body, :empty_400 ++ +
If you want to raise a Roda::RodaPlugins::InvalidRequestBody::Error
exception if an invalid request body is submitted (which makes it easier to handle these exceptions when using the error_handler plugin), you can use the :raise argument when loading the plugin:
plugin :invalid_request_body, :raise ++ +
For custom behavior, you can pass a block when loading the plugin. The block is called with the exception Rack raised when parsing the body. The block will be used to define a method in the application’s RodaRequest
class. It can either return a hash of parameters, or you can raise a different exception, or you can halt processing and return a response:
plugin :invalid_request_body do |exception| + # To treat the exception raised as a submitted parameter + {body_error: exception} +end ++
Classes and Modules
+ +Constants
+Error | += | +Class.new(RodaError) | ++ |
+ Exception class raised for invalid request bodies. + |
+
Public Class methods
+Set the action to use (:empty_400, :empty_hash, :raise) for invalid request bodies, or use a block for custom behavior.
+ +# File lib/roda/plugins/invalid_request_body.rb +46 def self.configure(app, action=nil, &block) +47 if action +48 if block +49 raise RodaError, "cannot provide both block and action when loading invalid_request_body plugin" +50 end +51 +52 method = :"handle_invalid_request_body_#{action}" +53 unless RequestMethods.private_method_defined?(method) +54 raise RodaError, "invalid invalid_request_body action provided: #{action}" +55 end +56 +57 app::RodaRequest.send(:alias_method, :handle_invalid_request_body, method) +58 elsif block +59 app::RodaRequest.class_eval do +60 define_method(:handle_invalid_request_body, &block) +61 alias handle_invalid_request_body handle_invalid_request_body +62 end +63 else +64 raise RodaError, "must provide block or action when loading invalid_request_body plugin" +65 end +66 +67 app::RodaRequest.send(:private, :handle_invalid_request_body) +68 end+
module -Roda::RodaPlugins::MatchHook::InstanceMethods +Roda::RodaPlugins::InvalidRequestBody::RequestMethods
module
Methods
Public Instance
Public Instance
Public Instance methods
-Default empty method if no match hooks are defined.
+Handle invalid request bodies as configured if the default behavior raises an exception.
# File lib/roda/plugins/match_hook.rb -46 def _match_hook -47 end+
# File lib/roda/plugins/invalid_request_body.rb +73 def POST +74 super +75 rescue => e +76 handle_invalid_request_body(e) +77 end
module
-The match_hook plugin adds hooks that are called upon a successful match by any of the matchers. The hooks do not take any arguments. If you would like hooks that pass the arguments/matchers and values yielded to the route block, use the match_hook_args plugin.
+The match_hook plugin adds hooks that are called upon a successful match by any of the matchers. The hooks do not take any arguments. If you would like hooks that pass the arguments/matchers and values yielded to the route block, use the match_hook_args plugin. This uses the match_hook_args plugin internally, but doesn’t pass the matchers and values yielded.
plugin :match_hook
@@ -49,7 +49,7 @@ module
Methods
Public Class
@@ -58,30 +58,28 @@ Public Class
Classes and Modules
Public Class methods
-
-
+
+
-configure(app)
+load_dependencies(app)
-
+
[show source]
- # File lib/roda/plugins/match_hook.rb
-17 def self.configure(app)
-18 app.opts[:match_hooks] ||= []
-19 end
+ # File lib/roda/plugins/match_hook.rb
+18 def self.load_dependencies(app)
+19 app.plugin :match_hook_args
+20 end
diff --git a/rdoc/classes/Roda/RodaPlugins/MatchHook/ClassMethods.html b/rdoc/classes/Roda/RodaPlugins/MatchHook/ClassMethods.html
index 8da558bf..142ea0cd 100644
--- a/rdoc/classes/Roda/RodaPlugins/MatchHook/ClassMethods.html
+++ b/rdoc/classes/Roda/RodaPlugins/MatchHook/ClassMethods.html
@@ -40,7 +40,6 @@ module
Methods
Public Instance
@@ -49,28 +48,6 @@ Public Instance
Public Instance methods
-
-
-
-freeze()
-
-
-
-
-Freeze the array of hook methods when freezing the app
-
-
-
-
-[show source]
-
- # File lib/roda/plugins/match_hook.rb
-23 def freeze
-24 opts[:match_hooks].freeze
-25 super
-26 end
-
-
@@ -87,19 +64,11 @@ Public Instance methods
[show source]
# File lib/roda/plugins/match_hook.rb
-29 def match_hook(&block)
-30 opts[:match_hooks] << define_roda_method("match_hook", 0, &block)
-31
-32 if opts[:match_hooks].length == 1
-33 class_eval("alias _match_hook #{opts[:match_hooks].first}", __FILE__, __LINE__)
-34 else
-35 class_eval("def _match_hook; #{opts[:match_hooks].join(';')} end", __FILE__, __LINE__)
-36 end
-37
-38 public :_match_hook
-39
-40 nil
-41 end
+24 def match_hook(&block)
+25 meth = define_roda_method("match_hook", 0, &block)
+26 add_match_hook{|_,_| send(meth)}
+27 nil
+28 end
diff --git a/rdoc/created.rid b/rdoc/created.rid
index 385e250c..fba30799 100644
--- a/rdoc/created.rid
+++ b/rdoc/created.rid
@@ -1,9 +1,9 @@
-Mon, 14 Aug 2023 09:03:07 -0700
+Tue, 12 Sep 2023 10:44:05 -0700
README.rdoc Sat, 08 Oct 2022 12:13:45 -0700
-CHANGELOG Mon, 14 Aug 2023 08:54:23 -0700
+CHANGELOG Tue, 12 Sep 2023 10:34:26 -0700
doc/CHANGELOG.old Fri, 11 Mar 2022 10:33:07 -0800
MIT-LICENSE Thu, 12 Jan 2023 07:50:45 -0800
-lib/roda.rb Mon, 19 Jun 2023 16:20:51 -0700
+lib/roda.rb Mon, 14 Aug 2023 09:53:11 -0700
lib/roda/cache.rb Tue, 12 Jan 2021 15:49:31 -0800
lib/roda/plugins.rb Wed, 27 Nov 2019 12:12:01 -0800
lib/roda/plugins/Integer_matcher_max.rb Tue, 08 Nov 2022 08:49:54 -0800
@@ -64,13 +64,14 @@ lib/roda/plugins/hooks.rb Sat, 06 Apr 2019 23:21:10 -0700
lib/roda/plugins/host_authorization.rb Mon, 12 Apr 2021 11:05:35 -0700
lib/roda/plugins/indifferent_params.rb Thu, 02 Feb 2023 11:13:09 -0800
lib/roda/plugins/inject_erb.rb Tue, 02 Nov 2021 13:25:06 -0700
+lib/roda/plugins/invalid_request_body.rb Mon, 11 Sep 2023 09:47:41 -0700
lib/roda/plugins/json.rb Tue, 08 Aug 2023 07:33:24 -0700
lib/roda/plugins/json_parser.rb Mon, 12 Sep 2022 13:47:50 -0700
lib/roda/plugins/link_to.rb Fri, 26 Aug 2022 13:01:46 -0700
lib/roda/plugins/mail_processor.rb Sat, 15 Jul 2023 08:02:19 -0700
lib/roda/plugins/mailer.rb Mon, 19 Jun 2023 16:20:51 -0700
lib/roda/plugins/match_affix.rb Mon, 22 Jun 2020 15:56:02 -0700
-lib/roda/plugins/match_hook.rb Mon, 07 Aug 2023 13:25:44 -0700
+lib/roda/plugins/match_hook.rb Mon, 14 Aug 2023 09:50:32 -0700
lib/roda/plugins/match_hook_args.rb Mon, 14 Aug 2023 08:54:23 -0700
lib/roda/plugins/middleware.rb Fri, 25 Mar 2022 08:00:11 -0700
lib/roda/plugins/middleware_stack.rb Fri, 12 Jan 2018 08:46:22 -0800
@@ -135,7 +136,7 @@ lib/roda/plugins/view_options.rb Mon, 12 Sep 2022 13:47:50 -0700
lib/roda/request.rb Fri, 17 Mar 2023 08:33:20 -0700
lib/roda/response.rb Mon, 19 Jun 2023 16:20:51 -0700
lib/roda/session_middleware.rb Sun, 04 Aug 2019 14:34:46 -0700
-lib/roda/version.rb Mon, 14 Aug 2023 08:54:23 -0700
+lib/roda/version.rb Tue, 12 Sep 2023 10:34:26 -0700
doc/conventions.rdoc Mon, 13 Jun 2022 14:42:04 -0700
doc/release_notes/1.0.0.txt Tue, 19 Aug 2014 09:04:25 -0700
doc/release_notes/1.1.0.txt Tue, 11 Nov 2014 11:35:26 -0800
@@ -243,5 +244,6 @@ doc/release_notes/3.69.0.txt Tue, 13 Jun 2023 07:51:16 -0700
doc/release_notes/3.7.0.txt Fri, 20 Apr 2018 11:49:04 -0700
doc/release_notes/3.70.0.txt Tue, 11 Jul 2023 16:10:40 -0700
doc/release_notes/3.71.0.txt Mon, 14 Aug 2023 08:54:23 -0700
+doc/release_notes/3.72.0.txt Tue, 12 Sep 2023 10:34:26 -0700
doc/release_notes/3.8.0.txt Thu, 17 May 2018 13:49:47 -0700
doc/release_notes/3.9.0.txt Mon, 11 Jun 2018 12:33:07 -0700
diff --git a/rdoc/files/CHANGELOG.html b/rdoc/files/CHANGELOG.html
index 3ef2fd74..271c073a 100644
--- a/rdoc/files/CHANGELOG.html
+++ b/rdoc/files/CHANGELOG.html
@@ -31,12 +31,21 @@ CHANGELOG
Last Update:
-2023-08-14 08:54:23 -0700
+2023-09-12 10:34:26 -0700
+3.72.0 (2023-09-12)¶ ↑
+-
+
Add invalid_request_body plugin for custom handling of invalid request bodies (jeremyevans)
+ -
+
Warn when defining method that expects 1 argument when block requires multiple arguments when :check_arity option is set to :warn (jeremyevans)
+ -
+
Implement the match_hooks plugin using the match_hook_args plugin (jeremyevans)
+
+
3.71.0 (2023-08-14)¶ ↑
-
Add match_hook_args plugin, similar to match_hooks but support matchers and block args as hook arguments (jeremyevans)
diff --git a/rdoc/files/doc/release_notes/3_72_0_txt.html b/rdoc/files/doc/release_notes/3_72_0_txt.html
new file mode 100644
index 00000000..52a53c54
--- /dev/null
+++ b/rdoc/files/doc/release_notes/3_72_0_txt.html
@@ -0,0 +1,87 @@
+
+
+
+3.72.0.txt
+
+
+
+
+
+
+
+
+3.72.0.txt
+
+
+doc/release_notes/3.72.0.txt
+
+
+Last Update:
+2023-09-12 10:34:26 -0700
+
+
+
+
+
+New Features¶ ↑
+-
+
An invalid_request_body plugin has been added for allowing custom handling of invalid request bodies. Roda
uses Rack’s request body parsing, and by default invalid request bodies can result in different exceptions based on how the body is invalid and which version of Rack is in use.
+
+If you want to treat an invalid request body as the submission of no parameters, you can use the :empty_hash argument when loading the plugin:
+
+plugin :invalid_request_body, :empty_hash
+
+
+If you want to return a empty 400 (Bad Request) response if an invalid request body is submitted, you can use the :empty_400 argument when loading the plugin:
+
+plugin :invalid_request_body, :empty_400
+
+
+If you want to raise a Roda::RodaPlugins::InvalidRequestBody::Error exception if an invalid request body is submitted (which makes it easier to handle these exceptions when using the error_handler plugin), you can use the :raise argument when loading the plugin:
+
+plugin :invalid_request_body, :raise
+
+
+For custom behavior, you can pass a block when loading the plugin The block is called with the exception Rack raised when parsing the body. The block will be used to define a method in the application’s RodaRequest class. It can either return a hash of parameters, or you can raise a different exception, or you can halt processing and return a response:
+
+plugin :invalid_request_body do |exception|
+ # To treat the exception raised as a submitted parameter
+ {body_error: exception}
+end
+
+
+
+Other Improvements¶ ↑
+-
+
When using the check_arity: :warn Roda
option, Roda
now correctly warns when defining a method that expects a single argument when the provided block requires multiple arguments.
+ -
+
The match_hooks plugin is now implemented using the match_hook_args plugin, simplifying the implementation. This change should be transparent unless you were reaching into the internals.
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/rdoc/classes/Roda/RodaPlugins/MatchHook/RequestMethods.html b/rdoc/files/lib/roda/plugins/invalid_request_body_rb.html
similarity index 77%
rename from rdoc/classes/Roda/RodaPlugins/MatchHook/RequestMethods.html
rename to rdoc/files/lib/roda/plugins/invalid_request_body_rb.html
index 40f279d6..4f0be9d7 100644
--- a/rdoc/classes/Roda/RodaPlugins/MatchHook/RequestMethods.html
+++ b/rdoc/files/lib/roda/plugins/invalid_request_body_rb.html
@@ -1,7 +1,7 @@
-Roda::RodaPlugins::MatchHook::RequestMethods
+invalid_request_body.rb
@@ -22,24 +22,23 @@
-
+
-module
-Roda::RodaPlugins::MatchHook::RequestMethods
+invalid_request_body.rb
-
+
+lib/roda/plugins/invalid_request_body.rb
+
+
+Last Update:
+2023-09-11 09:47:41 -0700
+
-
-
diff --git a/rdoc/files/lib/roda/plugins/match_hook_rb.html b/rdoc/files/lib/roda/plugins/match_hook_rb.html
index 0b924dda..cd58199f 100644
--- a/rdoc/files/lib/roda/plugins/match_hook_rb.html
+++ b/rdoc/files/lib/roda/plugins/match_hook_rb.html
@@ -31,7 +31,7 @@ match_hook.rb
Last Update:
-2023-08-07 13:25:44 -0700
+2023-08-14 09:50:32 -0700
diff --git a/rdoc/files/lib/roda/version_rb.html b/rdoc/files/lib/roda/version_rb.html
index 405d2f54..7dc4acec 100644
--- a/rdoc/files/lib/roda/version_rb.html
+++ b/rdoc/files/lib/roda/version_rb.html
@@ -31,7 +31,7 @@ version.rb
Last Update:
-2023-08-14 08:54:23 -0700
+2023-09-12 10:34:26 -0700
diff --git a/rdoc/files/lib/roda_rb.html b/rdoc/files/lib/roda_rb.html
index 426c4959..10c47095 100644
--- a/rdoc/files/lib/roda_rb.html
+++ b/rdoc/files/lib/roda_rb.html
@@ -31,7 +31,7 @@ roda.rb
Last Update:
-2023-06-19 16:20:51 -0700
+2023-08-14 09:53:11 -0700
diff --git a/rdoc/fr_class_index.html b/rdoc/fr_class_index.html
index c744e2ed..41be83b2 100644
--- a/rdoc/fr_class_index.html
+++ b/rdoc/fr_class_index.html
@@ -156,6 +156,8 @@
Roda::RodaPlugins::InjectERB::InstanceMethods
Roda::RodaPlugins::Json
Roda::RodaPlugins::Json::ClassMethods
Roda::RodaPlugins::Json::InstanceMethods
@@ -180,8 +182,6 @@
Roda::RodaPlugins::MatchAffix::RequestMethods
Roda::RodaPlugins::MatchHook
Roda::RodaPlugins::MatchHook::ClassMethods
-Roda::RodaPlugins::MatchHook::InstanceMethods
-Roda::RodaPlugins::MatchHook::RequestMethods
Roda::RodaPlugins::MatchHookArgs
Roda::RodaPlugins::MatchHookArgs::ClassMethods
Roda::RodaPlugins::MatchHookArgs::InstanceMethods
diff --git a/rdoc/fr_file_index.html b/rdoc/fr_file_index.html
index 54f3392b..ed20f193 100644
--- a/rdoc/fr_file_index.html
+++ b/rdoc/fr_file_index.html
@@ -121,6 +121,7 @@
3.7.0.txt
3.70.0.txt
3.71.0.txt
+3.72.0.txt
3.8.0.txt
3.9.0.txt
roda.rb
@@ -184,6 +185,7 @@
host_authorization.rb
indifferent_params.rb
inject_erb.rb
+invalid_request_body.rb
json.rb
json_parser.rb
link_to.rb
diff --git a/rdoc/fr_method_index.html b/rdoc/fr_method_index.html
index 475bc30e..7f1d17d8 100644
--- a/rdoc/fr_method_index.html
+++ b/rdoc/fr_method_index.html
@@ -38,57 +38,57 @@
#scope (Roda::RodaPlugins::Base::RequestMethods)
#status (Roda::RodaPlugins::Base::ResponseMethods)
::configure (Roda::RodaPlugins::CustomBlockResults)
-::configure (Roda::RodaPlugins::Csrf)
::configure (Roda::RodaPlugins::SinatraHelpers)
::configure (Roda::RodaPlugins::Middleware)
-::configure (Roda::RodaPlugins::CustomMatchers)
::configure (Roda::RodaPlugins::MatchHookArgs)
-::configure (Roda::RodaPlugins::Cookies)
+::configure (Roda::RodaPlugins::Csrf)
+::configure (Roda::RodaPlugins::CustomMatchers)
::configure (Roda::RodaPlugins::DefaultHeaders)
+::configure (Roda::RodaPlugins::Cookies)
::configure (Roda::RodaPlugins::AdditionalRenderEngines)
::configure (Roda::RodaPlugins::DefaultStatus)
::configure (Roda::RodaPlugins::AdditionalViewDirectories)
::configure (Roda::RodaPlugins::Sessions)
::configure (Roda::RodaPlugins::Assets)
::configure (Roda::RodaPlugins::RunAppendSlash)
-::configure (Roda::RodaPlugins::MatchHook)
::configure (Roda::RodaPlugins::MatchAffix)
::configure (Roda::RodaPlugins::DirectCall)
::configure (Roda::RodaPlugins::Environments)
::configure (Roda::RodaPlugins::MultiPublic)
-::configure (Roda::RodaPlugins::ContentSecurityPolicy)
-::configure (Roda::RodaPlugins::MultiRoute)
::configure (Roda::RodaPlugins::ErrorEmail)
-::configure (Roda::RodaPlugins::ContentFor)
-::configure (Roda::RodaPlugins::MultiRun)
+::configure (Roda::RodaPlugins::MultiRoute)
+::configure (Roda::RodaPlugins::ContentSecurityPolicy)
::configure (Roda::RodaPlugins::ErrorHandler)
-::configure (Roda::RodaPlugins::AutoloadHashBranches)
+::configure (Roda::RodaPlugins::MultiRun)
::configure (Roda::RodaPlugins::Mailer)
-::configure (Roda::RodaPlugins::CommonLogger)
+::configure (Roda::RodaPlugins::ContentFor)
+::configure (Roda::RodaPlugins::AutoloadHashBranches)
::configure (Roda::RodaPlugins::ErrorMail)
+::configure (Roda::RodaPlugins::CommonLogger)
+::configure (Roda::RodaPlugins::NamedRoutes)
::configure (Roda::RodaPlugins::ClassLevelRouting)
::configure (Roda::RodaPlugins::AutoloadNamedRoutes)
-::configure (Roda::RodaPlugins::NamedRoutes)
::configure (Roda::RodaPlugins::Static)
::configure (Roda::RodaPlugins::NamedTemplates)
::configure (Roda::RodaPlugins::FilterCommonLogger)
-::configure (Roda::RodaPlugins::Render)
-::configure (Roda::RodaPlugins::NotFound)
::configure (Roda::RodaPlugins::RouteCsrf)
+::configure (Roda::RodaPlugins::NotFound)
+::configure (Roda::RodaPlugins::Render)
::configure (Roda::RodaPlugins::Chunked)
-::configure (Roda::RodaPlugins::HashBranchViewSubdir)
::configure (Roda::RodaPlugins::Path)
+::configure (Roda::RodaPlugins::HashBranchViewSubdir)
::configure (Roda::RodaPlugins::PathRewriter)
::configure (Roda::RodaPlugins::RouteBlockArgs)
::configure (Roda::RodaPlugins::HashBranches)
::configure (Roda::RodaPlugins::RequestAref)
::configure (Roda::RodaPlugins::RenderLocals)
::configure (Roda::RodaPlugins::HashPaths)
-::configure (Roda::RodaPlugins::StripPathPrefix)
-::configure (Roda::RodaPlugins::JsonParser)
::configure (Roda::RodaPlugins::RenderCoverage)
+::configure (Roda::RodaPlugins::JsonParser)
+::configure (Roda::RodaPlugins::StripPathPrefix)
::configure (Roda::RodaPlugins::Public)
::configure (Roda::RodaPlugins::Json)
+::configure (Roda::RodaPlugins::InvalidRequestBody)
::configure (Roda::RodaPlugins::HashRoutes)
::configure (Roda::RodaPlugins::IntegerMatcherMax)
::configure (Roda::RodaPlugins::SymbolMatchers)
@@ -106,73 +106,74 @@
::deprecate_constant (Roda::RodaPlugins)
::handle_type (Roda::RodaPlugins::TypecastParams::Params)
::js (Roda::RodaPlugins::ExceptionPage)
-::load_dependencies (Roda::RodaPlugins::FilterCommonLogger)
+::load_dependencies (Roda::RodaPlugins::MultiRoute)
::load_dependencies (Roda::RodaPlugins::AdditionalRenderEngines)
::load_dependencies (Roda::RodaPlugins::SinatraHelpers)
::load_dependencies (Roda::RodaPlugins::AdditionalViewDirectories)
::load_dependencies (Roda::RodaPlugins::InjectERB)
::load_dependencies (Roda::RodaPlugins::RecheckPrecompiledAssets)
::load_dependencies (Roda::RodaPlugins::Assets)
+::load_dependencies (Roda::RodaPlugins::MatchHook)
::load_dependencies (Roda::RodaPlugins::MatchAffix)
-::load_dependencies (Roda::RodaPlugins::MultiPublic)
::load_dependencies (Roda::RodaPlugins::TypecastParamsSizedIntegers)
::load_dependencies (Roda::RodaPlugins::HashRoutes)
::load_dependencies (Roda::RodaPlugins::SymbolMatchers)
-::load_dependencies (Roda::RodaPlugins::RenderCoverage)
+::load_dependencies (Roda::RodaPlugins::MultiPublic)
+::load_dependencies (Roda::RodaPlugins::ErbH)
::load_dependencies (Roda::RodaPlugins::PrecompileTemplates)
::load_dependencies (Roda::RodaPlugins::LinkTo)
-::load_dependencies (Roda::RodaPlugins::PlaceholderStringMatchers)
::load_dependencies (Roda::RodaPlugins::NamedTemplates)
-::load_dependencies (Roda::RodaPlugins::RenderLocals)
+::load_dependencies (Roda::RodaPlugins::RenderEach)
::load_dependencies (Roda::RodaPlugins::NotAllowed)
::load_dependencies (Roda::RodaPlugins::ViewOptions)
::load_dependencies (Roda::RodaPlugins::BranchLocals)
-::load_dependencies (Roda::RodaPlugins::MultiRoute)
+::load_dependencies (Roda::RodaPlugins::PlaceholderStringMatchers)
::load_dependencies (Roda::RodaPlugins::AssetsPreloading)
-::load_dependencies (Roda::RodaPlugins::ContentFor)
::load_dependencies (Roda::RodaPlugins::AutoloadHashBranches)
+::load_dependencies (Roda::RodaPlugins::ContentFor)
::load_dependencies (Roda::RodaPlugins::MultiView)
::load_dependencies (Roda::RodaPlugins::MultibyteStringMatcher)
::load_dependencies (Roda::RodaPlugins::ExceptionPage)
::load_dependencies (Roda::RodaPlugins::CaptureERB)
-::load_dependencies (Roda::RodaPlugins::HashBranchViewSubdir)
+::load_dependencies (Roda::RodaPlugins::FilterCommonLogger)
::load_dependencies (Roda::RodaPlugins::Chunked)
::load_dependencies (Roda::RodaPlugins::Partials)
::load_dependencies (Roda::RodaPlugins::AutoloadNamedRoutes)
+::load_dependencies (Roda::RodaPlugins::HashBranchViewSubdir)
::load_dependencies (Roda::RodaPlugins::PadrinoRender)
-::load_dependencies (Roda::RodaPlugins::NotFound)
::load_dependencies (Roda::RodaPlugins::StaticRouting)
-::load_dependencies (Roda::RodaPlugins::RenderEach)
-::load_dependencies (Roda::RodaPlugins::ErbH)
+::load_dependencies (Roda::RodaPlugins::NotFound)
+::load_dependencies (Roda::RodaPlugins::RenderCoverage)
+::load_dependencies (Roda::RodaPlugins::RenderLocals)
::load_plugin (Roda::RodaPlugins)
::max_input_bytesize (Roda::RodaPlugins::TypecastParams::Params)
::nest (Roda::RodaPlugins::TypecastParams::Params)
-::new (Roda::RodaPlugins::Mailer::InstanceMethods)
::new (Roda::RodaPlugins::Flash::FlashHash)
::new (Roda::RodaPlugins::Chunked::Body)
-::new (Roda::RodaPlugins::Streaming::AsyncStream)
-::new (Roda::RodaPlugins::ClassLevelRouting::InstanceMethods)
::new (RodaSessionMiddleware::SessionHash)
-::new (RodaSessionMiddleware)
-::new (Roda::RodaPlugins::ResponseRequest::InstanceMethods)
+::new (Roda::RodaPlugins::ClassLevelRouting::InstanceMethods)
+::new (Roda::RodaPlugins::Streaming::AsyncStream)
::new (Roda::RodaPlugins::PathRewriter::RequestMethods)
-::new (Roda::RodaPlugins::Chunked::StreamBody)
-::new (Roda::RodaPlugins::Streaming::Stream)
+::new (Roda::RodaPlugins::ResponseRequest::InstanceMethods)
+::new (RodaSessionMiddleware)
::new (Roda::RodaPlugins::RequestHeaders::Headers)
+::new (Roda::RodaPlugins::Streaming::Stream)
+::new (Roda::RodaPlugins::Mailer::InstanceMethods)
::new (Roda::RodaPlugins::Base::InstanceMethods)
::new (Roda::RodaPlugins::ContentSecurityPolicy::Policy)
-::new (Roda::RodaPlugins::HashRoutes::DSL)
+::new (Roda::RodaPlugins::Chunked::StreamBody)
+::new (Roda::RodaPlugins::MiddlewareStack::Stack)
::new (Roda::RodaPlugins::DisallowFileUploads::RequestMethods)
+::new (Roda::RodaPlugins::HashRoutes::DSL)
::new (Roda::RodaPlugins::Render::TemplateMtimeWrapper)
-::new (Roda::RodaPlugins::MiddlewareStack::StackPosition)
::new (Roda::RodaPlugins::Base::ResponseMethods)
::new (Roda::RodaPlugins::Base::RequestMethods)
-::new (Roda::RodaPlugins::IndifferentParams::QueryParser::Params)
::new (Roda::RodaPlugins::ContentSecurityPolicy::ResponseMethods)
+::new (Roda::RodaPlugins::IndifferentParams::QueryParser::Params)
::new (Roda::RodaPlugins::RecheckPrecompiledAssets::CompiledAssetsHash)
::new (Roda::RodaPlugins::TypecastParams::Params)
+::new (Roda::RodaPlugins::MiddlewareStack::StackPosition)
::new (Roda::RodaPlugins::Head::CloseLater)
-::new (Roda::RodaPlugins::MiddlewareStack::Stack)
::new (Roda::RodaPlugins::Middleware::Forwarder)
::new (Roda::RodaCache)
::new (Roda::RodaPlugins::SinatraHelpers::DelayedBody)
@@ -181,28 +182,28 @@
::start_timer (Roda::RodaPlugins::CommonLogger)
::tilt_template_compiled_method (Roda::RodaPlugins::Render)
#<< (Roda::RodaPlugins::Streaming::Stream)
+#POST (Roda::RodaPlugins::InvalidRequestBody::RequestMethods)
#POST (Roda::RodaPlugins::JsonParser::RequestMethods)
#[] (RodaSessionMiddleware::SessionHash)
-#[] (Roda::RodaPlugins::RecheckPrecompiledAssets::CompiledAssetsHash)
-#[] (Roda::RodaCache)
#[] (Roda::RodaPlugins::RequestHeaders::Headers)
-#[] (Roda::RodaPlugins::TypecastParams::Params)
#[] (Roda::RodaPlugins::Base::ResponseMethods)
+#[] (Roda::RodaPlugins::TypecastParams::Params)
+#[] (Roda::RodaCache)
+#[] (Roda::RodaPlugins::RecheckPrecompiledAssets::CompiledAssetsHash)
#[]= (Roda::RodaPlugins::Flash::FlashHash)
#[]= (Roda::RodaPlugins::Base::ResponseMethods)
-#[]= (Roda::RodaPlugins::RecheckPrecompiledAssets::CompiledAssetsHash)
#[]= (RodaSessionMiddleware::SessionHash)
#[]= (Roda::RodaCache)
-#_match_hook (Roda::RodaPlugins::MatchHook::InstanceMethods)
+#[]= (Roda::RodaPlugins::RecheckPrecompiledAssets::CompiledAssetsHash)
#_match_hook_args (Roda::RodaPlugins::MatchHookArgs::InstanceMethods)
#_remaining_path (RodaSessionMiddleware::RequestMethods)
-#_roda_handle_main_route (Roda::RodaPlugins::ErrorHandler::InstanceMethods)
#_roda_handle_main_route (Roda::RodaPlugins::Base::InstanceMethods)
+#_roda_handle_main_route (Roda::RodaPlugins::ErrorHandler::InstanceMethods)
#_roda_handle_route (Roda::RodaPlugins::Base::InstanceMethods)
#_roda_main_route (Roda::RodaPlugins::Base::InstanceMethods)
-#_roda_run_main_route (Roda::RodaPlugins::BeforeHook::InstanceMethods)
-#_roda_run_main_route (Roda::RodaPlugins::Middleware::InstanceMethods)
#_roda_run_main_route (Roda::RodaPlugins::Base::InstanceMethods)
+#_roda_run_main_route (Roda::RodaPlugins::Middleware::InstanceMethods)
+#_roda_run_main_route (Roda::RodaPlugins::BeforeHook::InstanceMethods)
#_string_parse! (Roda::RodaPlugins::TypecastParams::DateParseInputHandler)
#add_file (Roda::RodaPlugins::Mailer::InstanceMethods)
#add_match_hook (Roda::RodaPlugins::MatchHookArgs::ClassMethods)
@@ -232,13 +233,13 @@
#build! (Roda::RodaPlugins::DelayBuild::ClassMethods)
#cache_control (Roda::RodaPlugins::Caching::ResponseMethods)
#cached_matcher (Roda::RodaPlugins::Base::RequestClassMethods)
-#call (Roda::RodaPlugins::Base::InstanceMethods)
#call (Roda::RodaPlugins::ErrorHandler::InstanceMethods)
#call (Roda::RodaPlugins::Base::ClassMethods)
-#call (Roda::RodaPlugins::DirectCall::ClassMethods)
-#call (Roda::RodaPlugins::BeforeHook::InstanceMethods)
#call (Roda::RodaPlugins::Middleware::Forwarder)
+#call (Roda::RodaPlugins::Base::InstanceMethods)
#call (Roda::RodaPlugins::Middleware::InstanceMethods)
+#call (Roda::RodaPlugins::BeforeHook::InstanceMethods)
+#call (Roda::RodaPlugins::DirectCall::ClassMethods)
#call (RodaSessionMiddleware)
#capture_erb (Roda::RodaPlugins::CaptureERB::InstanceMethods)
#check_csrf! (Roda::RodaPlugins::RouteCsrf::InstanceMethods)
@@ -266,19 +267,19 @@
#content_type (Roda::RodaPlugins::SinatraHelpers::ResponseMethods)
#convert! (Roda::RodaPlugins::TypecastParams::Params)
#convert_each! (Roda::RodaPlugins::TypecastParams::Params)
-#create_template (Roda::RodaPlugins::RenderCoverage::ClassMethods)
#create_template (Roda::RodaPlugins::Render::ClassMethods)
+#create_template (Roda::RodaPlugins::RenderCoverage::ClassMethods)
#csrf_field (Roda::RodaPlugins::RouteCsrf::InstanceMethods)
#csrf_field (Roda::RodaPlugins::Csrf::InstanceMethods)
-#csrf_header (Roda::RodaPlugins::Csrf::InstanceMethods)
#csrf_header (Roda::RodaPlugins::RouteCsrf::InstanceMethods)
-#csrf_metatag (Roda::RodaPlugins::Csrf::InstanceMethods)
+#csrf_header (Roda::RodaPlugins::Csrf::InstanceMethods)
#csrf_metatag (Roda::RodaPlugins::RouteCsrf::InstanceMethods)
+#csrf_metatag (Roda::RodaPlugins::Csrf::InstanceMethods)
#csrf_path (Roda::RodaPlugins::RouteCsrf::InstanceMethods)
#csrf_tag (Roda::RodaPlugins::RouteCsrf::InstanceMethods)
#csrf_tag (Roda::RodaPlugins::Csrf::InstanceMethods)
-#csrf_token (Roda::RodaPlugins::Csrf::InstanceMethods)
#csrf_token (Roda::RodaPlugins::RouteCsrf::InstanceMethods)
+#csrf_token (Roda::RodaPlugins::Csrf::InstanceMethods)
#custom_matcher (Roda::RodaPlugins::CustomMatchers::ClassMethods)
#default_headers (Roda::RodaPlugins::DefaultHeaders::ResponseMethods)
#default_headers (Roda::RodaPlugins::DefaultHeaders::ClassMethods)
@@ -294,19 +295,19 @@
#dig! (Roda::RodaPlugins::TypecastParams::Params)
#discard (Roda::RodaPlugins::Flash::FlashHash)
#dispatch_from (Roda::RodaPlugins::HashRoutes::DSL)
+#each (RodaSessionMiddleware::SessionHash)
+#each (Roda::RodaPlugins::Streaming::Stream)
+#each (Roda::RodaPlugins::Streaming::AsyncStream)
#each (Roda::RodaPlugins::Chunked::StreamBody)
-#each (Roda::RodaPlugins::Head::CloseLater)
-#each (Roda::RodaPlugins::RecheckPrecompiledAssets::CompiledAssetsHash)
#each (Roda::RodaPlugins::SinatraHelpers::DelayedBody)
-#each (Roda::RodaPlugins::Streaming::Stream)
-#each (RodaSessionMiddleware::SessionHash)
+#each (Roda::RodaPlugins::RecheckPrecompiledAssets::CompiledAssetsHash)
+#each (Roda::RodaPlugins::Head::CloseLater)
#each (Roda::RodaPlugins::Chunked::Body)
-#each (Roda::RodaPlugins::Streaming::AsyncStream)
#each_chunk (Roda::RodaPlugins::Chunked::InstanceMethods)
#each_partial (Roda::RodaPlugins::Partials::InstanceMethods)
#empty? (Roda::RodaPlugins::Base::ResponseMethods)
-#empty? (Roda::RodaPlugins::SinatraHelpers::DelayedBody)
#empty? (RodaSessionMiddleware::SessionHash)
+#empty? (Roda::RodaPlugins::SinatraHelpers::DelayedBody)
#env (Roda::RodaPlugins::Base::InstanceMethods)
#environment (Roda::RodaPlugins::Environments::ClassMethods)
#environment= (Roda::RodaPlugins::Environments::ClassMethods)
@@ -325,49 +326,48 @@
#expand_path (Roda::RodaPlugins::Base::ClassMethods)
#expand_path (Roda::RodaPlugins::StripPathPrefix::ClassMethods)
#expires (Roda::RodaPlugins::Caching::ResponseMethods)
-#fetch (Roda::RodaPlugins::TypecastParams::Params)
#fetch (RodaSessionMiddleware::SessionHash)
+#fetch (Roda::RodaPlugins::TypecastParams::Params)
+#finish (Roda::RodaPlugins::Base::ResponseMethods)
#finish (Roda::RodaPlugins::Mailer::ResponseMethods)
-#finish (Roda::RodaPlugins::Caching::ResponseMethods)
#finish (Roda::RodaPlugins::SinatraHelpers::ResponseMethods)
#finish (Roda::RodaPlugins::DropBody::ResponseMethods)
-#finish (Roda::RodaPlugins::Base::ResponseMethods)
#finish (Roda::RodaPlugins::DeleteEmptyHeaders::ResponseMethods)
-#finish_with_body (Roda::RodaPlugins::Base::ResponseMethods)
+#finish (Roda::RodaPlugins::Caching::ResponseMethods)
#finish_with_body (Roda::RodaPlugins::DeleteEmptyHeaders::ResponseMethods)
+#finish_with_body (Roda::RodaPlugins::Base::ResponseMethods)
#flash (Roda::RodaPlugins::Flash::InstanceMethods)
#flush (Roda::RodaPlugins::Chunked::InstanceMethods)
#forward_next (Roda::RodaPlugins::Middleware::RequestMethods)
-#freeze (Roda::RodaPlugins::AutoloadNamedRoutes::ClassMethods)
-#freeze (Roda::RodaPlugins::MultiRoute::ClassMethods)
-#freeze (Roda::RodaPlugins::PathRewriter::ClassMethods)
-#freeze (Roda::RodaPlugins::MailProcessor::ClassMethods)
-#freeze (Roda::RodaPlugins::CustomBlockResults::ClassMethods)
+#freeze (Roda::RodaPlugins::HashPaths::ClassMethods)
#freeze (Roda::RodaPlugins::StatusHandler::ClassMethods)
-#freeze (Roda::RodaCache)
-#freeze (Roda::RodaPlugins::TypecastParams::ClassMethods)
-#freeze (Roda::RodaPlugins::MultiRun::ClassMethods)
-#freeze (Roda::RodaPlugins::MatchHook::ClassMethods)
-#freeze (Roda::RodaPlugins::Hooks::ClassMethods)
#freeze (Roda::RodaPlugins::AutoloadHashBranches::ClassMethods)
+#freeze (Roda::RodaPlugins::CustomBlockResults::ClassMethods)
+#freeze (Roda::RodaPlugins::MultiRoute::ClassMethods)
+#freeze (Roda::RodaPlugins::AutoloadNamedRoutes::ClassMethods)
+#freeze (Roda::RodaPlugins::DefaultHeaders::ClassMethods)
+#freeze (Roda::RodaPlugins::MultiRun::ClassMethods)
+#freeze (Roda::RodaPlugins::Base::ClassMethods)
#freeze (Roda::RodaPlugins::Render::ClassMethods)
+#freeze (Roda::RodaPlugins::ClassLevelRouting::ClassMethods)
+#freeze (Roda::RodaPlugins::HashBranches::ClassMethods)
+#freeze (Roda::RodaPlugins::Path::ClassMethods)
+#freeze (Roda::RodaPlugins::Hooks::ClassMethods)
+#freeze (Roda::RodaPlugins::HashRoutes::ClassMethods)
#freeze (Roda::RodaPlugins::ContentSecurityPolicy::Policy)
-#freeze (Roda::RodaPlugins::Base::ClassMethods)
-#freeze (Roda::RodaPlugins::HashBranchViewSubdir::ClassMethods)
+#freeze (Roda::RodaCache)
#freeze (Roda::RodaPlugins::MatchHookArgs::ClassMethods)
-#freeze (Roda::RodaPlugins::HashRoutes::ClassMethods)
-#freeze (Roda::RodaPlugins::DefaultHeaders::ClassMethods)
#freeze (Roda::RodaPlugins::NamedRoutes::ClassMethods)
-#freeze (Roda::RodaPlugins::ClassLevelRouting::ClassMethods)
-#freeze (Roda::RodaPlugins::HashBranches::ClassMethods)
+#freeze (Roda::RodaPlugins::TypecastParams::ClassMethods)
#freeze (Roda::RodaPlugins::NamedTemplates::ClassMethods)
-#freeze (Roda::RodaPlugins::HashPaths::ClassMethods)
-#freeze (Roda::RodaPlugins::Path::ClassMethods)
+#freeze (Roda::RodaPlugins::MailProcessor::ClassMethods)
+#freeze (Roda::RodaPlugins::HashBranchViewSubdir::ClassMethods)
+#freeze (Roda::RodaPlugins::PathRewriter::ClassMethods)
#freeze_template_caches! (Roda::RodaPlugins::PrecompileTemplates::ClassMethods)
#get (Roda::RodaPlugins::Base::RequestMethods)
#h (Roda::RodaPlugins::H::InstanceMethods)
-#halt (Roda::RodaPlugins::Halt::RequestMethods)
#halt (Roda::RodaPlugins::Base::RequestMethods)
+#halt (Roda::RodaPlugins::Halt::RequestMethods)
#handle (Roda::RodaPlugins::MailProcessor::RequestMethods)
#handle_block_result (Roda::RodaPlugins::CustomBlockResults::ClassMethods)
#handle_chunk_error (Roda::RodaPlugins::Chunked::InstanceMethods)
@@ -376,8 +376,8 @@
#handle_stream_error (Roda::RodaPlugins::Streaming::InstanceMethods)
#handled_mail_hook (Roda::RodaPlugins::MailProcessor::InstanceMethods)
#has_key? (RodaSessionMiddleware::SessionHash)
-#hash_branch (Roda::RodaPlugins::HashBranchViewSubdir::ClassMethods)
#hash_branch (Roda::RodaPlugins::HashBranches::ClassMethods)
+#hash_branch (Roda::RodaPlugins::HashBranchViewSubdir::ClassMethods)
#hash_branches (Roda::RodaPlugins::HashBranches::RequestMethods)
#hash_matcher (Roda::RodaPlugins::HashMatcher::ClassMethods)
#hash_path (Roda::RodaPlugins::HashPaths::ClassMethods)
@@ -393,28 +393,28 @@
#include (Roda::RodaPlugins::Base::ClassMethods)
#include? (RodaSessionMiddleware::SessionHash)
#informational? (Roda::RodaPlugins::SinatraHelpers::ResponseMethods)
-#inherited (Roda::RodaPlugins::HashPaths::ClassMethods)
-#inherited (Roda::RodaPlugins::Render::ClassMethods)
#inherited (Roda::RodaPlugins::HashBranches::ClassMethods)
-#inherited (Roda::RodaPlugins::Base::ClassMethods)
#inherited (Roda::RodaPlugins::MultiRoute::ClassMethods)
-#inherited (Roda::RodaPlugins::HashBranchViewSubdir::ClassMethods)
+#inherited (Roda::RodaPlugins::Base::ClassMethods)
#inherited (Roda::RodaPlugins::TypecastParams::ClassMethods)
+#inherited (Roda::RodaPlugins::HashBranchViewSubdir::ClassMethods)
+#inherited (Roda::RodaPlugins::HashPaths::ClassMethods)
+#inherited (Roda::RodaPlugins::Render::ClassMethods)
#inherited (Roda::RodaPlugins::NamedRoutes::ClassMethods)
#inject_erb (Roda::RodaPlugins::InjectERB::InstanceMethods)
#inline_template_block (Roda::RodaPlugins::Render::ClassMethods)
-#inspect (Roda::RodaPlugins::Base::ResponseMethods)
-#inspect (RodaSessionMiddleware::SessionHash)
-#inspect (Roda::RodaPlugins::Base::ResponseClassMethods)
#inspect (Roda::RodaPlugins::Base::RequestClassMethods)
#inspect (Roda::RodaPlugins::Base::RequestMethods)
-#is (Roda::RodaPlugins::NotAllowed::RequestMethods)
+#inspect (Roda::RodaPlugins::Base::ResponseClassMethods)
+#inspect (RodaSessionMiddleware::SessionHash)
+#inspect (Roda::RodaPlugins::Base::ResponseMethods)
#is (Roda::RodaPlugins::HashRoutes::DSL)
-#is (Roda::RodaPlugins::OptimizedMatching::RequestMethods)
#is (Roda::RodaPlugins::Base::RequestMethods)
+#is (Roda::RodaPlugins::OptimizedMatching::RequestMethods)
+#is (Roda::RodaPlugins::NotAllowed::RequestMethods)
#is_exactly (Roda::RodaPlugins::OptimizedStringMatchers::RequestMethods)
-#is_get? (Roda::RodaPlugins::Head::RequestMethods)
#is_get? (Roda::RodaPlugins::Base::RequestMethods)
+#is_get? (Roda::RodaPlugins::Head::RequestMethods)
#is_segment (Roda::RodaPlugins::OptimizedSegmentMatchers::RequestMethods)
#join (Roda::RodaPlugins::SinatraHelpers::DelayedBody)
#json_result_classes (Roda::RodaPlugins::Json::ClassMethods)
@@ -426,8 +426,8 @@
#link_to (Roda::RodaPlugins::LinkTo::InstanceMethods)
#loaded? (RodaSessionMiddleware::SessionHash)
#mail (Roda::RodaPlugins::MailProcessor::InstanceMethods)
-#mail (Roda::RodaPlugins::Mailer::ClassMethods)
#mail (Roda::RodaPlugins::Mailer::RequestMethods)
+#mail (Roda::RodaPlugins::Mailer::ClassMethods)
#mail_attachments (Roda::RodaPlugins::Mailer::ResponseMethods)
#mail_recipients (Roda::RodaPlugins::MailProcessor::InstanceMethods)
#mail_text (Roda::RodaPlugins::MailProcessor::InstanceMethods)
@@ -460,12 +460,12 @@
#new (Roda::RodaPlugins::Middleware::ClassMethods)
#no_chunk! (Roda::RodaPlugins::Chunked::InstanceMethods)
#no_mail! (Roda::RodaPlugins::Mailer::InstanceMethods)
-#not_found (Roda::RodaPlugins::NotFound::ClassMethods)
#not_found (Roda::RodaPlugins::SinatraHelpers::RequestMethods)
+#not_found (Roda::RodaPlugins::NotFound::ClassMethods)
#not_found? (Roda::RodaPlugins::SinatraHelpers::ResponseMethods)
-#on (Roda::RodaPlugins::Base::RequestMethods)
#on (Roda::RodaPlugins::OptimizedMatching::RequestMethods)
#on (Roda::RodaPlugins::HashRoutes::DSL)
+#on (Roda::RodaPlugins::Base::RequestMethods)
#on_branch (Roda::RodaPlugins::OptimizedStringMatchers::RequestMethods)
#on_segment (Roda::RodaPlugins::OptimizedSegmentMatchers::RequestMethods)
#on_type (Roda::RodaPlugins::TypeRouting::RequestMethods)
@@ -473,14 +473,14 @@
#opts (Roda::RodaPlugins::Base::InstanceMethods)
#param_name (Roda::RodaPlugins::TypecastParams::Error)
#param_names (Roda::RodaPlugins::TypecastParams::Error)
-#params (Roda::RodaPlugins::IndifferentParams::InstanceMethods)
#params (Roda::RodaPlugins::ParamsCapturing::RequestMethods)
+#params (Roda::RodaPlugins::IndifferentParams::InstanceMethods)
#parse_nested_query (Roda::RodaPlugins::IndifferentParams::QueryParser)
#partial (Roda::RodaPlugins::Partials::InstanceMethods)
#pass (Roda::RodaPlugins::Pass::RequestMethods)
#path (Roda::RodaPlugins::Path::InstanceMethods)
-#path (Roda::RodaPlugins::Base::RequestMethods)
#path (Roda::RodaPlugins::Path::ClassMethods)
+#path (Roda::RodaPlugins::Base::RequestMethods)
#path_block (Roda::RodaPlugins::Path::ClassMethods)
#path_classes (Roda::RodaPlugins::Path::ClassMethods)
#persist_session (Roda::RodaPlugins::Sessions::RequestMethods)
@@ -507,8 +507,8 @@
#relative_path (Roda::RodaPlugins::RelativePath::InstanceMethods)
#relative_prefix (Roda::RodaPlugins::RelativePath::InstanceMethods)
#remove (Roda::RodaPlugins::MiddlewareStack::Stack)
-#render (Roda::RodaPlugins::Render::TemplateMtimeWrapper)
#render (Roda::RodaPlugins::PadrinoRender::InstanceMethods)
+#render (Roda::RodaPlugins::Render::TemplateMtimeWrapper)
#render (Roda::RodaPlugins::Render::InstanceMethods)
#render_asset (Roda::RodaPlugins::Assets::InstanceMethods)
#render_each (Roda::RodaPlugins::RenderEach::InstanceMethods)
@@ -525,27 +525,27 @@
#response_delegate (Roda::RodaPlugins::Delegate::ClassMethods)
#response_module (Roda::RodaPlugins::ModuleInclude::ClassMethods)
#rewrite_path (Roda::RodaPlugins::PathRewriter::ClassMethods)
-#roda_class (Roda::RodaPlugins::Base::ResponseMethods)
#roda_class (Roda::RodaPlugins::Base::RequestMethods)
+#roda_class (Roda::RodaPlugins::Base::ResponseMethods)
+#root (Roda::RodaPlugins::NotAllowed::RequestMethods)
#root (Roda::RodaPlugins::EmptyRoot::RequestMethods)
#root (Roda::RodaPlugins::Base::RequestMethods)
-#root (Roda::RodaPlugins::NotAllowed::RequestMethods)
#route (Roda::RodaPlugins::NamedRoutes::ClassMethods)
-#route (Roda::RodaPlugins::NamedRoutes::RequestMethods)
#route (Roda::RodaPlugins::Base::ClassMethods)
+#route (Roda::RodaPlugins::NamedRoutes::RequestMethods)
#route (Roda::RodaPlugins::MultiRoute::ClassMethods)
-#run (Roda::RodaPlugins::RunRequireSlash::RequestMethods)
-#run (Roda::RodaPlugins::RunAppendSlash::RequestMethods)
-#run (Roda::RodaPlugins::MultiRun::ClassMethods)
#run (Roda::RodaPlugins::Base::RequestMethods)
+#run (Roda::RodaPlugins::MultiRun::ClassMethods)
#run (Roda::RodaPlugins::RunHandler::RequestMethods)
+#run (Roda::RodaPlugins::RunAppendSlash::RequestMethods)
+#run (Roda::RodaPlugins::RunRequireSlash::RequestMethods)
#send_early_hints (Roda::RodaPlugins::EarlyHints::InstanceMethods)
#send_file (Roda::RodaPlugins::SinatraHelpers::RequestMethods)
#sendmail (Roda::RodaPlugins::Mailer::ClassMethods)
#server_error? (Roda::RodaPlugins::SinatraHelpers::ResponseMethods)
+#session (Roda::RodaPlugins::Base::RequestMethods)
#session (Roda::RodaPlugins::Sessions::RequestMethods)
#session (Roda::RodaPlugins::Base::InstanceMethods)
-#session (Roda::RodaPlugins::Base::RequestMethods)
#session_created_at (Roda::RodaPlugins::Sessions::RequestMethods)
#session_updated_at (Roda::RodaPlugins::Sessions::RequestMethods)
#set_cookie (Roda::RodaPlugins::Cookies::ResponseMethods)
@@ -587,8 +587,8 @@
#use_request_specific_csrf_tokens? (Roda::RodaPlugins::RouteCsrf::InstanceMethods)
#valid_csrf? (Roda::RodaPlugins::RouteCsrf::InstanceMethods)
#values (RodaSessionMiddleware::SessionHash)
-#view (Roda::RodaPlugins::Render::InstanceMethods)
#view (Roda::RodaPlugins::Chunked::InstanceMethods)
+#view (Roda::RodaPlugins::Render::InstanceMethods)
#view (Roda::RodaPlugins::HashRoutes::DSL)
#views (Roda::RodaPlugins::HashRoutes::DSL)
#write (Roda::RodaPlugins::Base::ResponseMethods)
The match_hook plugin adds hooks that are called upon a successful match by any of the matchers. The hooks do not take any arguments. If you would like hooks that pass the arguments/matchers and values yielded to the route block, use the match_hook_args plugin.
+The match_hook plugin adds hooks that are called upon a successful match by any of the matchers. The hooks do not take any arguments. If you would like hooks that pass the arguments/matchers and values yielded to the route block, use the match_hook_args plugin. This uses the match_hook_args plugin internally, but doesn’t pass the matchers and values yielded.
plugin :match_hook @@ -49,7 +49,7 @@module
Methods
Public Class
Public Class
Classes and Modules
Public Class methods
-# File lib/roda/plugins/match_hook.rb -17 def self.configure(app) -18 app.opts[:match_hooks] ||= [] -19 end+
# File lib/roda/plugins/match_hook.rb +18 def self.load_dependencies(app) +19 app.plugin :match_hook_args +20 end
module
Methods
Public Instance
Public Instance
Public Instance methods
-Freeze the array of hook methods when freezing the app
- -# File lib/roda/plugins/match_hook.rb -23 def freeze -24 opts[:match_hooks].freeze -25 super -26 end-
Public Instance methods
[show source]# File lib/roda/plugins/match_hook.rb -29 def match_hook(&block) -30 opts[:match_hooks] << define_roda_method("match_hook", 0, &block) -31 -32 if opts[:match_hooks].length == 1 -33 class_eval("alias _match_hook #{opts[:match_hooks].first}", __FILE__, __LINE__) -34 else -35 class_eval("def _match_hook; #{opts[:match_hooks].join(';')} end", __FILE__, __LINE__) -36 end -37 -38 public :_match_hook -39 -40 nil -41 end+24 def match_hook(&block) +25 meth = define_roda_method("match_hook", 0, &block) +26 add_match_hook{|_,_| send(meth)} +27 nil +28 end
CHANGELOG
3.72.0 (2023-09-12)¶ ↑
+-
+
Add invalid_request_body plugin for custom handling of invalid request bodies (jeremyevans)
+ -
+
Warn when defining method that expects 1 argument when block requires multiple arguments when :check_arity option is set to :warn (jeremyevans)
+ -
+
Implement the match_hooks plugin using the match_hook_args plugin (jeremyevans)
+
3.71.0 (2023-08-14)¶ ↑
-
Add match_hook_args plugin, similar to match_hooks but support matchers and block args as hook arguments (jeremyevans)
diff --git a/rdoc/files/doc/release_notes/3_72_0_txt.html b/rdoc/files/doc/release_notes/3_72_0_txt.html new file mode 100644 index 00000000..52a53c54 --- /dev/null +++ b/rdoc/files/doc/release_notes/3_72_0_txt.html @@ -0,0 +1,87 @@ + + + +3.72.0.txt + + + + + + +++ + + diff --git a/rdoc/classes/Roda/RodaPlugins/MatchHook/RequestMethods.html b/rdoc/files/lib/roda/plugins/invalid_request_body_rb.html similarity index 77% rename from rdoc/classes/Roda/RodaPlugins/MatchHook/RequestMethods.html rename to rdoc/files/lib/roda/plugins/invalid_request_body_rb.html index 40f279d6..4f0be9d7 100644 --- a/rdoc/classes/Roda/RodaPlugins/MatchHook/RequestMethods.html +++ b/rdoc/files/lib/roda/plugins/invalid_request_body_rb.html @@ -1,7 +1,7 @@ -++3.72.0.txt +
++doc/release_notes/3.72.0.txt +++Last Update: +2023-09-12 10:34:26 -0700 ++++ + +++++New Features¶ ↑
+-
+
An invalid_request_body plugin has been added for allowing custom handling of invalid request bodies.
+ +Roda
uses Rack’s request body parsing, and by default invalid request bodies can result in different exceptions based on how the body is invalid and which version of Rack is in use.If you want to treat an invalid request body as the submission of no parameters, you can use the :empty_hash argument when loading the plugin:
+ +plugin :invalid_request_body, :empty_hash +
+ +If you want to return a empty 400 (Bad Request) response if an invalid request body is submitted, you can use the :empty_400 argument when loading the plugin:
+ +plugin :invalid_request_body, :empty_400 +
+ +If you want to raise a Roda::RodaPlugins::InvalidRequestBody::Error exception if an invalid request body is submitted (which makes it easier to handle these exceptions when using the error_handler plugin), you can use the :raise argument when loading the plugin:
+ +plugin :invalid_request_body, :raise +
+ +For custom behavior, you can pass a block when loading the plugin The block is called with the exception Rack raised when parsing the body. The block will be used to define a method in the application’s RodaRequest class. It can either return a hash of parameters, or you can raise a different exception, or you can halt processing and return a response:
+ +plugin :invalid_request_body do |exception| + # To treat the exception raised as a submitted parameter + {body_error: exception} +end +
+
Other Improvements¶ ↑
+-
+
When using the check_arity: :warn
+Roda
option,Roda
now correctly warns when defining a method that expects a single argument when the provided block requires multiple arguments. -
+
The match_hooks plugin is now implemented using the match_hook_args plugin, simplifying the implementation. This change should be transparent unless you were reaching into the internals.
+
++ +Roda::RodaPlugins::MatchHook::RequestMethods +invalid_request_body.rb @@ -22,24 +22,23 @@ -+-module -Roda::RodaPlugins::MatchHook::RequestMethods +
invalid_request_body.rb
- ++lib/roda/plugins/invalid_request_body.rb +++Last Update: +2023-09-11 09:47:41 -0700 +-match_hook.rb
Last Update: -2023-08-07 13:25:44 -0700 +2023-08-14 09:50:32 -0700diff --git a/rdoc/files/lib/roda/version_rb.html b/rdoc/files/lib/roda/version_rb.html index 405d2f54..7dc4acec 100644 --- a/rdoc/files/lib/roda/version_rb.html +++ b/rdoc/files/lib/roda/version_rb.html @@ -31,7 +31,7 @@version.rb
Last Update: -2023-08-14 08:54:23 -0700 +2023-09-12 10:34:26 -0700 -
+