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

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
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.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeNamedRouteCollection

Returns a new instance of NamedRouteCollection.



90
91
92
# File 'lib/action_dispatch/routing/route_set.rb', line 90

def initialize
  clear!
end

Instance Attribute Details

#helpersObject (readonly)

Returns the value of attribute helpers.



88
89
90
# File 'lib/action_dispatch/routing/route_set.rb', line 88

def helpers
  @helpers
end

#moduleObject (readonly)

Returns the value of attribute module.



88
89
90
# File 'lib/action_dispatch/routing/route_set.rb', line 88

def module
  @module
end

#routesObject (readonly)

Returns the value of attribute routes.



88
89
90
# File 'lib/action_dispatch/routing/route_set.rb', line 88

def routes
  @routes
end

Instance Method Details

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



107
108
109
110
# File 'lib/action_dispatch/routing/route_set.rb', line 107

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

#clear!Object Also known as: clear



98
99
100
101
102
103
104
105
# File 'lib/action_dispatch/routing/route_set.rb', line 98

def clear!
  @routes = {}
  @helpers = []

  @module ||= Module.new do
    instance_methods.each { |selector| remove_method(selector) }
  end
end

#eachObject



120
121
122
123
# File 'lib/action_dispatch/routing/route_set.rb', line 120

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

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



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

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

#helper_namesObject



94
95
96
# File 'lib/action_dispatch/routing/route_set.rb', line 94

def helper_names
  self.module.instance_methods.map(&:to_s)
end

#install(destinations = [ActionController::Base, ActionView::Base], regenerate = false) ⇒ Object



141
142
143
144
145
146
# File 'lib/action_dispatch/routing/route_set.rb', line 141

def install(destinations = [ActionController::Base, ActionView::Base], regenerate = false)
  reset! if regenerate
  Array(destinations).each do |dest|
    dest.__send__(:include, @module)
  end
end

#lengthObject



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

def length
  routes.length
end

#namesObject



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

def names
  routes.keys
end

#reset!Object



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

def reset!
  old_routes = routes.dup
  clear!
  old_routes.each do |name, route|
    add(name, route)
  end
end