diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2014-05-08 11:49:02 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2014-05-12 15:54:45 -0700 |
commit | 74a6ad2c6b612eb58f7fac7522eb9bed9e92d133 (patch) | |
tree | 03a1588e50e436468521c9df2b7e2bdb505e9f8f /actionpack/lib/action_dispatch | |
parent | 56ff626560c4c430e065bc3a6d149d89c88f4272 (diff) | |
download | rails-74a6ad2c6b612eb58f7fac7522eb9bed9e92d133.tar.gz rails-74a6ad2c6b612eb58f7fac7522eb9bed9e92d133.tar.bz2 rails-74a6ad2c6b612eb58f7fac7522eb9bed9e92d133.zip |
undo optimized calls until the builder object is finished
Diffstat (limited to 'actionpack/lib/action_dispatch')
-rw-r--r-- | actionpack/lib/action_dispatch/routing/polymorphic_routes.rb | 55 | ||||
-rw-r--r-- | actionpack/lib/action_dispatch/routing/url_for.rb | 2 |
2 files changed, 20 insertions, 37 deletions
diff --git a/actionpack/lib/action_dispatch/routing/polymorphic_routes.rb b/actionpack/lib/action_dispatch/routing/polymorphic_routes.rb index 6d89de9692..83b8c11e70 100644 --- a/actionpack/lib/action_dispatch/routing/polymorphic_routes.rb +++ b/actionpack/lib/action_dispatch/routing/polymorphic_routes.rb @@ -109,11 +109,9 @@ module ActionDispatch suffix = routing_type options if options[:action] == 'new' - inflection = SINGULAR_ROUTE_KEY - builder = HelperMethodBuilder.singular suffix + builder = HelperMethodBuilder.singular prefix, suffix else - inflection = ROUTE_KEY - builder = HelperMethodBuilder.plural suffix + builder = HelperMethodBuilder.plural prefix, suffix end case record_or_hash_or_array @@ -125,8 +123,7 @@ module ActionDispatch recipient = record_or_hash_or_array.shift end - method, args = builder.handle_list record_or_hash_or_array, - prefix + method, args = builder.handle_list record_or_hash_or_array when Hash unless record_or_hash_or_array[:id] raise ArgumentError, "Nil location provided. Can't build URI." @@ -135,20 +132,17 @@ module ActionDispatch opts = record_or_hash_or_array.dup.merge!(opts) record = opts.delete(:id) - method, args = builder.handle_model record, prefix + method, args = builder.handle_model record when String, Symbol - method, args = builder.handle_string record_or_hash_or_array, - prefix + method, args = builder.handle_string record_or_hash_or_array when Class - method, args = builder.handle_class record_or_hash_or_array, - prefix + method, args = builder.handle_class record_or_hash_or_array when nil raise ArgumentError, "Nil location provided. Can't build URI." else - method, args = builder.handle_model record_or_hash_or_array, - prefix + method, args = builder.handle_model record_or_hash_or_array end @@ -161,7 +155,7 @@ module ActionDispatch # Returns the path component of a URL for the given record. It uses # <tt>polymorphic_url</tt> with <tt>routing_type: :path</tt>. - def polymorphic_path(record_or_hash_or_array, options) + def polymorphic_path(record_or_hash_or_array, options = {}) polymorphic_url(record_or_hash_or_array, options.merge(:routing_type => :path)) end @@ -185,32 +179,33 @@ module ActionDispatch private class HelperMethodBuilder # :nodoc: - def self.singular(suffix) - new(->(name) { name.singular_route_key }, suffix) + def self.singular(prefix, suffix) + new(->(name) { name.singular_route_key }, prefix, suffix) end - def self.plural(suffix) - new(->(name) { name.route_key }, suffix) + def self.plural(prefix, suffix) + new(->(name) { name.route_key }, prefix, suffix) end - attr_reader :suffix + attr_reader :suffix, :prefix - def initialize(key_strategy, suffix) + def initialize(key_strategy, prefix, suffix) @key_strategy = key_strategy + @prefix = prefix @suffix = suffix end - def handle_string(record, prefix) + def handle_string(record) method = prefix + "#{record}_#{suffix}" [method, []] end - def handle_class(klass, prefix) + def handle_class(klass) name = @key_strategy.call klass.model_name [prefix + "#{name}_#{suffix}", []] end - def handle_model(record, prefix) + def handle_model(record) args = [] model = record.to_model @@ -226,7 +221,7 @@ module ActionDispatch [named_route, args] end - def handle_list(list, prefix) + def handle_list(list) record_list = list.dup record = record_list.pop @@ -267,18 +262,6 @@ module ActionDispatch end end - ROUTE_KEY = lambda { |name| name.route_key } - SINGULAR_ROUTE_KEY = lambda { |name| name.singular_route_key } - - - def model_path_helper_call(record) - handle_model record, ''.freeze, "path".freeze, ROUTE_KEY - end - - def class_path_helper_call(klass) - handle_class klass, ''.freeze, "path".freeze, ROUTE_KEY - end - def action_prefix(options) options[:action] ? "#{options[:action]}_" : '' end diff --git a/actionpack/lib/action_dispatch/routing/url_for.rb b/actionpack/lib/action_dispatch/routing/url_for.rb index 4a0ef40873..0976e46903 100644 --- a/actionpack/lib/action_dispatch/routing/url_for.rb +++ b/actionpack/lib/action_dispatch/routing/url_for.rb @@ -158,7 +158,7 @@ module ActionDispatch when Array polymorphic_url(options, options.extract_options!) else - polymorphic_url(options) + polymorphic_url(options, {}) end end |