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

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeNamedRouteCollection

Returns a new instance of NamedRouteCollection.



1004
1005
1006
# File 'lib/action_controller/routing.rb', line 1004

def initialize
  clear!
end

Instance Attribute Details

#helpersObject (readonly)

Returns the value of attribute helpers.



1002
1003
1004
# File 'lib/action_controller/routing.rb', line 1002

def helpers
  @helpers
end

#routesObject (readonly)

Returns the value of attribute routes.



1002
1003
1004
# File 'lib/action_controller/routing.rb', line 1002

def routes
  @routes
end

Instance Method Details

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



1018
1019
1020
1021
# File 'lib/action_controller/routing.rb', line 1018

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

#clear!Object Also known as: clear



1008
1009
1010
1011
1012
1013
1014
1015
1016
# File 'lib/action_controller/routing.rb', line 1008

def clear!
  @routes = {}
  @helpers = []
  
  @module ||= Module.new
  @module.instance_methods.each do |selector|
    @module.send :remove_method, selector
  end
end

#eachObject



1031
1032
1033
1034
# File 'lib/action_controller/routing.rb', line 1031

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

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



1023
1024
1025
# File 'lib/action_controller/routing.rb', line 1023

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

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



1044
1045
1046
# File 'lib/action_controller/routing.rb', line 1044

def install(destinations = [ActionController::Base, ActionView::Base])
  Array(destinations).each { |dest| dest.send :include, @module }
end

#lengthObject



1040
1041
1042
# File 'lib/action_controller/routing.rb', line 1040

def length
  routes.length
end

#namesObject



1036
1037
1038
# File 'lib/action_controller/routing.rb', line 1036

def names
  routes.keys
end