Class: Parse::ACL

Inherits:
Object
  • Object
show all
Defined in:
lib/parse/acl.rb

Constant Summary collapse

READ_ONLY =
{'read' => true}
WRITE_ONLY =
{'write' => true}
READ_WRITE =
{'read' => true, 'write' => true}
NONE =
{}
PUBLIC =
'*'
PUBLIC_READ_ONLY =
self.new PUBLIC => READ_ONLY
PUBLIC_WRITE_ONLY =
self.new PUBLIC => WRITE_ONLY
PUBLIC_READ_WRITE =
self.new PUBLIC => READ_WRITE
PUBLIC_NONE =
self.new PUBLIC => NONE

Instance Method Summary collapse

Constructor Details

#initialize(hash = {}, &block) ⇒ ACL

Returns a new instance of ACL.



10
11
12
13
# File 'lib/parse/acl.rb', line 10

def initialize hash={}, &block
  @acl = hash.dup
  tap &block if block
end

Instance Method Details

#readable(user) ⇒ Object



15
16
17
# File 'lib/parse/acl.rb', line 15

def readable user
  (@acl[user] ||= {})['read'] = true
end

#readable?(user) ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/parse/acl.rb', line 19

def readable? user
  !!(@acl[user] ||= {})['read']
end

#to_json(*args) ⇒ Object



31
32
33
# File 'lib/parse/acl.rb', line 31

def to_json *args
  @acl.to_json
end

#writable(user) ⇒ Object



23
24
25
# File 'lib/parse/acl.rb', line 23

def writable user
  (@acl[user] ||= {})['write'] = true
end

#writable?(user) ⇒ Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/parse/acl.rb', line 27

def writable? user
  !!(@acl[user] ||= {})['write']
end