123456789_123456789_123456789_123456789_123456789_

Class: ActionDispatch::Journey::Routes

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/journey/routes.rb

Overview

The Routing table. Contains all routes for a system. Routes can be added to the table by calling #add_route.

Class Method Summary

Instance Attribute Summary

::Enumerable - Included

#many?

Returns true if the enumerable has more than 1 element.

Instance Method Summary

::Enumerable - Included

#compact_blank

Returns a new ::Array without the blank items.

#exclude?

The negative of the Enumerable#include?.

#excluding

Returns a copy of the enumerable excluding the specified elements.

#in_order_of

Returns a new ::Array where the order has been set to that provided in the series, based on the key of the objects in the original enumerable.

#including

Returns a new array that includes the passed elements.

#index_by

Convert an enumerable to a hash, using the block result as the key and the element as the value.

#index_with

Convert an enumerable to a hash, using the element as the key and the block result as the value.

#maximum

Calculates the maximum from the extracted elements.

#minimum

Calculates the minimum from the extracted elements.

#pick

Extract the given key from the first element in the enumerable.

#pluck

Extract the given key from each element in the enumerable.

#sole

Returns the sole item in the enumerable.

#without
#as_json

::ActiveSupport::EnumerableCoreExt::Constants - Included

Constructor Details

.new(routes = []) ⇒ Routes

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/journey/routes.rb', line 14

def initialize(routes = [])
  @routes             = routes
  @ast                = nil
  @anchored_routes    = []
  @custom_routes      = []
  @simulator          = nil
end

Instance Attribute Details

#anchored_routes (readonly)

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/journey/routes.rb', line 12

attr_reader :routes, :custom_routes, :anchored_routes

#custom_routes (readonly)

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/journey/routes.rb', line 12

attr_reader :routes, :custom_routes, :anchored_routes

#empty?Boolean (readonly)

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/journey/routes.rb', line 22

def empty?
  routes.empty?
end

#routes (readonly)

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/journey/routes.rb', line 12

attr_reader :routes, :custom_routes, :anchored_routes

Instance Method Details

#add_route(name, mapping)

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/journey/routes.rb', line 67

def add_route(name, mapping)
  route = mapping.make_route name, routes.length
  routes << route
  partition_route(route)
  clear_cache!
  route
end

#ast

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/journey/routes.rb', line 53

def ast
  @ast ||= begin
    nodes = anchored_routes.map(&:ast)
    Nodes::Or.new(nodes)
  end
end

#clear

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/journey/routes.rb', line 39

def clear
  routes.clear
  anchored_routes.clear
  custom_routes.clear
end

#clear_cache! (private)

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/journey/routes.rb', line 76

def clear_cache!
  @ast                = nil
  @simulator          = nil
end

#each(&block)

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/journey/routes.rb', line 35

def each(&block)
  routes.each(&block)
end

#last

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/journey/routes.rb', line 31

def last
  routes.last
end

#length Also known as: #size

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/journey/routes.rb', line 26

def length
  routes.length
end

#partition_route(route)

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/journey/routes.rb', line 45

def partition_route(route)
  if route.path.anchored && route.path.requirements_anchored?
    anchored_routes << route
  else
    custom_routes << route
  end
end

#simulator

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/journey/routes.rb', line 60

def simulator
  @simulator ||= begin
    gtg = GTG::Builder.new(ast).transition_table
    GTG::Simulator.new(gtg)
  end
end

#size

Alias for #length.

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/journey/routes.rb', line 29

alias :size :length