Skip to content

Commit

Permalink
push string handling to the builder object
Browse files Browse the repository at this point in the history
  • Loading branch information
tenderlove committed May 12, 2014
1 parent e14ec12 commit 3095f5b
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions actionpack/lib/action_dispatch/routing/polymorphic_routes.rb
Expand Up @@ -140,10 +140,9 @@ def polymorphic_url(record_or_hash_or_array, options = {})
method, args = builder.handle_model record, prefix, suffix method, args = builder.handle_model record, prefix, suffix


when String, Symbol when String, Symbol
method, args = handle_string record_or_hash_or_array, method, args = builder.handle_string record_or_hash_or_array,
prefix, prefix,
suffix, suffix
inflection
when Class when Class
method, args = builder.handle_class record_or_hash_or_array, method, args = builder.handle_class record_or_hash_or_array,
prefix, prefix,
Expand Down Expand Up @@ -203,6 +202,11 @@ def initialize(key_strategy)
@key_strategy = key_strategy @key_strategy = key_strategy
end end


def handle_string(record, prefix, suffix)
method = prefix + "#{record}_#{suffix}"
[method, []]
end

def handle_class(klass, prefix, suffix) def handle_class(klass, prefix, suffix)
name = @key_strategy.call klass.model_name name = @key_strategy.call klass.model_name
[prefix + "#{name}_#{suffix}", []] [prefix + "#{name}_#{suffix}", []]
Expand Down Expand Up @@ -268,12 +272,6 @@ def handle_list(list, prefix, suffix, inflection)
[named_route, args] [named_route, args]
end end


def handle_string(record, prefix, suffix, inflection)
args = []
method = prefix + "#{record}_#{suffix}"
[method, args]
end

def model_path_helper_call(record) def model_path_helper_call(record)
handle_model record, ''.freeze, "path".freeze, ROUTE_KEY handle_model record, ''.freeze, "path".freeze, ROUTE_KEY
end end
Expand Down

0 comments on commit 3095f5b

Please sign in to comment.