Sha256: 81e91ab7443cfd6afcd3827e1719d2fa1aabd0fa216d8787a4b39fec5fd8c657

Contents?: true

Size: 1.19 KB

Versions: 53

Compression:

Stored size: 1.19 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 string class or symbol 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
        private

        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

53 entries across 53 versions & 1 rubygems

Version Path
roda-3.84.0 lib/roda/plugins/placeholder_string_matchers.rb
roda-3.83.0 lib/roda/plugins/placeholder_string_matchers.rb
roda-3.82.0 lib/roda/plugins/placeholder_string_matchers.rb
roda-3.81.0 lib/roda/plugins/placeholder_string_matchers.rb
roda-3.79.0 lib/roda/plugins/placeholder_string_matchers.rb
roda-3.78.0 lib/roda/plugins/placeholder_string_matchers.rb
roda-3.77.0 lib/roda/plugins/placeholder_string_matchers.rb
roda-3.76.0 lib/roda/plugins/placeholder_string_matchers.rb
roda-3.75.0 lib/roda/plugins/placeholder_string_matchers.rb
roda-3.74.0 lib/roda/plugins/placeholder_string_matchers.rb
roda-3.73.0 lib/roda/plugins/placeholder_string_matchers.rb
roda-3.72.0 lib/roda/plugins/placeholder_string_matchers.rb
roda-3.71.0 lib/roda/plugins/placeholder_string_matchers.rb
roda-3.70.0 lib/roda/plugins/placeholder_string_matchers.rb
roda-3.69.0 lib/roda/plugins/placeholder_string_matchers.rb
roda-3.68.0 lib/roda/plugins/placeholder_string_matchers.rb
roda-3.67.0 lib/roda/plugins/placeholder_string_matchers.rb
roda-3.66.0 lib/roda/plugins/placeholder_string_matchers.rb
roda-3.65.0 lib/roda/plugins/placeholder_string_matchers.rb
roda-3.64.0 lib/roda/plugins/placeholder_string_matchers.rb