About

ParseModel provides an Active Record pattern to your Parse models on RubyMotion.

Usage

Create a model:

class Post
  include Parse::Model

  fields :title, :body, :author
end

Create an instance:

p = Post.new
p.title = "Why RubyMotion Is Better Than Objective-C"
p.author = "Josh Symonds"
p.body = "trololol"
p.saveEventually

Parse::Model objects will respond_to? to all methods available to PFObject in the Parse iOS SDK. You can also access the PFObject instance directly with, you guessed it, Parse::Model#PFObject.

Users

class User
  include Parse::User
end

user = User.new
user.username = "adelevie"
user.email = "[email protected]"
user.password = "foobar"
user.

users = User.all # for more User query methods, see: https://parse.com/questions/why-does-querying-for-a-user-create-a-second-user-class 
users.map {|u| u.objectId}.include?(user.objectId) #=> true

Parse::User delegates to PFUser in a very similar fashion as Parse::Model delegates to PFOBject.

Queries

For now, just use Parse's native methods:

query = PFQuery.queryWithClassName("Post")
query.whereKey("title", equalTo:"Why RubyMotion Is Better Than Objective-C")
results = query.findObjects

Note that this will return an Array of PFObjects, not Parse::Model objects. To convert, just pass the PFObject instance into Parse::Model#new:

results.map! {|result| Post.new(result)}

Installation

Either gem install parse-model then require 'parse-model' in your Rakefile, OR

gem "parse-model" in your Gemfile. (Instructions for Bundler setup with Rubymotion)

Somewhere in your code, such as app/app_delegate.rb set your API keys:

Parse.setApplicationId("1234567890", clientKey:"abcdefghijk")

To install the Parse iOS SDK in your RubyMotion project, read this and this.

License

See LICENSE.txt