Sha256: b47c1cf17999ab349bb75c0811834bf739f8b42bd9a32512ae8e10ebe33085a2

Contents?: true

Size: 843 Bytes

Versions: 1

Compression:

Stored size: 843 Bytes

Contents

ActionDispatch::Journey::Routes.class_eval do
  def filters
    @filters || RoutingFilter::Chain.new.tap { |f| @filters = f unless frozen? }
  end
end

ActionDispatch::Journey::Router.class_eval do
  def find_routes_with_filtering(env)
    path = env.is_a?(Hash) ? env['PATH_INFO'] : env.path_info
    filter_parameters = {}
    original_path = path.dup

    @routes.filters.run(:around_recognize, path, env) do
      filter_parameters
    end

    find_routes_without_filtering(env).map do |match, parameters, route|
      [ match, parameters.merge(filter_parameters), route ]
    end.tap do |match, parameters, route|
      # restore the original path
      if env.is_a?(Hash)
        env['PATH_INFO'] = original_path
      else
        env.path_info = original_path
      end
    end
  end
  alias_method_chain :find_routes, :filtering
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
routing-filter-0.5.1 lib/routing_filter/adapters/routers/journey.rb