kelredd-resourceful 0.7.23 → 0.7.24

Sign up to get free protection for your applications and to get access to all the features.
@@ -134,12 +134,33 @@ module Resourceful
134
134
  # # => "?id=thomas_hardy"
135
135
  # {:id => 23423, :since => Time.now}.to_http_query_str
136
136
  # # => "?since=Thu,%2021%20Jun%202007%2012:10:05%20-0500&id=23423"
137
+ # {:id => [1,2]}.to_http_query_str
138
+ # # => "?id[]=1&id[]=2"
139
+ # {:poo => {:foo => 1, :bar => 2}}.to_http_query_str
140
+ # # => "?poo[bar]=2&poo[foo]=1"
141
+ # {:poo => {:foo => 1, :bar => {:bar1 => 1, :bar2 => "nasty"}}}.to_http_query_str
142
+ # "?poo[bar][bar1]=1&poo[bar][bar2]=nasty&poo[foo]=1"
137
143
  unless {}.respond_to?(:to_http_query_str)
138
144
  def to_http_query_str(opts = {})
139
- require 'cgi' unless defined?(CGI) && defined?(CGI::escape)
145
+ require 'cgi' unless defined?(::CGI) && defined?(::CGI::escape)
140
146
  opts[:prepend] ||= '?'
141
147
  opts[:append] ||= ''
142
- self.empty? ? '' : "#{opts[:prepend]}#{self.collect{|key, val| "#{key.to_s}=#{CGI.escape(val.to_s)}"}.join('&')}#{opts[:append]}"
148
+ opts[:key_ns] ||= nil
149
+ opt_strings = self.collect do |key, val|
150
+ key_s = opts[:key_ns] ? "#{opts[:key_ns]}[#{key.to_s}]" : key.to_s
151
+ if val.kind_of?(::Array)
152
+ val.collect{|i| "#{key_s}[]=#{::CGI.escape(i.to_s)}"}.join('&')
153
+ elsif val.kind_of?(::Hash)
154
+ val.to_http_query_str({
155
+ :prepend => '',
156
+ :key_ns => key_s,
157
+ :append => ''
158
+ })
159
+ else
160
+ "#{key_s}=#{::CGI.escape(val.to_s)}"
161
+ end
162
+ end
163
+ self.empty? ? '' : "#{opts[:prepend]}#{opt_strings.join('&')}#{opts[:append]}"
143
164
  end
144
165
  end
145
166
 
@@ -16,7 +16,7 @@ module Resourceful
16
16
  assoc_data = get_association_data(klass, clean_association_name)
17
17
  assoc_klass = klass.ancestors.include?(Resourceful::Model::Base) ? klass.get_namespaced_klass(assoc_data[:class_name]) : assoc_data[:class_name].resourceful_constantize
18
18
  fk_values = collection.inject([]) {|vals, item| vals << item.send(assoc_data[:foreign_key_method])}
19
- fk_results = assoc_klass.send(assoc_data[:find_method_name], :all, {assoc_data[:foreign_key_name] => fk_values.join(',')}, true)
19
+ fk_results = assoc_klass.send(assoc_data[:find_method_name], :all, {assoc_data[:foreign_key_name] => fk_values}, true)
20
20
  collection.each do |item|
21
21
  item_results = fk_results.reject{|result| result.send(assoc_data[:foreign_key_name]) != item.send(assoc_data[:foreign_key_method])}
22
22
  item.instance_variable_set("@#{clean_association_name}", [:belongs_to, :has_one].include?(assoc_data[:type]) ? item_results.first : item_results)
@@ -3,7 +3,7 @@ module Resourceful
3
3
 
4
4
  MAJOR = 0
5
5
  MINOR = 7
6
- TINY = 23
6
+ TINY = 24
7
7
 
8
8
  def self.to_s # :nodoc:
9
9
  [MAJOR, MINOR, TINY].join('.')
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kelredd-resourceful
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.23
4
+ version: 0.7.24
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kelly Redding