parsecom 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +2 -2
- data/lib/parse/client.rb +4 -0
- data/lib/parse/object.rb +20 -7
- data/lib/parse/user.rb +14 -4
- data/lib/parse/version.rb +1 -1
- data/spec/parse_object_spec.rb +1 -1
- data/spec/parse_user_spec.rb +9 -0
- metadata +2 -2
data/README.md
CHANGED
@@ -67,7 +67,7 @@ game_score.obj_id # => 'Ed1nuqPvcm'
|
|
67
67
|
### Retrieving Objects
|
68
68
|
|
69
69
|
There are two ways to retrieve objects. One is using Query objects directly and
|
70
|
-
another is using Parse::Object as a facade of query
|
70
|
+
another is using Parse::Object as a facade of a query object.
|
71
71
|
|
72
72
|
```ruby
|
73
73
|
# useing Query object directly
|
@@ -81,7 +81,7 @@ results = GameScore.find :where => {:objectId => 'Ed1nuqPvcm'}
|
|
81
81
|
result = GameScore.find 'Ed1nuqPvcm'
|
82
82
|
```
|
83
83
|
|
84
|
-
More complex
|
84
|
+
More complex query
|
85
85
|
|
86
86
|
```ruby
|
87
87
|
# useing Query object directly
|
data/lib/parse/client.rb
CHANGED
@@ -47,6 +47,10 @@ ex. Parse.credentials application_id: APPLICATION_ID, api_key: API_KEY
|
|
47
47
|
URI.encode password}", nil, &block
|
48
48
|
end
|
49
49
|
|
50
|
+
def log_out
|
51
|
+
@session_token = nil
|
52
|
+
end
|
53
|
+
|
50
54
|
def find parse_class, object_id_or_conditions, opts={}
|
51
55
|
if object_id_or_conditions.is_a? String
|
52
56
|
find_by_id parse_class, object_id_or_conditions, opts
|
data/lib/parse/object.rb
CHANGED
@@ -1,16 +1,25 @@
|
|
1
1
|
# coding:utf-8
|
2
2
|
module Parse
|
3
|
+
RESERVED_PARSE_CLASS = {
|
4
|
+
'_User' => 'Parse::User'
|
5
|
+
}
|
6
|
+
|
3
7
|
class Object
|
8
|
+
|
4
9
|
class << self
|
5
10
|
attr_accessor :parse_class_name, :parse_client, :auto_camel_case
|
6
11
|
|
7
12
|
def create parse_class_name, mod=::Object
|
8
13
|
raise 'already defined' if mod.const_defined? parse_class_name
|
9
14
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
15
|
+
if RESERVED_PARSE_CLASS.has_key? parse_class_name.to_s
|
16
|
+
eval RESERVED_PARSE_CLASS[parse_class_name.to_s]
|
17
|
+
else
|
18
|
+
klass = Class.new(Parse::Object)
|
19
|
+
klass.parse_class_name = parse_class_name.to_sym
|
20
|
+
klass.auto_camel_case = true
|
21
|
+
mod.const_set parse_class_name, klass
|
22
|
+
end
|
14
23
|
end
|
15
24
|
|
16
25
|
def parse_class_name
|
@@ -169,8 +178,12 @@ module Parse
|
|
169
178
|
# subclass of ParseObject for the given parse_class_name
|
170
179
|
#
|
171
180
|
def self.Object parse_class_name, mod=::Object
|
172
|
-
|
173
|
-
|
174
|
-
|
181
|
+
if RESERVED_PARSE_CLASS.has_key? parse_class_name.to_s
|
182
|
+
eval RESERVED_PARSE_CLASS[parse_class_name.to_s]
|
183
|
+
else
|
184
|
+
Parse::Object.create parse_class_name, mod \
|
185
|
+
unless mod.const_defined? parse_class_name
|
186
|
+
mod.const_get parse_class_name
|
187
|
+
end
|
175
188
|
end
|
176
189
|
end
|
data/lib/parse/user.rb
CHANGED
@@ -3,6 +3,10 @@ module Parse
|
|
3
3
|
class User < Object
|
4
4
|
|
5
5
|
class << self
|
6
|
+
def parse_class_name
|
7
|
+
'_User'
|
8
|
+
end
|
9
|
+
|
6
10
|
def sign_up username, password, hash={}
|
7
11
|
self.new(username, password, hash).sign_up
|
8
12
|
end
|
@@ -12,10 +16,14 @@ module Parse
|
|
12
16
|
end
|
13
17
|
end
|
14
18
|
|
15
|
-
def initialize username, password, hash={}
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
+
def initialize username=nil, password=nil, hash={}
|
20
|
+
if username.is_a? Hash
|
21
|
+
super username
|
22
|
+
else
|
23
|
+
super hash
|
24
|
+
@username = username
|
25
|
+
@password = password
|
26
|
+
end
|
19
27
|
end
|
20
28
|
|
21
29
|
def sign_up
|
@@ -42,6 +50,8 @@ module Parse
|
|
42
50
|
end
|
43
51
|
|
44
52
|
def log_out
|
53
|
+
parse_client.log_out
|
54
|
+
self
|
45
55
|
end
|
46
56
|
end
|
47
57
|
end
|
data/lib/parse/version.rb
CHANGED
data/spec/parse_object_spec.rb
CHANGED
@@ -46,7 +46,7 @@ describe Parse::Object, 'when it creates a new parse object' do
|
|
46
46
|
:order => 'createdAt', :keys => 'columnB', :limit => 3
|
47
47
|
class_as.size.should == 3
|
48
48
|
|
49
|
-
class_a = ClassA.find :where => {'objectId' => '
|
49
|
+
class_a = ClassA.find :where => {'objectId' => 'UUqhbnuTYx'},
|
50
50
|
:order => 'createdAt', :keys => 'columnB', :limit => 3
|
51
51
|
class_a.size.should == 1
|
52
52
|
end
|
data/spec/parse_user_spec.rb
CHANGED
@@ -21,3 +21,12 @@ describe Parse::User, 'when it logs out' do
|
|
21
21
|
it 'should get the session token' do
|
22
22
|
end
|
23
23
|
end
|
24
|
+
|
25
|
+
describe Parse::User, 'when it is included in other query' do
|
26
|
+
it 'should return a valid User object' do
|
27
|
+
class_a = ClassA.find 'UUqhbnuTYx', :include => 'user'
|
28
|
+
user = class_a.user
|
29
|
+
user.should be_an_instance_of Parse::User
|
30
|
+
user.obj_id.should == '5VuUwoEe0j'
|
31
|
+
end
|
32
|
+
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.0.
|
4
|
+
version: 0.0.2
|
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-10-
|
12
|
+
date: 2013-10-03 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|