aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_dispatch/routing/polymorphic_routes.rb
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2014-05-08 11:24:12 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2014-05-12 15:54:45 -0700
commit56ff626560c4c430e065bc3a6d149d89c88f4272 (patch)
treee7caa3323bc2a74f3eb0f442a9ed1d2928497a8a /actionpack/lib/action_dispatch/routing/polymorphic_routes.rb
parentcc1ff82df47fe46b2a53af421c71f3189b8738a5 (diff)
downloadrails-56ff626560c4c430e065bc3a6d149d89c88f4272.tar.gz
rails-56ff626560c4c430e065bc3a6d149d89c88f4272.tar.bz2
rails-56ff626560c4c430e065bc3a6d149d89c88f4272.zip
remove suffix from the handler methods
Diffstat (limited to 'actionpack/lib/action_dispatch/routing/polymorphic_routes.rb')
-rw-r--r--actionpack/lib/action_dispatch/routing/polymorphic_routes.rb39
1 files changed, 19 insertions, 20 deletions
diff --git a/actionpack/lib/action_dispatch/routing/polymorphic_routes.rb b/actionpack/lib/action_dispatch/routing/polymorphic_routes.rb
index 282e6ca506..6d89de9692 100644
--- a/actionpack/lib/action_dispatch/routing/polymorphic_routes.rb
+++ b/actionpack/lib/action_dispatch/routing/polymorphic_routes.rb
@@ -110,10 +110,10 @@ module ActionDispatch
if options[:action] == 'new'
inflection = SINGULAR_ROUTE_KEY
- builder = HelperMethodBuilder.singular
+ builder = HelperMethodBuilder.singular suffix
else
inflection = ROUTE_KEY
- builder = HelperMethodBuilder.plural
+ builder = HelperMethodBuilder.plural suffix
end
case record_or_hash_or_array
@@ -126,8 +126,7 @@ module ActionDispatch
end
method, args = builder.handle_list record_or_hash_or_array,
- prefix,
- suffix
+ prefix
when Hash
unless record_or_hash_or_array[:id]
raise ArgumentError, "Nil location provided. Can't build URI."
@@ -136,23 +135,20 @@ module ActionDispatch
opts = record_or_hash_or_array.dup.merge!(opts)
record = opts.delete(:id)
- method, args = builder.handle_model record, prefix, suffix
+ method, args = builder.handle_model record, prefix
when String, Symbol
method, args = builder.handle_string record_or_hash_or_array,
- prefix,
- suffix
+ prefix
when Class
method, args = builder.handle_class record_or_hash_or_array,
- prefix,
- suffix
+ prefix
when nil
raise ArgumentError, "Nil location provided. Can't build URI."
else
method, args = builder.handle_model record_or_hash_or_array,
- prefix,
- suffix
+ prefix
end
@@ -189,29 +185,32 @@ module ActionDispatch
private
class HelperMethodBuilder # :nodoc:
- def self.singular
- new(->(name) { name.singular_route_key })
+ def self.singular(suffix)
+ new(->(name) { name.singular_route_key }, suffix)
end
- def self.plural
- new(->(name) { name.route_key })
+ def self.plural(suffix)
+ new(->(name) { name.route_key }, suffix)
end
- def initialize(key_strategy)
+ attr_reader :suffix
+
+ def initialize(key_strategy, suffix)
@key_strategy = key_strategy
+ @suffix = suffix
end
- def handle_string(record, prefix, suffix)
+ def handle_string(record, prefix)
method = prefix + "#{record}_#{suffix}"
[method, []]
end
- def handle_class(klass, prefix, suffix)
+ def handle_class(klass, prefix)
name = @key_strategy.call klass.model_name
[prefix + "#{name}_#{suffix}", []]
end
- def handle_model(record, prefix, suffix)
+ def handle_model(record, prefix)
args = []
model = record.to_model
@@ -227,7 +226,7 @@ module ActionDispatch
[named_route, args]
end
- def handle_list(list, prefix, suffix)
+ def handle_list(list, prefix)
record_list = list.dup
record = record_list.pop