Module: LeanMotion::User::ClassMethods
- Defined in:
- lib/lean_motion/user.rb
Instance Method Summary collapse
- #all(&block) ⇒ Object
- #count(&block) ⇒ Object
- #current_user ⇒ Object
- #field(name) ⇒ Object
- #fields(*args) ⇒ Object
- #first(&block) ⇒ Object
- #get_fields ⇒ Object
- #login(username, password, &block) ⇒ Object
- #order(hash) ⇒ Object
- #page(number, pagesize = 20) ⇒ Object
- #query ⇒ Object
- #where(hash) ⇒ Object
Instance Method Details
#all(&block) ⇒ Object
117 118 119 120 121 122 123 124 |
# File 'lib/lean_motion/user.rb', line 117 def all(&block) return AVUser.query.findObjects.map {|obj| self.new(obj)} unless block_given? AVUser.query.findObjectsInBackgroundWithBlock(lambda do |objects, error| objects = objects.map {|obj| self.new(obj)} if objects block.call(objects, error) end) end |
#count(&block) ⇒ Object
56 57 58 59 60 61 62 63 |
# File 'lib/lean_motion/user.rb', line 56 def count(&block) cloud_query = query return cloud_query.countObjects unless block_given? cloud_query.countObjectsInBackgroundWithBlock(lambda do |count, error| block.call(count, error) end) end |
#current_user ⇒ Object
107 108 109 110 111 112 113 114 115 |
# File 'lib/lean_motion/user.rb', line 107 def current_user if AVUser.currentUser u = new u.AVUser = AVUser.currentUser return u else return nil end end |
#field(name) ⇒ Object
102 103 104 105 |
# File 'lib/lean_motion/user.rb', line 102 def field(name) @fields ||= [] @fields << name end |
#fields(*args) ⇒ Object
98 99 100 |
# File 'lib/lean_motion/user.rb', line 98 def fields(*args) args.each {|arg| field(arg)} end |
#first(&block) ⇒ Object
70 71 72 73 74 75 76 77 |
# File 'lib/lean_motion/user.rb', line 70 def first(&block) cloud_query = query return cloud_query.getFirst unless block_given? cloud_query.getFirstObjectInBackgroundWithBlock(lambda do |object, error| block.call(object, error) end) end |
#get_fields ⇒ Object
126 127 128 |
# File 'lib/lean_motion/user.rb', line 126 def get_fields @fields end |
#login(username, password, &block) ⇒ Object
45 46 47 48 49 |
# File 'lib/lean_motion/user.rb', line 45 def login(username, password, &block) AVUser.logInWithUsernameInBackground(username, password:password, block:lambda do |user, error| block.call(user, error) end) end |
#order(hash) ⇒ Object
79 80 81 82 83 84 85 86 87 88 |
# File 'lib/lean_motion/user.rb', line 79 def order(hash) cloud_query = query key = hash.first[0] sort= hash.first[1] if sort == :asc cloud_query.orderByAscending(key) else cloud_query.orderByDescending(key) end end |
#page(number, pagesize = 20) ⇒ Object
90 91 92 93 94 95 96 |
# File 'lib/lean_motion/user.rb', line 90 def page(number, pagesize=20) number ||= 1 cloud_query = query cloud_query.limit = pagesize cloud_query.skip = (number - 1) * pagesize cloud_query end |
#query ⇒ Object
52 53 54 |
# File 'lib/lean_motion/user.rb', line 52 def query LeanMotion::CloudQuery.alloc.initWithClassNameAndClassObject('_User', classObject:self) end |
#where(hash) ⇒ Object
65 66 67 68 |
# File 'lib/lean_motion/user.rb', line 65 def where(hash) cloud_query = query cloud_query.findByHash(hash) end |