Class: ActionDispatch::Routing::RouteSet::NamedRouteCollection

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
actionpack/lib/action_dispatch/routing/route_set.rb

Overview

A NamedRouteCollection instance is a collection of named routes, and also maintains an anonymous module that can be used to install helpers for the named routes.

Defined Under Namespace

Classes: UrlHelper

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Enumerable

#as_json, #exclude?, #index_by, #many?, #sum

Constructor Details

#initializeNamedRouteCollection

Returns a new instance of NamedRouteCollection.


105
106
107
108
109
# File 'actionpack/lib/action_dispatch/routing/route_set.rb', line 105

def initialize
  @routes  = {}
  @helpers = []
  @module  = Module.new
end

Instance Attribute Details

#helpersObject (readonly)

Returns the value of attribute helpers


103
104
105
# File 'actionpack/lib/action_dispatch/routing/route_set.rb', line 103

def helpers
  @helpers
end

#moduleObject (readonly)

Returns the value of attribute module


103
104
105
# File 'actionpack/lib/action_dispatch/routing/route_set.rb', line 103

def module
  @module
end

#routesObject (readonly)

Returns the value of attribute routes


103
104
105
# File 'actionpack/lib/action_dispatch/routing/route_set.rb', line 103

def routes
  @routes
end

Instance Method Details

#add(name, route) ⇒ Object Also known as: []=


124
125
126
127
# File 'actionpack/lib/action_dispatch/routing/route_set.rb', line 124

def add(name, route)
  routes[name.to_sym] = route
  define_named_route_methods(name, route)
end

#clear!Object Also known as: clear


115
116
117
118
119
120
121
122
# File 'actionpack/lib/action_dispatch/routing/route_set.rb', line 115

def clear!
  @helpers.each do |helper|
    @module.remove_possible_method helper
  end

  @routes.clear
  @helpers.clear
end

#eachObject


137
138
139
140
# File 'actionpack/lib/action_dispatch/routing/route_set.rb', line 137

def each
  routes.each { |name, route| yield name, route }
  self
end

#get(name) ⇒ Object Also known as: []


129
130
131
# File 'actionpack/lib/action_dispatch/routing/route_set.rb', line 129

def get(name)
  routes[name.to_sym]
end

#helper_namesObject


111
112
113
# File 'actionpack/lib/action_dispatch/routing/route_set.rb', line 111

def helper_names
  @helpers.map(&:to_s)
end

#lengthObject


146
147
148
# File 'actionpack/lib/action_dispatch/routing/route_set.rb', line 146

def length
  routes.length
end

#namesObject


142
143
144
# File 'actionpack/lib/action_dispatch/routing/route_set.rb', line 142

def names
  routes.keys
end