Class: Arrthorizer::Privilege
- Inherits:
-
Object
- Object
- Arrthorizer::Privilege
- Defined in:
- lib/arrthorizer/privilege.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
Instance Method Summary collapse
- #accessible_to?(role) ⇒ Boolean
-
#initialize(attrs) ⇒ Privilege
constructor
A new instance of Privilege.
- #make_accessible_to(role) ⇒ Object
- #permitted_roles ⇒ Object
- #to_key ⇒ Object
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
#name ⇒ Object (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
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_roles ⇒ Object
27 28 29 |
# File 'lib/arrthorizer/privilege.rb', line 27 def permitted_roles @permitted_roles ||= Registry.new end |
#to_key ⇒ Object
31 32 33 |
# File 'lib/arrthorizer/privilege.rb', line 31 def to_key name end |