Module: ParseModel::User

Defined in:
lib/ParseModel/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



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/ParseModel/User.rb', line 11

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

Instance Attribute Details

#PFUserObject

Returns the value of attribute PFUser.



3
4
5
# File 'lib/ParseModel/User.rb', line 3

def PFUser
  @PFUser
end

Class Method Details

.included(base) ⇒ Object



58
59
60
# File 'lib/ParseModel/User.rb', line 58

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

Instance Method Details

#fieldsObject



28
29
30
# File 'lib/ParseModel/User.rb', line 28

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

#initializeObject



7
8
9
# File 'lib/ParseModel/User.rb', line 7

def initialize
  @PFUser = PFUser.user
end