mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
03d3f036a7
This was almost every case where we are overriding `respond_to?` in a way that mirrors a parallel implementation of `method_missing`. There is one remaining case in Active Model that should probably do the same thing, but had a sufficiently strange implementation that I want to investigate it separately. Fixes #26333.
42 lines
1 KiB
Ruby
42 lines
1 KiB
Ruby
require "active_support/core_ext/array/extract_options"
|
|
|
|
module ActionDispatch
|
|
module Routing
|
|
class RoutesProxy #:nodoc:
|
|
include ActionDispatch::Routing::UrlFor
|
|
|
|
attr_accessor :scope, :routes
|
|
alias :_routes :routes
|
|
|
|
def initialize(routes, scope, helpers)
|
|
@routes, @scope = routes, scope
|
|
@helpers = helpers
|
|
end
|
|
|
|
def url_options
|
|
scope.send(:_with_routes, routes) do
|
|
scope.url_options
|
|
end
|
|
end
|
|
|
|
def respond_to_missing?(method, include_private = false)
|
|
super || @helpers.respond_to?(method)
|
|
end
|
|
|
|
def method_missing(method, *args)
|
|
if @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)
|
|
@helpers.#{method}(*args)
|
|
end
|
|
RUBY
|
|
send(method, *args)
|
|
else
|
|
super
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|