Sha256: e6a0e075984657f1c47fcf65c4ce99ce045c2447d7eef74ab8b2726beea49eba

Contents?: true

Size: 1.33 KB

Versions: 2

Compression:

Stored size: 1.33 KB

Contents

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

    def getFirst(&block)
      return @classObject.new(self.getFirstObject) unless block_given?

      self.getFirstObjectInBackgroundWithBlock(lambda do |object, error|
        obj = @classObject.new(object) if object
        block.call(obj, error)
      end)
    end

    def get(id, &block)
      return @classObject.new(self.getObjectWithId(id)) unless block_given?

      self.getObjectInBackgroundWithId(id, block:lambda do |object, error|
        obj = @classObject.new(object) if object
        block.call(obj, error)
      end)
    end

    def count(&block)
      return self.countObjects unless block_given?

      self.countObjectsInBackgroundWithBlock(lambda do |count, error|
        block.call(count, error)
      end)
    end

  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ParseModel-0.0.5 lib/ParseModel/query.rb
ParseModel-0.0.4 lib/ParseModel/query.rb