class ActionDispatch::Routing::RouteSet::Generator

Experimental RBS support (using type sampling data from the type_fusion project).

# sig/action_dispatch/routing/route_set.rbs

class ActionDispatch::Routing::RouteSet::Generator
  def controller: () -> String
  def generate: () -> ActionDispatch::Journey::Formatter::RouteWithParams
  def normalize_controller_action_id!: () -> nil
  def use_relative_controller!: () -> nil
end

def controller

Experimental RBS support (using type sampling data from the type_fusion project).

def controller: () -> String

This signature was generated using 1 sample from 1 application.

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

Experimental RBS support (using type sampling data from the type_fusion project).

def generate: () -> ActionDispatch::Journey::Formatter::RouteWithParams

This signature was generated using 1 sample from 1 application.

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!

Experimental RBS support (using type sampling data from the type_fusion project).

def normalize_controller_action_id!: () -> nil

This signature was generated using 1 sample from 1 application.

more keys from the recall.
:controller, :action or :id is not found, don't pull any
or if the key in the options is identical. If any of
The recall key is only used if there is no key in the options
This pulls :controller, :action, and :id out of the recall.
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!

Experimental RBS support (using type sampling data from the type_fusion project).

def use_relative_controller!: () -> nil

This signature was generated using 2 samples from 1 application.

is specified, the controller becomes "foo/baz/bat"
if the current controller is "foo/bar/baz" and controller: "baz/bat"
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