1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/actionpack/lib/action_dispatch/routing/routes_proxy.rb

43 lines
1 KiB
Ruby
Raw Normal View History

require 'active_support/core_ext/array/extract_options'
2010-08-25 07:41:56 -04:00
module ActionDispatch
module Routing
class RoutesProxy #:nodoc:
include ActionDispatch::Routing::UrlFor
attr_accessor :scope, :routes
alias :_routes :routes
2015-02-19 18:11:08 -05:00
def initialize(routes, scope, helpers)
2010-08-25 07:41:56 -04:00
@routes, @scope = routes, scope
2015-02-19 18:11:08 -05:00
@helpers = helpers
2010-08-25 07:41:56 -04:00
end
def url_options
scope.send(:_with_routes, routes) do
scope.url_options
end
end
def respond_to?(method, include_private = false)
super || @helpers.respond_to?(method)
end
2010-08-25 07:41:56 -04:00
def method_missing(method, *args)
if @helpers.respond_to?(method)
2010-08-25 07:41:56 -04:00
self.class.class_eval <<-RUBY, __FILE__, __LINE__ + 1
def #{method}(*args)
options = args.extract_options!
args << url_options.merge((options || {}).symbolize_keys)
@helpers.#{method}(*args)
2010-08-25 07:41:56 -04:00
end
RUBY
send(method, *args)
else
super
end
end
end
end
end