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 initialize: (String named_route, Hash options, Hash recall, ActionDispatch::Routing::RouteSet set) -> void
  def named_route_exists?: () -> ActionDispatch::Journey::Route
  def normalize_controller!: () -> String
  def normalize_controller_action_id!: () -> nil
  def normalize_options!: () -> String
  def segment_keys: () -> Array[Symbol]
  def use_recall_for: (Symbol key) -> 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 166 samples 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 46 samples 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)

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

type ActionDispatch__Routing__RouteSet__Generator_initialize_options = controller | String | action | String | gem | String | version | String | class | String | controller | String | action | String | gem | String | version | String | module | ModuleDefinition | controller | String | action | String | gem | String | version | String | controller | String | action | String | gem | String | version | Gem::Version | controller | String | action | String | gem | String | version | String | class | String | name | String | controller | String | action | String | gem | String | version | String | guide | String | controller | String | action | String | gem | String | version | String | file | String | id | String | controller | String | action | String | gem | String | version | String | controller | String | action | String | gem | String | version | String | id | ModuleDefinition | controller | String | action | String | gem | String | version | String | id | String | controller | String | action | String | gem | String | version | String | class_id | String | id | String
type ActionDispatch__Routing__RouteSet__Generator_initialize_recall =  | controller | String | action | String | gem | String | version | String | controller | String | action | String | controller | String | action | String | gem | String | version | String | class | String | name | String | controller | String | action | String | gem | String | version | String | file | String | controller | String | action | String | gem | String | version | String | guide | String | format | String | controller | String | action | String | gem | String | version | String | id | String | controller | String | action | String | gem | String | version | String | class_id | String | id | String | id | String | controller | String | action | String | gem | String | version | String | controller | String | action | String | gem | String | version | String | id | String | format | String

def initialize: (String named_route, ActionDispatch__Routing__RouteSet__Generator_initialize_options options, ActionDispatch__Routing__RouteSet__Generator_initialize_recall recall, ActionDispatch::Routing::RouteSet set) -> void

This signature was generated using 59 samples from 1 application.

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?

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

def named_route_exists?: () -> ActionDispatch::Journey::Route

This signature was generated using 26 samples from 1 application.

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

def normalize_controller!

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

def normalize_controller!: () -> String

This signature was generated using 61 samples from 1 application.

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 49 samples 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!

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

def normalize_options!: () -> String

This signature was generated using 58 samples from 1 application.

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

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

def segment_keys: () -> Symbol | Symbol

This signature was generated using 24 samples from 1 application.

def segment_keys
  set.named_routes[named_route].segment_keys
end

def use_recall_for(key)

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

def use_recall_for: (Symbol key) -> nil

This signature was generated using 57 samples from 1 application.

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 55 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