Class: NCMB::Acl

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

Constant Summary

Constants included from NCMB

API_VERSION, DOMAIN, SCRIPT_API_VERSION, SCRIPT_DOMAIN

Instance Method Summary collapse

Methods included from NCMB

CurrentUser, initialize

Constructor Details

#initialize(params = nil) ⇒ Acl



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

def initialize(params = nil)
  @fields = {'*': {
      read: true,
      write: true
    }
  }
  if params
    @fields = @fields.merge(params)
  end
end

Instance Method Details

#public(read_or_write, bol = true) ⇒ Object



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

def public(read_or_write, bol = true)
  @fields['*'.to_sym][read_or_write.to_sym] = bol
end

#role(role, read_or_write, value = true) ⇒ Object

:reek:DuplicateMethodCall { max_calls: 2 }



40
41
42
43
# File 'lib/ncmb/acl.rb', line 40

def role(role, read_or_write, value = true)
  @fields[role.name.to_sym] = {read: true, write: true} unless @fields[role.name.to_sym]
  @fields[role.name.to_sym][read_or_write.to_sym] = value
end

#to_json(a = "") ⇒ Object



18
19
20
21
22
23
24
25
26
27
# File 'lib/ncmb/acl.rb', line 18

def to_json(a = "")
  params = {}
  @fields.each do |key, value|
    params[key.to_sym] = {} if value[:read] || value[:write]
    [:read, :write].each do |name|
      params[key.to_sym][name] = true if value[name]
    end
  end
  params.to_json
end

#user(user, read_or_write, value = true) ⇒ Object

:reek:DuplicateMethodCall { max_calls: 2 }



34
35
36
37
# File 'lib/ncmb/acl.rb', line 34

def user(user, read_or_write, value = true)
  @fields[user.objectId.to_sym] = {read: true, write: true} unless @fields[user.objectId.to_sym]
  @fields[user.objectId.to_sym][read_or_write.to_sym] = value
end