ParseModel 0.0.1
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 +4 -0
- data/Gemfile +4 -0
- data/ParseModel.gemspec +24 -0
- data/README.md +81 -0
- data/Rakefile +1 -0
- data/lib/ParseModel.rb +105 -0
- data/lib/ParseModel/version.rb +3 -0
- metadata +52 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/ParseModel.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "ParseModel/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "ParseModel"
|
7
|
+
s.version = ParseModel::VERSION
|
8
|
+
s.authors = ["Alan deLevie"]
|
9
|
+
s.email = ["adelevie@gmail.com"]
|
10
|
+
s.homepage = ""
|
11
|
+
s.summary = %q{An Active Record pattern for your Parse models on RubyMotion.}
|
12
|
+
s.description = %q{An Active Record pattern for your Parse models on RubyMotion.}
|
13
|
+
|
14
|
+
s.rubyforge_project = "ParseModel"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
# specify any dependencies here; for example:
|
22
|
+
# s.add_development_dependency "rspec"
|
23
|
+
# s.add_runtime_dependency "rest-client"
|
24
|
+
end
|
data/README.md
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
# About
|
2
|
+
|
3
|
+
ParseModel provides an Active Record pattern to your Parse models on RubyMotion.
|
4
|
+
|
5
|
+
## Usage
|
6
|
+
|
7
|
+
Create a model:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
class Post
|
11
|
+
include Parse::Model
|
12
|
+
|
13
|
+
fields :title, :body, :author
|
14
|
+
end
|
15
|
+
```
|
16
|
+
|
17
|
+
Create an instance:
|
18
|
+
|
19
|
+
```ruby
|
20
|
+
p = Post.new
|
21
|
+
p.title = "Why RubyMotion Is Better Than Objective-C"
|
22
|
+
p.author = "Josh Symonds"
|
23
|
+
p.body = "trololol"
|
24
|
+
p.saveEventually
|
25
|
+
```
|
26
|
+
|
27
|
+
`Parse::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, `Parse::Model#PFObject`.
|
28
|
+
|
29
|
+
### Users
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
class User
|
33
|
+
include Parse::User
|
34
|
+
end
|
35
|
+
|
36
|
+
user = User.new
|
37
|
+
user.username = "adelevie"
|
38
|
+
user.email = "adelevie@gmail.com"
|
39
|
+
user.password = "foobar"
|
40
|
+
user.signUp
|
41
|
+
|
42
|
+
users = User.all # for more User query methods, see: https://parse.com/questions/why-does-querying-for-a-user-create-a-second-user-class
|
43
|
+
users.map {|u| u.objectId}.include?(user.objectId) #=> true
|
44
|
+
```
|
45
|
+
|
46
|
+
`Parse::User` delegates to `PFUser` in a very similar fashion as `Parse::Model` delegates to `PFOBject`.
|
47
|
+
|
48
|
+
### Queries
|
49
|
+
|
50
|
+
For now, just use Parse's native methods:
|
51
|
+
|
52
|
+
```ruby
|
53
|
+
query = PFQuery.queryWithClassName("Post")
|
54
|
+
query.whereKey("title", equalTo:"Why RubyMotion Is Better Than Objective-C")
|
55
|
+
results = query.findObjects
|
56
|
+
```
|
57
|
+
|
58
|
+
Note that this will return an `Array` of `PFObjects`, not `Parse::Model` objects. To convert, just pass the `PFObject` instance into `Parse::Model#new`:
|
59
|
+
|
60
|
+
```ruby
|
61
|
+
results.map! {|result| Post.new(result)}
|
62
|
+
```
|
63
|
+
|
64
|
+
|
65
|
+
## Installation
|
66
|
+
|
67
|
+
Either `gem install parse-model` then `require 'parse-model'` in your `Rakefile`, OR
|
68
|
+
|
69
|
+
`gem "parse-model"` in your Gemfile. ([Instructions for Bundler setup with Rubymotion)](http://thunderboltlabs.com/posts/using-bundler-with-rubymotion)
|
70
|
+
|
71
|
+
Somewhere in your code, such as `app/app_delegate.rb` set your API keys:
|
72
|
+
|
73
|
+
```ruby
|
74
|
+
Parse.setApplicationId("1234567890", clientKey:"abcdefghijk")
|
75
|
+
```
|
76
|
+
|
77
|
+
To install the Parse iOS SDK in your RubyMotion project, read [this](http://www.rubymotion.com/developer-center/guides/project-management/#_using_3rd_party_libraries) and [this](http://stackoverflow.com/a/10453895/94154).
|
78
|
+
|
79
|
+
## License
|
80
|
+
|
81
|
+
See LICENSE.txt
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/lib/ParseModel.rb
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
require "ParseModel/version"
|
2
|
+
|
3
|
+
module Parse
|
4
|
+
module User
|
5
|
+
attr_accessor :PFUser
|
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
|
+
|
59
|
+
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
|
metadata
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ParseModel
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Alan deLevie
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-07-01 00:00:00.000000000Z
|
13
|
+
dependencies: []
|
14
|
+
description: An Active Record pattern for your Parse models on RubyMotion.
|
15
|
+
email:
|
16
|
+
- adelevie@gmail.com
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- .gitignore
|
22
|
+
- Gemfile
|
23
|
+
- ParseModel.gemspec
|
24
|
+
- README.md
|
25
|
+
- Rakefile
|
26
|
+
- lib/ParseModel.rb
|
27
|
+
- lib/ParseModel/version.rb
|
28
|
+
homepage: ''
|
29
|
+
licenses: []
|
30
|
+
post_install_message:
|
31
|
+
rdoc_options: []
|
32
|
+
require_paths:
|
33
|
+
- lib
|
34
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
35
|
+
none: false
|
36
|
+
requirements:
|
37
|
+
- - ! '>='
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
requirements: []
|
47
|
+
rubyforge_project: ParseModel
|
48
|
+
rubygems_version: 1.8.10
|
49
|
+
signing_key:
|
50
|
+
specification_version: 3
|
51
|
+
summary: An Active Record pattern for your Parse models on RubyMotion.
|
52
|
+
test_files: []
|