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:
parent
e35c2043b1
commit
b1c66f060b
3 changed files with 36 additions and 32 deletions
|
@ -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'
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
35
actionpack/lib/action_dispatch/routing/routes_proxy.rb
Normal file
35
actionpack/lib/action_dispatch/routing/routes_proxy.rb
Normal 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
|
Loading…
Reference in a new issue