1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Move RoutesProxy to separate file

This commit is contained in:
Piotr Sarnacki 2010-08-25 13:41:56 +02:00
parent e35c2043b1
commit b1c66f060b
3 changed files with 36 additions and 32 deletions

View file

@ -268,6 +268,7 @@ module ActionDispatch
autoload :Mapper, 'action_dispatch/routing/mapper'
autoload :Route, 'action_dispatch/routing/route'
autoload :RouteSet, 'action_dispatch/routing/route_set'
autoload :RoutesProxy, 'action_dispatch/routing/routes_proxy'
autoload :UrlFor, 'action_dispatch/routing/url_for'
autoload :PolymorphicRoutes, 'action_dispatch/routing/polymorphic_routes'

View file

@ -261,38 +261,6 @@ module ActionDispatch
named_routes.install(destinations, regenerate_code)
end
class RoutesProxy
include ActionDispatch::Routing::UrlFor
attr_accessor :scope, :routes
alias :_routes :routes
def initialize(routes, scope)
@routes, @scope = routes, scope
end
def url_options
scope.send(:_with_routes, routes) do
scope.url_options
end
end
def method_missing(method, *args)
if routes.url_helpers.respond_to?(method)
self.class.class_eval <<-RUBY, __FILE__, __LINE__ + 1
def #{method}(*args)
options = args.extract_options!
args << url_options.merge((options || {}).symbolize_keys)
routes.url_helpers.#{method}(*args)
end
RUBY
send(method, *args)
else
super
end
end
end
module MountedHelpers
end

View file

@ -0,0 +1,35 @@
module ActionDispatch
module Routing
class RoutesProxy #:nodoc:
include ActionDispatch::Routing::UrlFor
attr_accessor :scope, :routes
alias :_routes :routes
def initialize(routes, scope)
@routes, @scope = routes, scope
end
def url_options
scope.send(:_with_routes, routes) do
scope.url_options
end
end
def method_missing(method, *args)
if routes.url_helpers.respond_to?(method)
self.class.class_eval <<-RUBY, __FILE__, __LINE__ + 1
def #{method}(*args)
options = args.extract_options!
args << url_options.merge((options || {}).symbolize_keys)
routes.url_helpers.#{method}(*args)
end
RUBY
send(method, *args)
else
super
end
end
end
end
end