Sha256: d3ccfecb6e81014d08fed07f1a1b16d82a5c4aa75cb437b3e4835a4645507307

Contents?: true

Size: 1.17 KB

Versions: 33

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 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
        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

33 entries across 33 versions & 1 rubygems

Version Path
roda-3.31.0 lib/roda/plugins/placeholder_string_matchers.rb
roda-3.30.0 lib/roda/plugins/placeholder_string_matchers.rb
roda-3.29.0 lib/roda/plugins/placeholder_string_matchers.rb
roda-3.28.0 lib/roda/plugins/placeholder_string_matchers.rb
roda-3.27.0 lib/roda/plugins/placeholder_string_matchers.rb
roda-3.26.0 lib/roda/plugins/placeholder_string_matchers.rb
roda-3.25.0 lib/roda/plugins/placeholder_string_matchers.rb
roda-3.24.0 lib/roda/plugins/placeholder_string_matchers.rb
roda-3.23.0 lib/roda/plugins/placeholder_string_matchers.rb
roda-3.22.0 lib/roda/plugins/placeholder_string_matchers.rb
roda-3.21.0 lib/roda/plugins/placeholder_string_matchers.rb
roda-3.20.0 lib/roda/plugins/placeholder_string_matchers.rb
roda-3.19.0 lib/roda/plugins/placeholder_string_matchers.rb
roda-3.18.0 lib/roda/plugins/placeholder_string_matchers.rb
roda-3.17.0 lib/roda/plugins/placeholder_string_matchers.rb
roda-3.16.0 lib/roda/plugins/placeholder_string_matchers.rb
roda-3.15.0 lib/roda/plugins/placeholder_string_matchers.rb
roda-3.14.1 lib/roda/plugins/placeholder_string_matchers.rb
roda-3.14.0 lib/roda/plugins/placeholder_string_matchers.rb
roda-3.13.0 lib/roda/plugins/placeholder_string_matchers.rb