Class: Rushiro::Permissions

Inherits:
Object
  • Object
show all
Defined in:
lib/rushiro/permissions.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(entries) ⇒ Permissions

Returns a new instance of Permissions.



4
5
6
7
8
# File 'lib/rushiro/permissions.rb', line 4

def initialize(entries)
  @permissions = entries.map do |permission|
    Permission.new(permission)
  end || []
end

Instance Attribute Details

#permissionsObject (readonly)

Returns the value of attribute permissions.



3
4
5
# File 'lib/rushiro/permissions.rb', line 3

def permissions
  @permissions
end

Instance Method Details

#add_permission(perm) ⇒ Object



15
16
17
18
19
20
# File 'lib/rushiro/permissions.rb', line 15

def add_permission(perm)
  to_add = Permission.new(perm)
  return false if @permissions.any?{|_p| _p == to_add}
  @permissions << to_add
  true
end

#permitted?(perm) ⇒ Boolean

Returns:

  • (Boolean)


10
11
12
13
# File 'lib/rushiro/permissions.rb', line 10

def permitted?(perm)
  return nil if @permissions.empty?
  @permissions.any? { |permission| permission.implied?(perm) }
end

#remove_permission(perm) ⇒ Object



22
23
24
# File 'lib/rushiro/permissions.rb', line 22

def remove_permission(perm)
  !!@permissions.delete(Permission.new(perm))
end

#serializeObject



26
27
28
# File 'lib/rushiro/permissions.rb', line 26

def serialize
  @permissions.map(&:serialize)
end