Class: ActionDispatch::Routing::DeprecatedMapper
- Inherits:
-
Object
- Object
- ActionDispatch::Routing::DeprecatedMapper
- Defined in:
- actionpack/lib/action_dispatch/routing/deprecated_mapper.rb
Overview
:nodoc:
Defined Under Namespace
Classes: Resource, SingletonResource
Constant Summary
- INHERITABLE_OPTIONS =
:namespace, :shallow
Instance Method Summary (collapse)
- - (Object) connect(path, options = {})
-
- (DeprecatedMapper) initialize(set)
constructor
:nodoc:.
-
- (Object) method_missing(route_name, *args, &proc)
:nodoc:.
-
- (Object) named_route(name, path, options = {})
:nodoc:.
- - (Object) namespace(name, options = {}, &block)
- - (Object) resource(*entities, &block)
- - (Object) resources(*entities, &block)
-
- (Object) root(options = {})
Creates a named route called "root" for matching the root level request.
Constructor Details
- (DeprecatedMapper) initialize(set)
:nodoc:
33 34 35 36 37 |
# File 'actionpack/lib/action_dispatch/routing/deprecated_mapper.rb', line 33 def initialize(set) #:nodoc: ActiveSupport::Deprecation.warn "You are using the old router DSL which will be removed in Rails 3.1. " << "Please check how to update your routes file at: http://www.engineyard.com/blog/2010/the-lowdown-on-routes-in-rails-3/" @set = set end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
- (Object) method_missing(route_name, *args, &proc)
:nodoc:
204 205 206 207 |
# File 'actionpack/lib/action_dispatch/routing/deprecated_mapper.rb', line 204 def method_missing(route_name, *args, &proc) #:nodoc: super unless args.length >= 1 && proc.nil? named_route(route_name, *args) end |
Instance Method Details
- (Object) connect(path, options = {})
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'actionpack/lib/action_dispatch/routing/deprecated_mapper.rb', line 39 def connect(path, = {}) = .dup if conditions = .delete(:conditions) conditions = conditions.dup method = [conditions.delete(:method)].flatten.compact method.map! { |m| m = m.to_s.upcase if m == "HEAD" raise ArgumentError, "HTTP method HEAD is invalid in route conditions. Rails processes HEAD requests the same as GETs, returning just the response headers" end unless HTTP_METHODS.include?(m.downcase.to_sym) raise ArgumentError, "Invalid HTTP method specified in route conditions" end m } if method.length > 1 method = Regexp.union(*method) elsif method.length == 1 method = method.first else method = nil end end path_prefix = .delete(:path_prefix) name_prefix = .delete(:name_prefix) namespace = .delete(:namespace) name = .delete(:_name) name = "#{name_prefix}#{name}" if name_prefix requirements = .delete(:requirements) || {} defaults = .delete(:defaults) || {} .each do |k, v| if v.is_a?(Regexp) if value = .delete(k) requirements[k.to_sym] = value end else value = .delete(k) defaults[k.to_sym] = value.is_a?(Symbol) ? value : value.to_param end end requirements.each do |_, requirement| if requirement.source =~ %r{\A(\\A|\^)|(\\Z|\\z|\$)\Z} raise ArgumentError, "Regexp anchor characters are not allowed in routing requirements: #{requirement.inspect}" end if requirement.multiline? raise ArgumentError, "Regexp multiline option not allowed in routing requirements: #{requirement.inspect}" end end requirements[:controller] ||= @set.controller_constraints if defaults[:controller] defaults[:action] ||= 'index' defaults[:controller] = defaults[:controller].to_s defaults[:controller] = "#{namespace}#{defaults[:controller]}" if namespace end if defaults[:action] defaults[:action] = defaults[:action].to_s end if path.is_a?(String) path = "#{path_prefix}/#{path}" if path_prefix path = path.gsub('.:format', '(.:format)') path = optionalize_trailing_dynamic_segments(path, requirements, defaults) glob = $1.to_sym if path =~ /\/\*(\w+)$/ path = ::Rack::Mount::Utils.normalize_path(path) if glob && !defaults[glob].blank? raise ActionController::RoutingError, "paths cannot have non-empty default values" end end app = Routing::RouteSet::Dispatcher.new(:defaults => defaults, :glob => glob) conditions = {} conditions[:request_method] = method if method conditions[:path_info] = path if path @set.add_route(app, conditions, requirements, defaults, name) end |
- (Object) named_route(name, path, options = {})
:nodoc:
191 192 193 194 |
# File 'actionpack/lib/action_dispatch/routing/deprecated_mapper.rb', line 191 def named_route(name, path, = {}) #:nodoc: [:_name] = name connect(path, ) end |
- (Object) namespace(name, options = {}, &block)
196 197 198 199 200 201 202 |
# File 'actionpack/lib/action_dispatch/routing/deprecated_mapper.rb', line 196 def namespace(name, = {}, &block) if [:namespace] ({:path_prefix => "#{.delete(:path_prefix)}/#{name}", :name_prefix => "#{.delete(:name_prefix)}#{name}_", :namespace => "#{.delete(:namespace)}#{name}/" }.merge(), &block) else ({:path_prefix => name, :name_prefix => "#{name}_", :namespace => "#{name}/" }.merge(), &block) end end |
- (Object) resource(*entities, &block)
361 362 363 364 |
# File 'actionpack/lib/action_dispatch/routing/deprecated_mapper.rb', line 361 def resource(*entities, &block) = entities. entities.each { |entity| map_singleton_resource(entity, .dup, &block) } end |
- (Object) resources(*entities, &block)
356 357 358 359 |
# File 'actionpack/lib/action_dispatch/routing/deprecated_mapper.rb', line 356 def resources(*entities, &block) = entities. entities.each { |entity| map_resource(entity, .dup, &block) } end |
- (Object) root(options = {})
Creates a named route called "root" for matching the root level request.
182 183 184 185 186 187 188 189 |
# File 'actionpack/lib/action_dispatch/routing/deprecated_mapper.rb', line 182 def root( = {}) if .is_a?(Symbol) if source_route = @set.named_routes.routes[] = source_route.defaults.merge({ :conditions => source_route.conditions }) end end named_route("root", '', ) end |