Sha256: 166fe38c4b3d11d2354c1c2e9d814a45fb3de4bccf38da0baca1f78c747a65a7
Contents?: true
Size: 1.14 KB
Versions: 1
Compression:
Stored size: 1.14 KB
Contents
module ParseModel class 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
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
ParseModel-0.0.4 | lib/ParseModel/Model.rb |