Class: KakaxiParse::Role

Inherits:
BaseModel show all
Defined in:
lib/kakaxi_parse/role.rb

Constant Summary

Constants inherited from BaseModel

BaseModel::DEFUALT_LIMIT

Instance Attribute Summary

Attributes inherited from BaseModel

#created_at, #id, #name, #updated_at

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseModel

all, #delete, demodulize, find, order, #save, #update

Constructor Details

#initialize(id: nil, name: nil, updated_at: nil, created_at: nil) ⇒ Role

Returns a new instance of Role.



3
4
5
6
7
8
9
10
# File 'lib/kakaxi_parse/role.rb', line 3

def initialize(
      id: nil,
      name: nil,
      updated_at: nil,
      created_at: nil
    )
  super(id, name, updated_at, created_at)
end

Class Method Details

.nameObject



16
17
18
# File 'lib/kakaxi_parse/role.rb', line 16

def self.name
  '_Role'
end

.short_nameObject



20
21
22
# File 'lib/kakaxi_parse/role.rb', line 20

def self.short_name
  'role'
end

.where(hash, limit: DEFUALT_LIMIT) ⇒ Object



12
13
14
# File 'lib/kakaxi_parse/role.rb', line 12

def self.where(hash, limit: DEFUALT_LIMIT)
  to_objects(super(self, hash, limit)) if valid_key?(hash)
end

Instance Method Details

#add_user(id) ⇒ Object



24
25
26
27
28
29
30
31
32
33
# File 'lib/kakaxi_parse/role.rb', line 24

def add_user(id)
  params = Datatype::AddRelation.new(User, [id]).to_hash
  result = API.new("classes/#{self.class.demodulize}/#{ self.id }", params: params).put
  if result.has_key? 'updatedAt'
    self.updated_at = DateTime.strptime(result['updatedAt'], '%Y-%m-%dT%H:%M:%S.%LZ')
    true
  else
    false
  end
end