Sha256: 7111c60de4e06936fe1277dee8a64c342c3a5042d49e21da0dfff24292645191

Contents?: true

Size: 1.17 KB

Versions: 1

Compression:

Stored size: 1.17 KB

Contents

# frozen-string-literal: true

#
class Roda
  module RodaPlugins
    # The placeholder_string_matcher plugin exists for backwards compatibility
    # with previous versions of Roda that allowed placeholders inside strings
    # if they were prefixed by colons:
    #
    #   plugin :placeholder_string_matchers
    #
    #   route do |r|
    #     r.is("foo/:bar") |v|
    #       # matches foo/baz, yielding "baz"
    #       # does not match foo, foo/, or foo/baz/
    #     end
    #   end
    #
    # It is not recommended to use this in new applications, and it is encouraged
    # to use separate symbol or string class matchers instead:
    #
    #   r.is "foo", String
    #   r.is "foo", :bar 
    module PlaceholderStringMatchers
      def self.load_dependencies(app)
        app.plugin :_symbol_regexp_matchers
      end

      module RequestMethods
        def _match_string(str)
          if str.index(":")
            consume(self.class.cached_matcher(str){Regexp.escape(str).gsub(/:(\w+)/){|m| _match_symbol_regexp($1)}})
          else
            super
          end
        end
      end
    end

    register_plugin(:placeholder_string_matchers, PlaceholderStringMatchers)
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
roda-2.29.0 lib/roda/plugins/placeholder_string_matchers.rb