Class: ParseModel::Query

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

Instance Method Summary collapse

Instance Method Details

#count(&block) ⇒ Object



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

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

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

#find(&block) ⇒ Object



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

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



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

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



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

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



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

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

#setClassObject(classObject) ⇒ Object



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

def setClassObject(classObject)
  @classObject = classObject
  self
end