Class: NCMB::Role

Inherits:
Object show all
Includes:
NCMB
Defined in:
lib/ncmb/role.rb

Constant Summary

Constants included from NCMB

API_VERSION, DOMAIN, SCRIPT_API_VERSION, SCRIPT_DOMAIN

Class Method Summary collapse

Instance Method Summary collapse

Methods included from NCMB

CurrentUser, initialize

Methods inherited from Object

#ClassName, #[], #call, #convert_params, #deletable?, #delete, #error, #fields, #method_missing, #path, #post, #put, #saved?, #set

Constructor Details

#initialize(name) ⇒ Role

Returns a new instance of Role.



7
8
9
10
11
12
13
14
15
16
# File 'lib/ncmb/role.rb', line 7

def initialize(name)
  if name.is_a? Hash
    @fields = name
  else
    @fields = {
      roleName: name
    }
  end
  @fields[:acl] = NCMB::Acl.new
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class NCMB::Object

Class Method Details

.find_or_create(name) ⇒ Object



18
19
20
21
22
23
# File 'lib/ncmb/role.rb', line 18

def self.find_or_create(name)
  d = NCMB::DataStore.new('role')
  d.path = NCMB::Role.new(name).base_path
  role = d.where('roleName', name).limit(1).get.first
  role ? NCMB::Role.new(role.fields) : NCMB::Role.new(name).save()
end

Instance Method Details

#base_pathObject



29
30
31
# File 'lib/ncmb/role.rb', line 29

def base_path
  path = "/#{@@client.api_version}/roles"
end

#nameObject



25
26
27
# File 'lib/ncmb/role.rb', line 25

def name
  "role:#{@fields[:roleName]}"
end