Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

remove suffix from the handler methods

  • Loading branch information...
commit 56ff626560c4c430e065bc3a6d149d89c88f4272 1 parent cc1ff82
@tenderlove tenderlove authored
Showing with 19 additions and 20 deletions.
  1. +19 −20 actionpack/lib/action_dispatch/routing/polymorphic_routes.rb
View
39 actionpack/lib/action_dispatch/routing/polymorphic_routes.rb
@@ -110,10 +110,10 @@ def polymorphic_url(record_or_hash_or_array, options = {})
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 @@ def polymorphic_url(record_or_hash_or_array, options = {})
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 @@ def polymorphic_url(record_or_hash_or_array, options = {})
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 @@ def #{action}_polymorphic_path(record_or_hash, options = {}) # def edit_p
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 @@ def handle_model(record, prefix, suffix)
[named_route, args]
end
- def handle_list(list, prefix, suffix)
+ def handle_list(list, prefix)
record_list = list.dup
record = record_list.pop
Please sign in to comment.
Something went wrong with that request. Please try again.