lib/roda.rb in roda-2.21.0 vs lib/roda.rb in roda-2.22.0
- old
+ new
@@ -681,11 +681,11 @@
# Match the given string to the request path. Regexp escapes the
# string so that regexp metacharacters are not matched, and recognizes
# colon tokens for placeholders.
def _match_string(str)
- if str.index(COLON)
+ if str.index(COLON) && placeholder_string_matcher?
consume(self.class.cached_matcher(str){Regexp.escape(str).gsub(/:(\w+)/){|m| _match_symbol_regexp($1)}})
else
rp = @remaining_path
if rp.start_with?("/#{str}")
last = str.length + 1
@@ -748,16 +748,23 @@
def always
block_result(yield)
throw :halt, response.finish
end
- # The body to use for the response if the response does not return
+ # The body to use for the response if the response does not already have
# a body. By default, a String is returned directly, and nil is
# returned otherwise.
def block_result_body(result)
- if result.is_a?(String)
+ case result
+ when String
result
+ when nil, false
+ # nothing
+ else
+ if roda_class.opts[:unsupported_block_result] == :raise
+ raise RodaError, "unsupported block result: #{result.inspect}"
+ end
end
end
# Attempts to match the pattern to the current path. If there is no
# match, returns false without changes. Otherwise, modifies
@@ -828,11 +835,16 @@
_match_hash(matcher)
when Array
_match_array(matcher)
when Proc
matcher.call
+ when true, false, nil
+ matcher
else
+ if roda_class.opts[:unsupported_matcher] == :raise
+ raise RodaError, "unsupported matcher: #{matcher.inspect}"
+ end
matcher
end
end
# Match only if all of the arguments in the given array match.
@@ -847,10 +859,16 @@
type.any?{|t| match_method(t)}
else
type.to_s.upcase == @env[REQUEST_METHOD]
end
end
+
+ # Whether string matchers are used verbatim, without handling
+ # placeholders via colons.
+ def placeholder_string_matcher?
+ !roda_class.opts[:verbatim_string_matcher]
+ end
end
# Class methods for RodaResponse
module ResponseClassMethods
# Reference to the Roda class related to this response class.
@@ -974,9 +992,10 @@
# response.redirect('foo', 301)
# response.redirect('bar')
def redirect(path, status = 302)
@headers[LOCATION] = path
@status = status
+ nil
end
# Return the Roda class related to this response.
def roda_class
self.class.roda_class