ParseModel 0.0.1 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +15 -1
- data/.repl_history +0 -0
- data/Gemfile +1 -1
- data/LICENSE +22 -0
- data/ParseModel.gemspec +1 -2
- data/README.md +16 -8
- data/Rakefile +7 -0
- data/lib/ParseModel.rb +4 -102
- data/lib/ParseModel/Model.rb +55 -0
- data/lib/ParseModel/User.rb +58 -0
- data/lib/ParseModel/query.rb +24 -0
- data/lib/ParseModel/version.rb +1 -1
- metadata +17 -3
data/.gitignore
CHANGED
data/.repl_history
ADDED
File without changes
|
data/Gemfile
CHANGED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Alan deLevie
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/ParseModel.gemspec
CHANGED
data/README.md
CHANGED
@@ -2,13 +2,22 @@
|
|
2
2
|
|
3
3
|
ParseModel provides an Active Record pattern to your Parse models on RubyMotion.
|
4
4
|
|
5
|
+
I'm using ParseModel internally for a project, slowly but surely making it much, much better. When the project is near completion, I'm going to extract additional functionality into the gem.
|
6
|
+
|
7
|
+
Some features to expect:
|
8
|
+
* Easier queries (`Post.where(:author => @author)`)
|
9
|
+
* Associations (`class Post; include Parse::Model; has_one :author; end`)
|
10
|
+
* Overall, a much more Ruby-esque API that still leaves full access to all of the features in the Parse iOS SDK
|
11
|
+
|
12
|
+
If you have any questions or suggestions, email me.
|
13
|
+
|
5
14
|
## Usage
|
6
15
|
|
7
16
|
Create a model:
|
8
17
|
|
9
18
|
```ruby
|
10
19
|
class Post
|
11
|
-
include
|
20
|
+
include ParseModel::Model
|
12
21
|
|
13
22
|
fields :title, :body, :author
|
14
23
|
end
|
@@ -24,13 +33,13 @@ p.body = "trololol"
|
|
24
33
|
p.saveEventually
|
25
34
|
```
|
26
35
|
|
27
|
-
`
|
36
|
+
`ParseModel::Model` objects will `respond_to?` to all methods available to [`PFObject`](https://parse.com/docs/ios/api/Classes/PFObject.html) in the Parse iOS SDK. You can also access the `PFObject` instance directly with, you guessed it, `ParseModel::Model#PFObject`.
|
28
37
|
|
29
38
|
### Users
|
30
39
|
|
31
40
|
```ruby
|
32
41
|
class User
|
33
|
-
include
|
42
|
+
include ParseModel::User
|
34
43
|
end
|
35
44
|
|
36
45
|
user = User.new
|
@@ -43,7 +52,7 @@ users = User.all # for more User query methods, see: https://parse.com/questions
|
|
43
52
|
users.map {|u| u.objectId}.include?(user.objectId) #=> true
|
44
53
|
```
|
45
54
|
|
46
|
-
`
|
55
|
+
`ParseModel::User` delegates to `PFUser` in a very similar fashion as `ParseModel::Model` delegates to `PFOBject`.
|
47
56
|
|
48
57
|
### Queries
|
49
58
|
|
@@ -55,7 +64,7 @@ query.whereKey("title", equalTo:"Why RubyMotion Is Better Than Objective-C")
|
|
55
64
|
results = query.findObjects
|
56
65
|
```
|
57
66
|
|
58
|
-
Note that this will return an `Array` of `PFObjects`, not `
|
67
|
+
Note that this will return an `Array` of `PFObjects`, not `ParseModel::Model` objects. To convert, just pass the `PFObject` instance into `ParseModel::Model#new`:
|
59
68
|
|
60
69
|
```ruby
|
61
70
|
results.map! {|result| Post.new(result)}
|
@@ -64,9 +73,8 @@ results.map! {|result| Post.new(result)}
|
|
64
73
|
|
65
74
|
## Installation
|
66
75
|
|
67
|
-
Either `gem install
|
68
|
-
|
69
|
-
`gem "parse-model"` in your Gemfile. ([Instructions for Bundler setup with Rubymotion)](http://thunderboltlabs.com/posts/using-bundler-with-rubymotion)
|
76
|
+
Either `gem install ParseModel` then `require 'ParseModel'` in your `Rakefile`, OR
|
77
|
+
`gem "ParseModel"` in your Gemfile. ([Instructions for Bundler setup with Rubymotion)](http://thunderboltlabs.com/posts/using-bundler-with-rubymotion)
|
70
78
|
|
71
79
|
Somewhere in your code, such as `app/app_delegate.rb` set your API keys:
|
72
80
|
|
data/Rakefile
CHANGED
data/lib/ParseModel.rb
CHANGED
@@ -1,105 +1,7 @@
|
|
1
1
|
require "ParseModel/version"
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
RESERVED_KEYS = ['username', 'password', 'email']
|
8
|
-
|
9
|
-
def initialize
|
10
|
-
@PFUser = PFUser.user
|
11
|
-
end
|
12
|
-
|
13
|
-
def method_missing(method, *args, &block)
|
14
|
-
if RESERVED_KEYS.include?(method)
|
15
|
-
@PFUser.send(method)
|
16
|
-
elsif RESERVED_KEYS.map {|f| "#{f}="}.include?("#{method}")
|
17
|
-
@PFUser.send(method, args.first)
|
18
|
-
elsif fields.include?(method)
|
19
|
-
@PFUser.objectForKey(method)
|
20
|
-
elsif fields.map {|f| "#{f}="}.include?("#{method}")
|
21
|
-
method = method.split("=")[0]
|
22
|
-
@PFUser.setObject(args.first, forKey:method)
|
23
|
-
elsif @PFUser.respond_to?(method)
|
24
|
-
@PFUser.send(method, *args, &block)
|
25
|
-
else
|
26
|
-
super
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
def fields
|
31
|
-
self.class.send(:get_fields)
|
32
|
-
end
|
33
|
-
|
34
|
-
module ClassMethods
|
35
|
-
def fields(*args)
|
36
|
-
args.each {|arg| field(arg)}
|
37
|
-
end
|
38
|
-
|
39
|
-
def field(name)
|
40
|
-
@fields
|
41
|
-
end
|
42
|
-
|
43
|
-
def get_fields
|
44
|
-
@fields ||= []
|
45
|
-
@fields
|
46
|
-
end
|
47
|
-
|
48
|
-
def all
|
49
|
-
query = PFQuery.queryForUser
|
50
|
-
users = query.findObjects
|
51
|
-
users
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
def self.included(base)
|
56
|
-
base.extend(ClassMethods)
|
57
|
-
end
|
58
|
-
|
3
|
+
Motion::Project::App.setup do |app|
|
4
|
+
Dir.glob(File.join(File.dirname(__FILE__), "ParseModel/*.rb")).each do |file|
|
5
|
+
app.files.unshift(file)
|
59
6
|
end
|
60
|
-
|
61
|
-
module Model
|
62
|
-
attr_accessor :PFObject
|
63
|
-
|
64
|
-
def initialize
|
65
|
-
@PFObject = PFObject.objectWithClassName(self.class.to_s)
|
66
|
-
end
|
67
|
-
|
68
|
-
def method_missing(method, *args, &block)
|
69
|
-
if fields.include?(method)
|
70
|
-
@PFObject.objectForKey(method)
|
71
|
-
elsif fields.map {|f| "#{f}="}.include?("#{method}")
|
72
|
-
method = method.split("=")[0]
|
73
|
-
@PFObject.setObject(args.first, forKey:method)
|
74
|
-
elsif @PFObject.respond_to?(method)
|
75
|
-
@PFObject.send(method, *args, &block)
|
76
|
-
else
|
77
|
-
super
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
def fields
|
82
|
-
self.class.send(:get_fields)
|
83
|
-
end
|
84
|
-
|
85
|
-
module ClassMethods
|
86
|
-
def fields(*args)
|
87
|
-
args.each {|arg| field(arg)}
|
88
|
-
end
|
89
|
-
|
90
|
-
def field(name)
|
91
|
-
@fields ||= []
|
92
|
-
@fields << name
|
93
|
-
end
|
94
|
-
|
95
|
-
def get_fields
|
96
|
-
@fields
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
def self.included(base)
|
101
|
-
base.extend(ClassMethods)
|
102
|
-
end
|
103
|
-
|
104
|
-
end
|
105
|
-
end
|
7
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
module ParseModel
|
2
|
+
|
3
|
+
module Model
|
4
|
+
attr_accessor :PFObject
|
5
|
+
|
6
|
+
def initialize(pf_object=nil)
|
7
|
+
if pf_object
|
8
|
+
@PFObject = pf_object
|
9
|
+
else
|
10
|
+
@PFObject = PFObject.objectWithClassName(self.class.to_s)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def method_missing(method, *args, &block)
|
15
|
+
if fields.include?(method)
|
16
|
+
@PFObject.objectForKey(method)
|
17
|
+
elsif fields.map {|f| "#{f}="}.include?("#{method}")
|
18
|
+
method = method.split("=")[0]
|
19
|
+
@PFObject.setObject(args.first, forKey:method)
|
20
|
+
elsif @PFObject.respond_to?(method)
|
21
|
+
@PFObject.send(method, *args, &block)
|
22
|
+
else
|
23
|
+
super
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def fields
|
28
|
+
self.class.send(:get_fields)
|
29
|
+
end
|
30
|
+
|
31
|
+
module ClassMethods
|
32
|
+
def fields(*args)
|
33
|
+
args.each {|arg| field(arg)}
|
34
|
+
end
|
35
|
+
|
36
|
+
def field(name)
|
37
|
+
@fields ||= []
|
38
|
+
@fields << name
|
39
|
+
end
|
40
|
+
|
41
|
+
def query
|
42
|
+
ParseModel::Query.alloc.initWithClassNameAndClassObject(self.name, classObject:self)
|
43
|
+
end
|
44
|
+
|
45
|
+
def get_fields
|
46
|
+
@fields
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def self.included(base)
|
51
|
+
base.extend(ClassMethods)
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
module ParseModel
|
2
|
+
module User
|
3
|
+
attr_accessor :PFUser
|
4
|
+
|
5
|
+
RESERVED_KEYS = ['username', 'password', 'email']
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
@PFUser = PFUser.user
|
9
|
+
end
|
10
|
+
|
11
|
+
def method_missing(method, *args, &block)
|
12
|
+
if RESERVED_KEYS.include?(method)
|
13
|
+
@PFUser.send(method)
|
14
|
+
elsif RESERVED_KEYS.map {|f| "#{f}="}.include?("#{method}")
|
15
|
+
@PFUser.send(method, args.first)
|
16
|
+
elsif fields.include?(method)
|
17
|
+
@PFUser.objectForKey(method)
|
18
|
+
elsif fields.map {|f| "#{f}="}.include?("#{method}")
|
19
|
+
method = method.split("=")[0]
|
20
|
+
@PFUser.setObject(args.first, forKey:method)
|
21
|
+
elsif @PFUser.respond_to?(method)
|
22
|
+
@PFUser.send(method, *args, &block)
|
23
|
+
else
|
24
|
+
super
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def fields
|
29
|
+
self.class.send(:get_fields)
|
30
|
+
end
|
31
|
+
|
32
|
+
module ClassMethods
|
33
|
+
def fields(*args)
|
34
|
+
args.each {|arg| field(arg)}
|
35
|
+
end
|
36
|
+
|
37
|
+
def field(name)
|
38
|
+
@fields
|
39
|
+
end
|
40
|
+
|
41
|
+
def get_fields
|
42
|
+
@fields ||= []
|
43
|
+
@fields
|
44
|
+
end
|
45
|
+
|
46
|
+
def all
|
47
|
+
query = PFQuery.queryForUser
|
48
|
+
users = query.findObjects
|
49
|
+
users
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def self.included(base)
|
54
|
+
base.extend(ClassMethods)
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module ParseModel
|
2
|
+
class Query < PFQuery
|
3
|
+
|
4
|
+
def setClassObject(classObject)
|
5
|
+
@classObject = classObject
|
6
|
+
end
|
7
|
+
|
8
|
+
def initWithClassNameAndClassObject(className, classObject:myClassObject)
|
9
|
+
self.initWithClassName(className)
|
10
|
+
self.setClassObject(myClassObject)
|
11
|
+
self
|
12
|
+
end
|
13
|
+
|
14
|
+
def find(&block)
|
15
|
+
return self.findObjects.map {|obj| @classObject.new(obj)} unless block_given?
|
16
|
+
|
17
|
+
self.findObjectsInBackgroundWithBlock(lambda do |objects, error|
|
18
|
+
objects = objects.map {|obj| @classObject.new(obj)} if objects
|
19
|
+
block.call(objects, error)
|
20
|
+
end)
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
data/lib/ParseModel/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ParseModel
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
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: 2012-
|
12
|
+
date: 2012-09-02 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: An Active Record pattern for your Parse models on RubyMotion.
|
15
15
|
email:
|
@@ -19,11 +19,25 @@ extensions: []
|
|
19
19
|
extra_rdoc_files: []
|
20
20
|
files:
|
21
21
|
- .gitignore
|
22
|
+
- .repl_history
|
22
23
|
- Gemfile
|
24
|
+
- LICENSE
|
23
25
|
- ParseModel.gemspec
|
24
26
|
- README.md
|
25
27
|
- Rakefile
|
28
|
+
- build/iPhoneSimulator-5.1-Development/Untitled.app/Info.plist
|
29
|
+
- build/iPhoneSimulator-5.1-Development/Untitled.app/PkgInfo
|
30
|
+
- build/iPhoneSimulator-5.1-Development/Untitled.app/Untitled
|
31
|
+
- build/iPhoneSimulator-5.1-Development/Untitled.dSYM/Contents/Info.plist
|
32
|
+
- build/iPhoneSimulator-5.1-Development/Untitled.dSYM/Contents/Resources/DWARF/Untitled
|
33
|
+
- build/iPhoneSimulator-5.1-Development/objs/init.mm
|
34
|
+
- build/iPhoneSimulator-5.1-Development/objs/init.o
|
35
|
+
- build/iPhoneSimulator-5.1-Development/objs/main.mm
|
36
|
+
- build/iPhoneSimulator-5.1-Development/objs/main.o
|
26
37
|
- lib/ParseModel.rb
|
38
|
+
- lib/ParseModel/Model.rb
|
39
|
+
- lib/ParseModel/User.rb
|
40
|
+
- lib/ParseModel/query.rb
|
27
41
|
- lib/ParseModel/version.rb
|
28
42
|
homepage: ''
|
29
43
|
licenses: []
|
@@ -45,7 +59,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
45
59
|
version: '0'
|
46
60
|
requirements: []
|
47
61
|
rubyforge_project: ParseModel
|
48
|
-
rubygems_version: 1.8.
|
62
|
+
rubygems_version: 1.8.24
|
49
63
|
signing_key:
|
50
64
|
specification_version: 3
|
51
65
|
summary: An Active Record pattern for your Parse models on RubyMotion.
|