lib/roda.rb in roda-2.28.0 vs lib/roda.rb in roda-2.29.0
- old
+ new
@@ -63,13 +63,23 @@
@route_block = nil
# Module in which all Roda plugins should be stored. Also contains logic for
# registering and loading plugins.
module RodaPlugins
+ OPTS = {}.freeze
+ EMPTY_ARRAY = [].freeze
+
# Stores registered plugins
@plugins = RodaCache.new
+ class << self
+ # Make warn a public method, as it is used for deprecation warnings.
+ # Roda::RodaPlugins.warn can be overridden for custom handling of
+ # deprecation warnings.
+ public :warn
+ end
+
# If the registered plugin already exists, use it. Otherwise,
# require it and return it. This raises a LoadError if such a
# plugin doesn't exist, or a RodaError if it exists but it does
# not register itself correctly.
def self.load_plugin(name)
@@ -738,11 +748,20 @@
# 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(":") && placeholder_string_matcher?
- consume(self.class.cached_matcher(str){Regexp.escape(str).gsub(/:(\w+)/){|m| _match_symbol_regexp($1)}})
+ # RODA3: Remove
+ not_warned = true
+ consume(self.class.cached_matcher(str){Regexp.escape(str).gsub(/:(\w+)/) do |m|
+ match = $1
+ if not_warned
+ nor_warned = false
+ RodaPlugins.warn("Placeholder symbol matchers are deprecated by default and will be removed in Roda 3 (matcher used: #{str.inspect}). Use the placeholder_symbol_matchers plugin or split the string and use separate symbol matchers or String class matchers for the placeholders")
+ end
+ _match_symbol_regexp(match)
+ end})
else
rp = @remaining_path
if rp.start_with?("/#{str}")
last = str.length + 1
case rp[last]
@@ -750,10 +769,11 @@
@remaining_path = rp[last, rp.length]
when nil
@remaining_path = ""
when Integer
# :nocov:
+ # RODA3: Remove
# Ruby 1.8 support
if rp[last].chr == "/"
@remaining_path = rp[last, rp.length]
end
# :nocov:
@@ -779,12 +799,11 @@
end
# Match any nonempty segment. This should be called without an argument.
alias _match_class_String _match_symbol
- # The regular expression to use for matching symbols. By default, any non-empty
- # segment matches.
+ # RODA3: Remove
def _match_symbol_regexp(s)
"([^\\/]+)"
end
# The base remaining path to use.
@@ -819,10 +838,12 @@
when nil, false
# nothing
else
if roda_class.opts[:unsupported_block_result] == :raise
raise RodaError, "unsupported block result: #{result.inspect}"
+ else
+ RodaPlugins.warn("Unsupported match block return result: #{result.inspect}. This is currently ignored, but will raise an error in Roda 3. Have the block return nil or false to ignore the result.")
end
end
end
# Attempts to match the pattern to the current path. If there is no
@@ -931,9 +952,10 @@
# Handle an unsupported matcher.
def unsupported_matcher(matcher)
if roda_class.opts[:unsupported_matcher] == :raise
raise RodaError, "unsupported matcher: #{matcher.inspect}"
end
+ RodaPlugins.warn("Unsupported matcher used: #{matcher.inspect}. This currently always matches, but will raise an error in Roda 3. Switch to using true if you want the matcher to always match.")
matcher
end
end
# Class methods for RodaResponse