Class: ActionDispatch::Routing::RoutesProxy

Inherits:
Object
  • Object
show all
Includes:
UrlFor
Defined in:
lib/action_dispatch/routing/routes_proxy.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from UrlFor

#full_url_for, #route_for, #url_for

Methods included from PolymorphicRoutes

#polymorphic_path, #polymorphic_url

Constructor Details

#initialize(routes, scope, helpers, script_namer = nil) ⇒ RoutesProxy

Returns a new instance of RoutesProxy.



15
16
17
18
19
# File 'lib/action_dispatch/routing/routes_proxy.rb', line 15

def initialize(routes, scope, helpers, script_namer = nil)
  @routes, @scope = routes, scope
  @helpers = helpers
  @script_namer = script_namer
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object (private)



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/action_dispatch/routing/routes_proxy.rb', line 32

def method_missing(method, *args)
  if @helpers.respond_to?(method)
    options = args.extract_options!
    options = url_options.merge((options || {}).symbolize_keys)

    if @script_namer
      options[:script_name] = merge_script_names(
        options[:script_name],
        @script_namer.call(options)
      )
    end

    args << options
    @helpers.public_send(method, *args)
  else
    super
  end
end

Instance Attribute Details

#routesObject Also known as: _routes

Returns the value of attribute routes.



12
13
14
# File 'lib/action_dispatch/routing/routes_proxy.rb', line 12

def routes
  @routes
end

#scopeObject

Returns the value of attribute scope.



12
13
14
# File 'lib/action_dispatch/routing/routes_proxy.rb', line 12

def scope
  @scope
end

Instance Method Details

#url_optionsObject



21
22
23
24
25
# File 'lib/action_dispatch/routing/routes_proxy.rb', line 21

def url_options
  scope.send(:_with_routes, routes) do
    scope.url_options
  end
end