123456789_123456789_123456789_123456789_123456789_

Class: ActionDispatch::Routing::RoutesProxy

Do not use. This class is for internal use only.
Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Instance Chain:
Inherits: Object
Defined in: actionpack/lib/action_dispatch/routing/routes_proxy.rb

UrlFor - Attributes & Methods

Class Method Summary

Instance Attribute Summary

UrlFor - Included

Instance Method Summary

UrlFor - Included

#initialize,
#route_for

Allows calling direct or regular named route.

#url_for

Generate a URL based on the options provided, .default_url_options, and the routes defined in config/routes.rb.

#url_options

Hook overridden in controller to add request information with .default_url_options.

#_routes_context, #_with_routes, #full_url_for

PolymorphicRoutes - Included

#polymorphic_path

Returns the path component of a URL for the given record.

#polymorphic_url

Constructs a call to a named RESTful route for the given record and returns the resulting URL string.

#polymorphic_mapping, #polymorphic_path_for_action, #polymorphic_url_for_action

Constructor Details

.new(routes, scope, helpers, script_namer = nil) ⇒ RoutesProxy

[ GitHub ]

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

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) (private)

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/routing/routes_proxy.rb', line 30

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

Class Attribute Details

.default_url_options (rw)

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/routing/url_for.rb', line 97

class_attribute :default_url_options

.default_url_options?Boolean (rw)

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/routing/url_for.rb', line 97

class_attribute :default_url_options

Instance Attribute Details

#_routes (readonly)

Alias for #routes.

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/routing/routes_proxy.rb', line 11

alias :_routes :routes

#default_url_options (rw)

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/routing/url_for.rb', line 97

class_attribute :default_url_options

#default_url_options?Boolean (rw)

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/routing/url_for.rb', line 97

class_attribute :default_url_options

#routes (rw) Also known as: #_routes

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/routing/routes_proxy.rb', line 10

attr_accessor :scope, :routes

#scope (rw)

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/routing/routes_proxy.rb', line 10

attr_accessor :scope, :routes

Instance Method Details

#merge_script_names(previous_script_name, new_script_name) (private)

Keeps the part of the script name provided by the global context via ENV, which mount doesn’t know about since it depends on the specific request, but use our script name resolver for the mount point dependent part.

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/routing/routes_proxy.rb', line 53

def merge_script_names(previous_script_name, new_script_name)
  return new_script_name unless previous_script_name

  resolved_parts = new_script_name.count("/")
  previous_parts = previous_script_name.count("/")
  context_parts = previous_parts - resolved_parts + 1

  (previous_script_name.split("/").slice(0, context_parts).join("/")) + new_script_name
end

#respond_to_missing?(method, _) ⇒ Boolean (private)

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/routing/routes_proxy.rb', line 26

def respond_to_missing?(method, _)
  super || @helpers.respond_to?(method)
end

#url_options

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/routing/routes_proxy.rb', line 19

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