parsecom 0.5.6 → 0.5.7

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -349,7 +349,10 @@ game_scores = GameScore.find :where => proc {
349
349
 
350
350
  #### Counting Objects
351
351
 
352
- TBD
352
+ ```ruby
353
+ game_scores = GameScore.find :where => {'playerName' => 'Jonathan Walsh'}, :count => true, :limit => 0
354
+ game_scores.query_count
355
+ ```
353
356
 
354
357
  #### Compound Queries
355
358
 
@@ -0,0 +1,3 @@
1
+ class Array
2
+ attr_accessor :query_count
3
+ end
@@ -49,8 +49,11 @@ module Parse
49
49
  end
50
50
 
51
51
  def find object_id_or_conditions, opts={}
52
- results = [parse_client.find(self.parse_class_name, object_id_or_conditions, opts)].flatten
53
- results.map! {|hash| self.new hash}
52
+ raw_results = parse_client.find(self.parse_class_name, object_id_or_conditions, opts)
53
+ results = [raw_results].flatten
54
+ results.map! {|hash| self.new hash} # TODO: should be recursive
55
+ results.query_count = raw_results.query_count
56
+ results
54
57
  end
55
58
 
56
59
  def find_by_id object_id, opts={}
@@ -18,7 +18,9 @@ module Parse
18
18
  def run &block
19
19
  block = proc do |body|
20
20
  # TODO: should handle error
21
- body['results']
21
+ results = body['results']
22
+ results.query_count = body['count']
23
+ results
22
24
  end unless block
23
25
  endpoint = %w(User).include?(@parse_class_name) \
24
26
  ? "#{@parse_class_name.lowercase}s"
@@ -105,6 +107,7 @@ module Parse
105
107
  params.push "include=#{URI.encode include}" unless include.empty?
106
108
  params.push "skip=#{URI.encode @skip.to_s}" if @skip
107
109
  params.push "limit=#{URI.encode @limit.to_s}" if @limit
110
+ params.push "count=1" if @count
108
111
 
109
112
  params.join '&'
110
113
  end
@@ -1,3 +1,3 @@
1
1
  module Parse
2
- VERSION = "0.5.6"
2
+ VERSION = "0.5.7"
3
3
  end
@@ -1,17 +1,20 @@
1
1
  # coding:utf-8
2
2
  require "parse/version"
3
3
 
4
+ require 'delegate'
4
5
  require 'open-uri'
5
6
  require 'fileutils'
6
7
  require 'json'
7
8
  require 'date'
8
9
  require 'net/https'
9
10
  require 'uri'
11
+ require 'parse/ext/array'
10
12
  require 'parse/ext/string'
11
13
  require 'parse/util'
12
14
  require 'parse/http_client'
13
15
  require 'parse/client'
14
16
  require 'parse/query'
17
+ require 'parse/query_result'
15
18
  require 'parse/acl'
16
19
  require 'parse/object'
17
20
  require 'parse/user'
@@ -69,6 +69,17 @@ describe Parse::Query, 'when it builds conditions' do
69
69
  query.to_params.should have_params('where' => '{"hometown":{"$select":{"query":{"className":"Team","where":{"winPct":{"$gt":0.5}}},"key":"city"}}}')
70
70
  query.where.clear
71
71
 
72
+ query.where do
73
+ subquery = subquery_for :Team
74
+ subquery.where do
75
+ column(:winPct).gt(0.5)
76
+ end
77
+ subquery.key = 'city'
78
+ column(:hometown).dont_select(subquery)
79
+ end
80
+ query.to_params.should have_params('where' => '{"hometown":{"$dontSelect":{"query":{"className":"Team","where":{"winPct":{"$gt":0.5}}},"key":"city"}}}')
81
+ query.where.clear
82
+
72
83
  query.where do
73
84
  column(:arrayKey).contains(2)
74
85
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: parsecom
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.6
4
+ version: 0.5.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-11-27 00:00:00.000000000 Z
12
+ date: 2013-12-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -81,6 +81,7 @@ files:
81
81
  - lib/parse/event.rb
82
82
  - lib/parse/event/app_opened.rb
83
83
  - lib/parse/event/error.rb
84
+ - lib/parse/ext/array.rb
84
85
  - lib/parse/ext/string.rb
85
86
  - lib/parse/file.rb
86
87
  - lib/parse/geo_point.rb