lib/ethon/easy/queryable.rb in ethon-0.7.3 vs lib/ethon/easy/queryable.rb in ethon-0.7.4
- old
+ new
@@ -6,10 +6,11 @@
module Queryable
# :nodoc:
def self.included(base)
base.send(:attr_accessor, :escape)
+ base.send(:attr_accessor, :params_encoding)
end
# Return wether there are elements in params or not.
#
# @example Return if params is empty.
@@ -93,18 +94,37 @@
end
def recursively_generate_pairs(h, prefix, pairs)
case h
when Hash
- h.each_pair do |k,v|
- key = prefix.nil? ? k : "#{prefix}[#{k}]"
- pairs_for(v, key, pairs)
- end
+ encode_hash_pairs(h, prefix, pairs)
when Array
- h.each_with_index do |v, i|
- key = "#{prefix}[#{i}]"
- pairs_for(v, key, pairs)
+ if params_encoding == :rack
+ encode_rack_array_pairs(h, prefix, pairs)
+ else
+ encode_indexed_array_pairs(h, prefix, pairs)
end
+ end
+ end
+
+ def encode_hash_pairs(h, prefix, pairs)
+ h.each_pair do |k,v|
+ key = prefix.nil? ? k : "#{prefix}[#{k}]"
+ pairs_for(v, key, pairs)
+ end
+ end
+
+ def encode_indexed_array_pairs(h, prefix, pairs)
+ h.each_with_index do |v, i|
+ key = "#{prefix}[#{i}]"
+ pairs_for(v, key, pairs)
+ end
+ end
+
+ def encode_rack_array_pairs(h, prefix, pairs)
+ h.each do |v|
+ key = "#{prefix}[]"
+ pairs_for(v, key, pairs)
end
end
def pairs_for(v, key, pairs)
case v