Class: Arrthorizer::Privilege

Inherits:
Object
  • Object
show all
Defined in:
lib/arrthorizer/privilege.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attrs) ⇒ Privilege

Returns a new instance of Privilege.



5
6
7
8
9
10
11
12
13
# File 'lib/arrthorizer/privilege.rb', line 5

def initialize(attrs)
  @name = attrs[:name].to_s

  (attrs[:roles] || []).each do |role|
    self.make_accessible_to(role)
  end

  self.class.register(self)
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/arrthorizer/privilege.rb', line 3

def name
  @name
end

Class Method Details

.get(name_or_privilege) ⇒ Object



15
16
17
# File 'lib/arrthorizer/privilege.rb', line 15

def self.get(name_or_privilege)
  registry.fetch(name_or_privilege)
end

Instance Method Details

#accessible_to?(role) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/arrthorizer/privilege.rb', line 23

def accessible_to?(role)
  !!permitted_roles.fetch(role) { false }
end

#make_accessible_to(role) ⇒ Object



19
20
21
# File 'lib/arrthorizer/privilege.rb', line 19

def make_accessible_to(role)
  permitted_roles.add(role)
end

#permitted_rolesObject



27
28
29
# File 'lib/arrthorizer/privilege.rb', line 27

def permitted_roles
  @permitted_roles ||= Registry.new
end

#to_keyObject



31
32
33
# File 'lib/arrthorizer/privilege.rb', line 31

def to_key
  name
end