Giter VIP home page Giter VIP logo

parsistence's Introduction

Parse.com is shutting down.

Due to this sad announcement, we will no longer support Parsistence. You're free to continue to use it as long as you wish, and perhaps Parsistence can be modified to work with any self-hosted Parse Server instance, but that will be up to the community.

Jamon Holmgren January 28, 2016

About

Parsistence provides an ActiveRecord/Persistence.js pattern to your Parse.com models on RubyMotion. It's an early fork from ParseModel by Alan deLevie but goes a different direction with its implementation.

Usage

Create a model:

class Post
  include Parsistence::Model

  fields :title, :body, :author
end

Create an instance:

p = Post.new

p.respond_to?(:title) #=> true

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

Parsistence::Model objects will respond_to? to all methods available to PFObject in the Parse iOS SDK, as well as 'fields' getters and setters. You can also access the PFObject instance directly with, you guessed it, Parsistence::Model#PFObject.

If you pass in a PFObject instance, it'll use that:

p = Post.new(pf_post)

If you pass in a hash, it'll set properties automatically:

p = Post.new(title: "Awesome")
p.title # => "Awesome"

Users

class User
  include Parsistence::User
end

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

users = User.all
users.map {|u| u.objectId}.include?(user.objectId) #=> true

Parsistence::User delegates to PFUser in a very similar fashion as Parsistence::Model delegates to PFOBject. Parsistence::User includes Parsistence::Model, in fact.

Queries

Queries use a somewhat different pattern than ActiveRecord but are relatively familiar. They are most like persistence.js.

Car.eq(license: "ABC-123", model: "Camry").order(year: :desc).limit(25).fetchAll do |cars, error|
  if cars
    cars.each do |car|
      # `car` is an instance of your `Car` model here.
    end
  end
end

Chain multiple conditions together, even the same condition type multiple times, then run fetch to execute the query. Pass in a block with two fields to receive the data.

####Available Conditions (note: each condition can take multiple comma-separated fields and values)

Method Effect Example
eq Equal to
Tree.eq(name: "Fir").fetchAll do |trees|
  ...
end
notEq NOT equal to
Tree.notEq(name: "Fir").fetchAll do |trees|
  ...
end
gt Greater than
Tree.gt(height: 10).fetchAll do |trees|
  ...
end
lt Less than
Tree.lt(height: 10).fetchAll do |trees|
  ...
end
gte Greater than or equal to
Tree.gte(height: 10).fetchAll do |trees|
  ...
end
lte Less than or equal to
Tree.lte(height: 10).fetchAll do |trees|
  ...
end
order Order by one or more fields (:asc/:desc).
Tree.order(height: :asc).fetchAll do |trees|
  ...
end
limit Limit and offset.
Tree.limit(25, 10).fetchAll do |trees|
  ...
end
in Get fields where value is contained in an array of values.
Tree.in(height: [10, 15, 20, 25]).fetchAll do |trees|
  ...
end

Relationships

Define your relationships in the Parse.com dashboard and also in your models.

class Post
  include Parsistence::Model

  fields :title, :body, :author

  belongs_to :author # Must be a "pointer" object on Parse.com
end

Author.where(name: "Jamon Holmgren").fetchOne do |fetchedAuthor, error|
  p = Post.new
  p.title = "Awesome Readme"
  p.body = "Read this first!"
  p.author = fetchedAuthor
  p.save
end

Installation

Either gem install Parsistence then require 'Parsistence' in your Rakefile, OR

gem "Parsistence" 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.

Testing

You will need to install the Parse SDK to run the tests. Installation is done via Cocoapods.

bundle
rake pod:install

You must also provide the Parse App ID and Client Key as environment variables when running the tests.

PARSE_APPLICATION_ID="yourappid" PARSE_CLIENT_KEY="yourclientkey" rake spec

License

See LICENSE.txt

parsistence's People

Contributors

adelevie avatar diogoandre avatar gdagley avatar jamonholmgren avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

parsistence's Issues

Interference with RubyMotionQuery::App:Class

Hi, I've just encountered an interesting error. I'm working on an RedPotion app which uses RedAlert, or more precicely RedAlert's app.make_button command. Long story short, if I add the parsistence gem to my project, the app.make_button command fails with this error:

2015-05-31 09:10:47.892 myapp 2[62109:19853849] home_table_screen.rb:50:in `gram_button': undefined method `make_button' for #<UIApplication:0x111a207d0> (NoMethodError)
2015-05-31 09:10:47.898 myapp 2[62109:19853849] *** Terminating app due to uncaught exception 'NoMethodError', reason: 'home_table_screen.rb:50:in `gram_button': undefined method `make_button' for #<UIApplication:0x111a207d0> (NoMethodError)
'
*** First throw call stack:
(
  0   CoreFoundation                      0x000000010421bc65 __exceptionPreprocess + 165
  1   libobjc.A.dylib                     0x0000000100e27bb7 objc_exception_throw + 45
  2   myapp 2                           0x0000000100539e0f _ZL10__vm_raisev + 399
  3   myapp 2                           0x0000000100539f3d rb_vm_raise + 205
  4   myapp 2                           0x0000000100436e39 rb_exc_raise + 9
  5   myapp 2                           0x00000001005381b2 rb_vm_method_missing + 786
  6   myapp 2                           0x000000010050b105 rb_vm_dispatch + 5925
  7   myapp 2                           0x000000010050989d rb_vm_trigger_method_missing + 1053
  8   myapp 2                           0x000000010050aaff rb_vm_dispatch + 4383
  9   myapp 2                           0x000000010013ea3c vm_dispatch + 1436
  10  myapp 2                           0x00000001003cc4b3 rb_scope__gram_button__ + 355
  11  myapp 2                           0x00000001003cca3d __unnamed_43 + 13
  12  UIKit                               0x0000000102d4ada2 -[UIApplication sendAction:to:from:forEvent:] + 75
  13  UIKit                               0x0000000102d4ada2 -[UIApplication sendAction:to:from:forEvent:] + 75
  14  UIKit                               0x0000000102e5c54a -[UIControl _sendActionsForEvents:withEvent:] + 467
  15  UIKit                               0x0000000102e5b919 -[UIControl touchesEnded:withEvent:] + 522
  16  UIKit                               0x0000000102d97998 -[UIWindow _sendTouchesForEvent:] + 735
  17  UIKit                               0x0000000102d982c2 -[UIWindow sendEvent:] + 682
  18  UIKit                               0x0000000102d5e581 -[UIApplication sendEvent:] + 246
  19  UIKit                               0x0000000102d6bd1c _UIApplicationHandleEventFromQueueEvent + 18265
  20  UIKit                               0x0000000102d465dc _UIApplicationHandleEventQueue + 2066
  21  CoreFoundation                      0x000000010414f431 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
  22  CoreFoundation                      0x00000001041452fd __CFRunLoopDoSources0 + 269
  23  CoreFoundation                      0x0000000104144934 __CFRunLoopRun + 868
  24  CoreFoundation                      0x0000000104144366 CFRunLoopRunSpecific + 470
  25  GraphicsServices                    0x00000001061d1a3e GSEventRunModal + 161
  26  UIKit                               0x0000000102d49900 UIApplicationMain + 1282
  27  myapp 2                           0x0000000100146e9f main + 111
  28  libdyld.dylib                       0x0000000105d51145 start + 1
  29  ???                                 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NoMethodError

As I had a similar issue before: infinitered/redpotion#97 , I noticed the following line:
undefined method 'make_button' for #<UIApplication:0x111a207d0>,
which is different to the line in the issue before:
undefined method 'make_button' for RubyMotionQuery::App:Class (NoMethodError).

So adding the parsistence gem seems to change RubyMotionQuery::App:Class to #<UIApplication:0x111a207d0>.

I don't quite understand why the class gets changed but I can reproduce this error by adding and removing the parsistence gem from the gemfile. Is this expected behavior in any way? Thanks a lot!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.