forked from adelevie/ParseModel
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improved query interface, not confirmed stable
- Loading branch information
Showing
9 changed files
with
162 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
source "http://rubygems.org" | ||
source :rubygems | ||
|
||
# Specify your gem's dependencies in ParseModel.gemspec | ||
gemspec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,4 @@ | ||
require "bundler/gem_tasks" | ||
$:.unshift("/Library/RubyMotion/lib") | ||
require 'motion/project' | ||
require 'bundler' | ||
Bundler.setup |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,105 +1,7 @@ | ||
require "ParseModel/version" | ||
|
||
module Parse | ||
module User | ||
attr_accessor :PFUser | ||
|
||
RESERVED_KEYS = ['username', 'password', 'email'] | ||
|
||
def initialize | ||
@PFUser = PFUser.user | ||
end | ||
|
||
def method_missing(method, *args, &block) | ||
if RESERVED_KEYS.include?(method) | ||
@PFUser.send(method) | ||
elsif RESERVED_KEYS.map {|f| "#{f}="}.include?("#{method}") | ||
@PFUser.send(method, args.first) | ||
elsif fields.include?(method) | ||
@PFUser.objectForKey(method) | ||
elsif fields.map {|f| "#{f}="}.include?("#{method}") | ||
method = method.split("=")[0] | ||
@PFUser.setObject(args.first, forKey:method) | ||
elsif @PFUser.respond_to?(method) | ||
@PFUser.send(method, *args, &block) | ||
else | ||
super | ||
end | ||
end | ||
|
||
def fields | ||
self.class.send(:get_fields) | ||
end | ||
|
||
module ClassMethods | ||
def fields(*args) | ||
args.each {|arg| field(arg)} | ||
end | ||
|
||
def field(name) | ||
@fields | ||
end | ||
|
||
def get_fields | ||
@fields ||= [] | ||
@fields | ||
end | ||
|
||
def all | ||
query = PFQuery.queryForUser | ||
users = query.findObjects | ||
users | ||
end | ||
end | ||
|
||
def self.included(base) | ||
base.extend(ClassMethods) | ||
end | ||
|
||
end | ||
|
||
module Model | ||
attr_accessor :PFObject | ||
|
||
def initialize | ||
@PFObject = PFObject.objectWithClassName(self.class.to_s) | ||
end | ||
|
||
def method_missing(method, *args, &block) | ||
if fields.include?(method) | ||
@PFObject.objectForKey(method) | ||
elsif fields.map {|f| "#{f}="}.include?("#{method}") | ||
method = method.split("=")[0] | ||
@PFObject.setObject(args.first, forKey:method) | ||
elsif @PFObject.respond_to?(method) | ||
@PFObject.send(method, *args, &block) | ||
else | ||
super | ||
end | ||
end | ||
|
||
def fields | ||
self.class.send(:get_fields) | ||
end | ||
|
||
module ClassMethods | ||
def fields(*args) | ||
args.each {|arg| field(arg)} | ||
end | ||
|
||
def field(name) | ||
@fields ||= [] | ||
@fields << name | ||
end | ||
|
||
def get_fields | ||
@fields | ||
end | ||
end | ||
|
||
def self.included(base) | ||
base.extend(ClassMethods) | ||
end | ||
|
||
Motion::Project::App.setup do |app| | ||
Dir.glob(File.join(File.dirname(__FILE__), "ParseModel/*.rb")).each do |file| | ||
app.files.unshift(file) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
module ParseModel | ||
|
||
module Model | ||
attr_accessor :PFObject | ||
|
||
def initialize(pf_object=nil) | ||
if pf_object | ||
@PFObject = pf_object | ||
else | ||
@PFObject = PFObject.objectWithClassName(self.class.to_s) | ||
end | ||
end | ||
|
||
def method_missing(method, *args, &block) | ||
if fields.include?(method) | ||
@PFObject.objectForKey(method) | ||
elsif fields.map {|f| "#{f}="}.include?("#{method}") | ||
method = method.split("=")[0] | ||
@PFObject.setObject(args.first, forKey:method) | ||
elsif @PFObject.respond_to?(method) | ||
@PFObject.send(method, *args, &block) | ||
else | ||
super | ||
end | ||
end | ||
|
||
def fields | ||
self.class.send(:get_fields) | ||
end | ||
|
||
module ClassMethods | ||
def fields(*args) | ||
args.each {|arg| field(arg)} | ||
end | ||
|
||
def field(name) | ||
@fields ||= [] | ||
@fields << name | ||
end | ||
|
||
def query | ||
ParseModel::Query.alloc.initWithClassNameAndClassObject(self.name, classObject:self) | ||
end | ||
|
||
def get_fields | ||
@fields | ||
end | ||
end | ||
|
||
def self.included(base) | ||
base.extend(ClassMethods) | ||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
module ParseModel | ||
module User | ||
attr_accessor :PFUser | ||
|
||
RESERVED_KEYS = ['username', 'password', 'email'] | ||
|
||
def initialize | ||
@PFUser = PFUser.user | ||
end | ||
|
||
def method_missing(method, *args, &block) | ||
if RESERVED_KEYS.include?(method) | ||
@PFUser.send(method) | ||
elsif RESERVED_KEYS.map {|f| "#{f}="}.include?("#{method}") | ||
@PFUser.send(method, args.first) | ||
elsif fields.include?(method) | ||
@PFUser.objectForKey(method) | ||
elsif fields.map {|f| "#{f}="}.include?("#{method}") | ||
method = method.split("=")[0] | ||
@PFUser.setObject(args.first, forKey:method) | ||
elsif @PFUser.respond_to?(method) | ||
@PFUser.send(method, *args, &block) | ||
else | ||
super | ||
end | ||
end | ||
|
||
def fields | ||
self.class.send(:get_fields) | ||
end | ||
|
||
module ClassMethods | ||
def fields(*args) | ||
args.each {|arg| field(arg)} | ||
end | ||
|
||
def field(name) | ||
@fields | ||
end | ||
|
||
def get_fields | ||
@fields ||= [] | ||
@fields | ||
end | ||
|
||
def all | ||
query = PFQuery.queryForUser | ||
users = query.findObjects | ||
users | ||
end | ||
end | ||
|
||
def self.included(base) | ||
base.extend(ClassMethods) | ||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
module ParseModel | ||
class Query < PFQuery | ||
|
||
def setClassObject(classObject) | ||
@classObject = classObject | ||
end | ||
|
||
def initWithClassNameAndClassObject(className, classObject:myClassObject) | ||
self.initWithClassName(className) | ||
self.setClassObject(myClassObject) | ||
self | ||
end | ||
|
||
def find(&block) | ||
return self.findObjects.map {|obj| @classObject.new(obj)} unless block_given? | ||
|
||
self.findObjectsInBackgroundWithBlock(lambda do |objects, error| | ||
objects = objects.map {|obj| @classObject.new(obj)} if objects | ||
block.call(objects, error) | ||
end) | ||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
module ParseModel | ||
VERSION = "0.0.1" | ||
VERSION = "0.0.2" | ||
end |