Class: ParseModel::Query

Inherits:
PFQuery
  • Object
show all
Defined in:
lib/ParseModel/query.rb

Instance Method Summary collapse

Instance Method Details

#count(&block) ⇒ Object



41
42
43
44
45
46
47
# File 'lib/ParseModel/query.rb', line 41

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

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

#find(&block) ⇒ Object



14
15
16
17
18
19
20
21
# File 'lib/ParseModel/query.rb', line 14

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

#get(id, &block) ⇒ Object



32
33
34
35
36
37
38
39
# File 'lib/ParseModel/query.rb', line 32

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

#getFirst(&block) ⇒ Object



23
24
25
26
27
28
29
30
# File 'lib/ParseModel/query.rb', line 23

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

#initWithClassNameAndClassObject(className, classObject: myClassObject) ⇒ Object



8
9
10
11
12
# File 'lib/ParseModel/query.rb', line 8

def initWithClassNameAndClassObject(className, classObject:myClassObject)
  self.initWithClassName(className)
  self.setClassObject(myClassObject)
  self
end

#setClassObject(classObject) ⇒ Object



4
5
6
# File 'lib/ParseModel/query.rb', line 4

def setClassObject(classObject)
  @classObject = classObject
end