Class: LeanMotion::CloudQuery
- Inherits:
-
AVQuery
- Object
- AVQuery
- LeanMotion::CloudQuery
- Defined in:
- lib/lean_motion/query.rb
Instance Method Summary collapse
- #compare(k, v) ⇒ Object
- #count(&block) ⇒ Object
- #destroy(&block) ⇒ Object
- #equal(k, v) ⇒ Object
- #find(&block) ⇒ Object
- #findByHash(hash) ⇒ Object
- #first(&block) ⇒ Object
- #get(id, &block) ⇒ Object
- #initWithClassNameAndClassObject(className, classObject: myClassObject) ⇒ Object
- #page(number, pagesize = 20) ⇒ Object
- #setClassObject(classObject) ⇒ Object
- #sort(hash) ⇒ Object
Instance Method Details
#compare(k, v) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/lean_motion/query.rb', line 40 def compare(k, v) type = v[0] value = v[1] case type when :gt, :greater self.whereKey(k, greaterThan: value) when :lt, :less self.whereKey(k, lessThan: value) when :gte, :greater_and_equal self.whereKey(k, greaterThanOrEqualTo: value) when :lte, :less_and_equal self.whereKey(k, lessThanOrEqualTo: value) when :bt, :between self.whereKey(k, greaterThan: v[1]) self.whereKey(k, lessThan: v[2]) end self end |
#count(&block) ⇒ Object
86 87 88 89 90 91 92 |
# File 'lib/lean_motion/query.rb', line 86 def count(&block) return self.countObjects unless block_given? self.countObjectsInBackgroundWithBlock(lambda do |count, error| block.call(count, error) end) end |
#destroy(&block) ⇒ Object
94 95 96 97 98 |
# File 'lib/lean_motion/query.rb', line 94 def destroy(&block) self.deleteAllInBackgroundWithBlock(lambda do |objects, error| block.call(objects, error) end) end |
#equal(k, v) ⇒ Object
30 31 32 33 34 35 36 37 38 |
# File 'lib/lean_motion/query.rb', line 30 def equal(k, v) if v.nil? self.whereKeyDoesNotExist(k) elsif v == :exist self.whereKeyExists(k) else self.whereKey(k, equalTo:v) end end |
#find(&block) ⇒ Object
59 60 61 62 63 64 65 66 |
# File 'lib/lean_motion/query.rb', line 59 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 |
#findByHash(hash) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/lean_motion/query.rb', line 16 def findByHash(hash) hash.each do |k, v| symbols = [:gt, :greater, :lt, :less, :gte, :greater_and_equal, :lte, :less_and_equal, :bt, :between] if v.class == Array && (symbols.include? v[0]) compare(k, v) else equal(k, v) end end self end |
#first(&block) ⇒ Object
68 69 70 71 72 73 74 75 |
# File 'lib/lean_motion/query.rb', line 68 def first(&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 |
#get(id, &block) ⇒ Object
77 78 79 80 81 82 83 84 |
# File 'lib/lean_motion/query.rb', line 77 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 |
#initWithClassNameAndClassObject(className, classObject: myClassObject) ⇒ Object
9 10 11 12 13 14 |
# File 'lib/lean_motion/query.rb', line 9 def initWithClassNameAndClassObject(className, classObject:myClassObject) @className = className self.initWithClassName(className) self.setClassObject(myClassObject) self end |
#page(number, pagesize = 20) ⇒ Object
100 101 102 103 104 105 |
# File 'lib/lean_motion/query.rb', line 100 def page(number, pagesize=20) number ||= 1 self.limit = pagesize self.skip = (number - 1) * pagesize self end |
#setClassObject(classObject) ⇒ Object
4 5 6 7 |
# File 'lib/lean_motion/query.rb', line 4 def setClassObject(classObject) @classObject = classObject self end |
#sort(hash) ⇒ Object
107 108 109 110 111 112 113 114 115 116 |
# File 'lib/lean_motion/query.rb', line 107 def sort(hash) key = hash.first[0] sort= hash.first[1] if sort == :asc self.orderByAscending(key) else self.orderByDescending(key) end self end |