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


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

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

Instance Attribute Details

#helpersObject (readonly)

Returns the value of attribute helpers


101
102
103
# File 'actionpack/lib/action_dispatch/routing/route_set.rb', line 101

def helpers
  @helpers
end

#moduleObject (readonly)

Returns the value of attribute module


101
102
103
# File 'actionpack/lib/action_dispatch/routing/route_set.rb', line 101

def module
  @module
end

#routesObject (readonly)

Returns the value of attribute routes


101
102
103
# File 'actionpack/lib/action_dispatch/routing/route_set.rb', line 101

def routes
  @routes
end

Instance Method Details

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


122
123
124
125
# File 'actionpack/lib/action_dispatch/routing/route_set.rb', line 122

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

#clear!Object Also known as: clear


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

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

  @routes.clear
  @helpers.clear
end

#eachObject


135
136
137
138
# File 'actionpack/lib/action_dispatch/routing/route_set.rb', line 135

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

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


127
128
129
# File 'actionpack/lib/action_dispatch/routing/route_set.rb', line 127

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

#helper_namesObject


109
110
111
# File 'actionpack/lib/action_dispatch/routing/route_set.rb', line 109

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

#lengthObject


144
145
146
# File 'actionpack/lib/action_dispatch/routing/route_set.rb', line 144

def length
  routes.length
end

#namesObject


140
141
142
# File 'actionpack/lib/action_dispatch/routing/route_set.rb', line 140

def names
  routes.keys
end