Class: ActionController::Routing::RouteSet::NamedRouteCollection

Inherits:
Object
  • Object
show all
Includes:
Optimisation, Enumerable
Defined in:
lib/action_controller/routing.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.

Constant Summary

Constants included from Optimisation

Optimisation::OPTIMISERS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Optimisation

#generate_optimisation_block

Constructor Details

#initializeNamedRouteCollection

Returns a new instance of NamedRouteCollection.



1110
1111
1112
# File 'lib/action_controller/routing.rb', line 1110

def initialize
  clear!
end

Instance Attribute Details

#helpersObject (readonly)

Returns the value of attribute helpers.



1108
1109
1110
# File 'lib/action_controller/routing.rb', line 1108

def helpers
  @helpers
end

#routesObject (readonly)

Returns the value of attribute routes.



1108
1109
1110
# File 'lib/action_controller/routing.rb', line 1108

def routes
  @routes
end

Instance Method Details

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



1124
1125
1126
1127
# File 'lib/action_controller/routing.rb', line 1124

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

#clear!Object Also known as: clear



1114
1115
1116
1117
1118
1119
1120
1121
1122
# File 'lib/action_controller/routing.rb', line 1114

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

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

#eachObject



1137
1138
1139
1140
# File 'lib/action_controller/routing.rb', line 1137

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

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



1129
1130
1131
# File 'lib/action_controller/routing.rb', line 1129

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

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



1158
1159
1160
1161
1162
1163
# File 'lib/action_controller/routing.rb', line 1158

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

#lengthObject



1146
1147
1148
# File 'lib/action_controller/routing.rb', line 1146

def length
  routes.length
end

#namesObject



1142
1143
1144
# File 'lib/action_controller/routing.rb', line 1142

def names
  routes.keys
end

#reset!Object



1150
1151
1152
1153
1154
1155
1156
# File 'lib/action_controller/routing.rb', line 1150

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