From f5ab6805edbd72f752069d94d88003314e2a8a0a Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Sun, 11 Sep 2011 17:52:19 -0700 Subject: delete unused code, pass path explicitly to journey --- actionpack/lib/action_dispatch/routing/route.rb | 32 ++++--------------------- 1 file changed, 5 insertions(+), 27 deletions(-) (limited to 'actionpack/lib/action_dispatch/routing/route.rb') diff --git a/actionpack/lib/action_dispatch/routing/route.rb b/actionpack/lib/action_dispatch/routing/route.rb index 10b3d38346..563adb02c4 100644 --- a/actionpack/lib/action_dispatch/routing/route.rb +++ b/actionpack/lib/action_dispatch/routing/route.rb @@ -1,27 +1,12 @@ module ActionDispatch module Routing class Route #:nodoc: - attr_reader :app, :conditions, :defaults, :name - attr_reader :path, :requirements, :set + attr_reader :conditions, :path def initialize(set, app, conditions, requirements, defaults, name, anchor) @set = set - @app = app - @defaults = defaults - @name = name - - # FIXME: we should not be doing this much work in a constructor. - - @requirements = requirements.merge(defaults) - @requirements.delete(:controller) if @requirements[:controller].is_a?(Regexp) - @requirements.delete_if { |k, v| - v == Regexp.compile("[^#{SEPARATORS.join}]+") - } - - if path = conditions[:path_info] - @path = path - conditions[:path_info] = ::Rack::Mount::Strexp.compile(path, requirements, SEPARATORS, anchor) - end + path = ::Rack::Mount::Strexp.new( + conditions[:path_info], requirements, SEPARATORS, anchor) @verbs = conditions[:request_method] || [] @@ -32,9 +17,8 @@ module ActionDispatch # # Here we munge values before they get sent on to rack-mount. @conditions[:request_method] = %r[^#{verb}$] unless @verbs.empty? - @conditions[:path_info] = Rack::Mount::RegexpWithNamedGroups.new(@conditions[:path_info]) if @conditions[:path_info] + @conditions[:path_info] = Rack::Mount::RegexpWithNamedGroups.new(path) @conditions.delete_if{ |k,v| k != :path_info && !valid_condition?(k) } - @requirements.delete_if{ |k,v| !valid_condition?(k) } end def verb @@ -45,15 +29,9 @@ module ActionDispatch @segment_keys ||= conditions[:path_info].names.compact.map { |key| key.to_sym } end - def to_s - @to_s ||= begin - "%-6s %-40s %s" % [(verb || :any).to_s.upcase, path, requirements.inspect] - end - end - private def valid_condition?(method) - segment_keys.include?(method) || set.valid_conditions.include?(method) + segment_keys.include?(method) || @set.valid_conditions.include?(method) end end end -- cgit v1.2.3 From 943aa826a48c7db682e24f13cc93ed3298aa7e1a Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Mon, 12 Sep 2011 15:48:03 -0700 Subject: reduce dependencies of external objects in the Route class --- actionpack/lib/action_dispatch/routing/route.rb | 28 +++++++++++++------------ 1 file changed, 15 insertions(+), 13 deletions(-) (limited to 'actionpack/lib/action_dispatch/routing/route.rb') diff --git a/actionpack/lib/action_dispatch/routing/route.rb b/actionpack/lib/action_dispatch/routing/route.rb index 563adb02c4..76d18e4dd5 100644 --- a/actionpack/lib/action_dispatch/routing/route.rb +++ b/actionpack/lib/action_dispatch/routing/route.rb @@ -3,10 +3,15 @@ module ActionDispatch class Route #:nodoc: attr_reader :conditions, :path - def initialize(set, app, conditions, requirements, defaults, name, anchor) - @set = set - path = ::Rack::Mount::Strexp.new( - conditions[:path_info], requirements, SEPARATORS, anchor) + def initialize(valid_conditions, app, conditions, requirements, defaults, name, anchor) + @valid_conditions = valid_conditions + strexp = Journey::Router::Strexp.new( + conditions.delete(:path_info), + requirements, + SEPARATORS, + anchor) + + @path = Journey::Path::Pattern.new(strexp) @verbs = conditions[:request_method] || [] @@ -16,22 +21,19 @@ module ActionDispatch # :request_method represents the HTTP verb that matches this route. # # Here we munge values before they get sent on to rack-mount. - @conditions[:request_method] = %r[^#{verb}$] unless @verbs.empty? - @conditions[:path_info] = Rack::Mount::RegexpWithNamedGroups.new(path) - @conditions.delete_if{ |k,v| k != :path_info && !valid_condition?(k) } - end - - def verb - @verbs.join '|' + unless @verbs.empty? + @conditions[:request_method] = %r[^#{@verbs.join('|')}$] + end + @conditions.delete_if{ |k,v| !valid_condition?(k) } end def segment_keys - @segment_keys ||= conditions[:path_info].names.compact.map { |key| key.to_sym } + @segment_keys ||= path.names.compact.map { |key| key.to_sym } end private def valid_condition?(method) - segment_keys.include?(method) || @set.valid_conditions.include?(method) + segment_keys.include?(method) || @valid_conditions.include?(method) end end end -- cgit v1.2.3 From ad1a89164927e1d87062a350ce259b3713c9e898 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Mon, 12 Sep 2011 16:11:55 -0700 Subject: unfactor the Route class to private factory methods --- actionpack/lib/action_dispatch/routing/route.rb | 40 ------------------------- 1 file changed, 40 deletions(-) delete mode 100644 actionpack/lib/action_dispatch/routing/route.rb (limited to 'actionpack/lib/action_dispatch/routing/route.rb') diff --git a/actionpack/lib/action_dispatch/routing/route.rb b/actionpack/lib/action_dispatch/routing/route.rb deleted file mode 100644 index 76d18e4dd5..0000000000 --- a/actionpack/lib/action_dispatch/routing/route.rb +++ /dev/null @@ -1,40 +0,0 @@ -module ActionDispatch - module Routing - class Route #:nodoc: - attr_reader :conditions, :path - - def initialize(valid_conditions, app, conditions, requirements, defaults, name, anchor) - @valid_conditions = valid_conditions - strexp = Journey::Router::Strexp.new( - conditions.delete(:path_info), - requirements, - SEPARATORS, - anchor) - - @path = Journey::Path::Pattern.new(strexp) - - @verbs = conditions[:request_method] || [] - - @conditions = conditions.dup - - # Rack-Mount requires that :request_method be a regular expression. - # :request_method represents the HTTP verb that matches this route. - # - # Here we munge values before they get sent on to rack-mount. - unless @verbs.empty? - @conditions[:request_method] = %r[^#{@verbs.join('|')}$] - end - @conditions.delete_if{ |k,v| !valid_condition?(k) } - end - - def segment_keys - @segment_keys ||= path.names.compact.map { |key| key.to_sym } - end - - private - def valid_condition?(method) - segment_keys.include?(method) || @valid_conditions.include?(method) - end - end - end -end -- cgit v1.2.3