lib/usher/util/generate.rb in usher-0.5.13 vs lib/usher/util/generate.rb in usher-0.6.0
- old
+ new
@@ -115,13 +115,15 @@
extra_params = params.last.is_a?(Hash) ? params.pop : nil
params = Hash[*path.dynamic_parts.inject(path.route.default_values ? path.route.default_values.to_a : []){|a, dynamic_part| a.concat([dynamic_part.name, params.shift || raise(MissingParameterException.new("got #{given_size}, expected #{path.dynamic_parts.size} parameters"))]); a}]
params.merge!(extra_params) if extra_params
end
-
result = Rack::Utils.uri_escape(generate_path_for_base_params(path, params))
unless !generate_extra || params.nil? || params.empty?
+ if usher.consider_destination_keys? && path.route.destination_keys
+ params.delete_if{|k, v| path.route.destination_keys.include?(k)}
+ end
extra_params = generate_extra_params(params, result[??])
result << extra_params
end
result
end
@@ -142,12 +144,12 @@
END_EVAL
@generation_module.generator = self
@generation_module.module_eval <<-END_EVAL
def respond_to?(method_name)
- if match = Regexp.new('^(.*?)_(path|url)$').match(method_name.to_s)
- @@generator.usher.named_routes.key?(match.group(1))
+ if method_name =~ /^(.*?)_(path|url)$/
+ @@generator.usher.named_routes.key?($1)
else
super
end
end
END_EVAL
@@ -182,10 +184,10 @@
url = url_parts.url
(url[-1] == ?/) ? url[0..-2] : url
end
- def path_for_routing_lookup(routing_lookup, params = {})
+ def path_for_routing_lookup(routing_lookup, params = {})
path = case routing_lookup
when Symbol
route = @usher.named_routes[routing_lookup]
raise UnrecognizedException unless route
route.find_matching_path(params || {})