Permalink
Browse files

Extract method refactoring in ActionDispatch::Routing.

  • Loading branch information...
1 parent 036d3e1 commit 1c125c3e0a760273c0004f4e18d9feb260e07e7b Joey Butler committed Dec 6, 2012
Showing with 10 additions and 12 deletions.
  1. +10 −12 actionpack/lib/action_dispatch/routing/mapper.rb
@@ -102,7 +102,7 @@ def normalize_options!
end
if @options[:constraints].is_a?(Hash)
- (@options[:defaults] ||= {}).reverse_merge!(defaults_from_constraints(@options[:constraints]))
+ (@options[:defaults] ||= {}).reverse_merge!(Utils.defaults_from_constraints(@options[:constraints]))
end
end
@@ -249,11 +249,6 @@ def default_controller
def default_action
@options[:action] || @scope[:action]
end
-
- def defaults_from_constraints(constraints)
- url_keys = [:protocol, :subdomain, :domain, :host, :port]
- constraints.select { |k, v| url_keys.include?(k) && (v.is_a?(String) || v.is_a?(Fixnum)) }
- end
end
# Invokes Rack::Mount::Utils.normalize path and ensure that
@@ -646,7 +641,7 @@ def scope(*args)
options[:constraints] ||= {}
if options[:constraints].is_a?(Hash)
- (options[:defaults] ||= {}).reverse_merge!(defaults_from_constraints(options[:constraints]))
+ (options[:defaults] ||= {}).reverse_merge!(Utils.defaults_from_constraints(options[:constraints]))
else
block, options[:constraints] = options[:constraints], {}
end
@@ -851,11 +846,6 @@ def merge_shallow_scope(parent, child) #:nodoc:
def override_keys(child) #:nodoc:
child.key?(:only) || child.key?(:except) ? [:only, :except] : []
end
-
- def defaults_from_constraints(constraints)
- url_keys = [:protocol, :subdomain, :domain, :host, :port]
- constraints.select { |k, v| url_keys.include?(k) && (v.is_a?(String) || v.is_a?(Fixnum)) }
- end
end
# Resource routing allows you to quickly declare all of the common routes
@@ -1690,5 +1680,13 @@ def initialize(set) #:nodoc:
include Concerns
include Resources
end
+
+ module Utils
+ def defaults_from_constraints(constraints)
+ url_keys = [:protocol, :subdomain, :domain, :host, :port]
+ constraints.select { |k, v| url_keys.include?(k) && (v.is_a?(String) || v.is_a?(Fixnum)) }
+ end
+ module_function :defaults_from_constraints
+ end
end
end

0 comments on commit 1c125c3

Please sign in to comment.