class ActionDispatch::Routing::RouteSet::Generator

def controller

def controller
  @options[:controller]
end

def current_controller

def current_controller
  @recall[:controller]
end

def different_controller?

def different_controller?
  return false unless current_controller
  controller.to_param != current_controller.to_param
end

def generate

MissingRoute will raise ActionController::UrlGenerationError.
Generates a path from routes, returns a RouteWithParams or MissingRoute.
def generate
  @set.formatter.generate(named_route, options, recall)
end

def initialize(named_route, options, recall, set)

def initialize(named_route, options, recall, set)
  @named_route = named_route
  @options     = options
  @recall      = recall
  @set         = set
  normalize_options!
  normalize_controller_action_id!
  use_relative_controller!
  normalize_controller!
end

def named_route_exists?

def named_route_exists?
  named_route && set.named_routes[named_route]
end

def normalize_controller!

Remove leading slashes from controllers
def normalize_controller!
  if controller
    if controller.start_with?("/")
      @options[:controller] = controller[1..-1]
    else
      @options[:controller] = controller
    end
  end
end

def normalize_controller_action_id!

more keys from the recall.
identical. If any of :controller, :action or :id is not found, don't pull any
only used if there is no key in the options or if the key in the options is
This pulls :controller, :action, and :id out of the recall. The recall key is
def normalize_controller_action_id!
  use_recall_for(:controller) || return
  use_recall_for(:action) || return
  use_recall_for(:id)
end

def normalize_options!

def normalize_options!
  # If an explicit :controller was given, always make :action explicit too, so
  # that action expiry works as expected for things like
  #
  #     generate({controller: 'content'}, {controller: 'content', action: 'show'})
  #
  # (the above is from the unit tests). In the above case, because the controller
  # was explicitly given, but no action, the action is implied to be "index", not
  # the recalled action of "show".
  if options[:controller]
    options[:action]     ||= "index"
    options[:controller]   = options[:controller].to_s
  end
  if options.key?(:action)
    options[:action] = (options[:action] || "index").to_s
  end
end

def segment_keys

def segment_keys
  set.named_routes[named_route].segment_keys
end

def use_recall_for(key)

def use_recall_for(key)
  if @recall[key] && (!@options.key?(key) || @options[key] == @recall[key])
    if !named_route_exists? || segment_keys.include?(key)
      @options[key] = @recall[key]
    end
  end
end

def use_relative_controller!

specified, the controller becomes "foo/baz/bat"
if the current controller is "foo/bar/baz" and controller: "baz/bat" is
def use_relative_controller!
  if !named_route && different_controller? && !controller.start_with?("/")
    old_parts = current_controller.split("/")
    size = controller.count("/") + 1
    parts = old_parts[0...-size] << controller
    @options[:controller] = parts.join("/")
  end
end