databasedotcom 1.1.1 → 1.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -236,19 +236,19 @@ module Databasedotcom
236
236
  def self.method_missing(method_name, *args, &block)
237
237
  if method_name.to_s =~ /^find_(or_create_|or_initialize_)?by_(.+)$/ || method_name.to_s =~ /^find_(all_)by_(.+)$/
238
238
  named_attrs = $2.split('_and_')
239
- attrs_and_values_for_find = []
239
+ attrs_and_values_for_find = {}
240
240
  hash_args = args.length == 1 && args[0].is_a?(Hash)
241
241
  attrs_and_values_for_write = hash_args ? args[0] : {}
242
242
 
243
243
  named_attrs.each_with_index do |attr, index|
244
244
  value = hash_args ? args[0][attr] : args[index]
245
- attrs_and_values_for_find << "#{attr} = '#{value}'"
245
+ attrs_and_values_for_find[attr] = value
246
246
  attrs_and_values_for_write[attr] = value unless hash_args
247
247
  end
248
248
 
249
249
  limit_clause = method_name.to_s.include?('_all_by_') ? "" : " LIMIT 1"
250
-
251
- results = self.client.query("SELECT #{self.field_list} FROM #{self.sobject_name} WHERE #{attrs_and_values_for_find.join(' AND ')}#{limit_clause}")
250
+
251
+ results = self.client.query("SELECT #{self.field_list} FROM #{self.sobject_name} WHERE #{soql_conditions_for(attrs_and_values_for_find)}#{limit_clause}")
252
252
  results = limit_clause == "" ? results : results.first rescue nil
253
253
 
254
254
  if results.nil?
@@ -298,6 +298,22 @@ module Databasedotcom
298
298
  raise ArgumentError.new("No attribute named #{attr_name}") unless self.type_map.has_key?(attr_name)
299
299
  self.type_map[attr_name][key]
300
300
  end
301
+
302
+ def self.soql_conditions_for(params)
303
+ params.inject([]) do |arr, av|
304
+ case av[1]
305
+ when String
306
+ value_str = "'#{av[1]}'"
307
+ when DateTime, Time
308
+ value_str = av[1].strftime("%Y-%m-%dT%H:%M:%S.%L%z").insert(-3, ":")
309
+ else
310
+ value_str = av[1].to_s
311
+ end
312
+
313
+ arr << "#{av[0]} = #{value_str}"
314
+ arr
315
+ end.join(" AND ")
316
+ end
301
317
  end
302
318
  end
303
319
  end
@@ -1,3 +1,3 @@
1
1
  module Databasedotcom
2
- VERSION = "1.1.1"
2
+ VERSION = "1.1.2"
3
3
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: databasedotcom
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 1.1.1
5
+ version: 1.1.2
6
6
  platform: ruby
7
7
  authors:
8
8
  - Glenn Gillen, Danny Burkes & Richard Zhao
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-09-23 00:00:00 Z
13
+ date: 2011-10-04 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: multipart-post