Module: LeanMotion::User

Defined in:
lib/lean_motion/user.rb

Defined Under Namespace

Modules: ClassMethods

Constant Summary collapse

RESERVED_KEYS =
['username', 'password', 'email']

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/lean_motion/user.rb', line 15

def method_missing(method, *args, &block)
  if RESERVED_KEYS.include?("#{method}")
    @AVUser.send(method)
  elsif RESERVED_KEYS.map {|f| "#{f}="}.include?("#{method}")
    @AVUser.send(method, args.first)
  elsif fields.include?(method)
    @AVUser.objectForKey(method)
  elsif fields.map {|f| "#{f}="}.include?("#{method}")
    method = method.split("=")[0]
    @AVUser.setObject(args.first, forKey:method)
  elsif @AVUser.respond_to?(method)
    @AVUser.send(method, *args, &block)
  else
    super
  end
end

Instance Attribute Details

#AVUserObject

Returns the value of attribute AVUser.



3
4
5
# File 'lib/lean_motion/user.rb', line 3

def AVUser
  @AVUser
end

Class Method Details

.included(base) ⇒ Object



132
133
134
# File 'lib/lean_motion/user.rb', line 132

def self.included(base)
  base.extend(ClassMethods)
end

Instance Method Details

#fieldsObject



32
33
34
# File 'lib/lean_motion/user.rb', line 32

def fields
  self.class.send(:get_fields)
end

#initialize(av_user_object = nil) ⇒ Object



7
8
9
10
11
12
13
# File 'lib/lean_motion/user.rb', line 7

def initialize(av_user_object=nil)
  if av_user_object
    @AVUser = av_user_object
  else
    @AVUser = AVUser.user
  end
end

#sign(&block) ⇒ Object



36
37
38
39
40
41
# File 'lib/lean_motion/user.rb', line 36

def sign(&block)
  return true unless block_given?
  @AVUser.signUpInBackgroundWithBlock(lambda do |succeeded, error|
      block.call(succeeded, error)
  end)
end