Sha256: 07f1bc3df998d2401b71061c2fc0e6b94f7737faa26ef6bf6e69164a467d3b48

Contents?: true

Size: 1.36 KB

Versions: 6

Compression:

Stored size: 1.36 KB

Contents

require 'action_dispatch/routing/mapper'
require 'action_dispatch/routing/route_set'

# make recognize_path pass the given environment through

module ActionDispatch
  module Routing
    class RouteSet
      def recognize_path(path, environment = {})
        method = (environment[:method] || "GET").to_s.upcase
        path = Rack::Mount::Utils.normalize_path(path)

        begin
          # env = Rack::MockRequest.env_for(path, {:method => method})
          env = Rack::MockRequest.env_for(path, {:method => method}).merge(environment)
        rescue URI::InvalidURIError => e
          raise ActionController::RoutingError, e.message
        end

        req = Rack::Request.new(env)
        @set.recognize(req) do |route, matches, params|
          params.each do |key, value|
            if value.is_a?(String)
              value = value.dup.force_encoding(Encoding::BINARY) if value.encoding_aware?
              params[key] = URI.unescape(value)
            end
          end

          dispatcher = route.app
          dispatcher = dispatcher.app while dispatcher.is_a?(Mapper::Constraints)

          if dispatcher.is_a?(Dispatcher) && dispatcher.controller(params, false)
            dispatcher.prepare_params!(params)
            return params
          end
        end

        raise ActionController::RoutingError, "No route matches #{path.inspect}"
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
adva-core-0.0.9 lib/patches/rails/recognize_path_env.rb
adva-core-0.0.8 lib/patches/rails/recognize_path_env.rb
adva-core-0.0.7 lib/patches/rails/recognize_path_env.rb
adva-core-0.0.6 lib/patches/rails/recognize_path_env.rb
adva-core-0.0.5 lib/patches/rails/recognize_path_env.rb
adva-core-0.0.4 lib/patches/rails/recognize_path_env.rb