Class: Rushiro::AccessControlHash
- Inherits:
-
Object
- Object
- Rushiro::AccessControlHash
- Defined in:
- lib/rushiro/access_control_hash.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#allows ⇒ Object
readonly
Returns the value of attribute allows.
-
#denies ⇒ Object
readonly
Returns the value of attribute denies.
-
#dirty ⇒ Object
readonly
Returns the value of attribute dirty.
-
#original ⇒ Object
readonly
Returns the value of attribute original.
Instance Method Summary collapse
-
#add_permission(perm) ⇒ Object
as string “allow|individual|domain(|action(|instance))”.
-
#initialize(hash) ⇒ AccessControlHash
constructor
A new instance of AccessControlHash.
- #permitted?(perm) ⇒ Boolean
-
#remove_permission(perm) ⇒ Object
as string “allow|individual|domain(|action(|instance))”.
- #serialize ⇒ Object
Constructor Details
#initialize(hash) ⇒ AccessControlHash
Returns a new instance of AccessControlHash.
6 7 8 9 10 11 |
# File 'lib/rushiro/access_control_hash.rb', line 6 def initialize(hash) @allows = AccessLevels.new(hash[:allows] || {}) @denies = AccessLevels.new(hash[:denies] || {}) @dirty = false @original = hash end |
Instance Attribute Details
#allows ⇒ Object (readonly)
Returns the value of attribute allows.
5 6 7 |
# File 'lib/rushiro/access_control_hash.rb', line 5 def allows @allows end |
#denies ⇒ Object (readonly)
Returns the value of attribute denies.
5 6 7 |
# File 'lib/rushiro/access_control_hash.rb', line 5 def denies @denies end |
#dirty ⇒ Object (readonly)
Returns the value of attribute dirty.
5 6 7 |
# File 'lib/rushiro/access_control_hash.rb', line 5 def dirty @dirty end |
#original ⇒ Object (readonly)
Returns the value of attribute original.
5 6 7 |
# File 'lib/rushiro/access_control_hash.rb', line 5 def original @original end |
Instance Method Details
#add_permission(perm) ⇒ Object
as string “allow|individual|domain(|action(|instance))”
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/rushiro/access_control_hash.rb', line 17 def (perm) #as string "allow|individual|domain(|action(|instance))" grant, rest = perm.split(GSEP, 2) case grant when 'allows' @allows.(rest) and @dirty = true when 'denies' @denies.(rest) and @dirty = true else raise ArgumentError.new("Could not add permission for type: #{grant} of #{perm}") end end |
#permitted?(perm) ⇒ Boolean
13 14 15 |
# File 'lib/rushiro/access_control_hash.rb', line 13 def permitted?(perm) # virtual end |
#remove_permission(perm) ⇒ Object
as string “allow|individual|domain(|action(|instance))”
29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/rushiro/access_control_hash.rb', line 29 def (perm) #as string "allow|individual|domain(|action(|instance))" grant, rest = perm.split(GSEP, 2) case grant when 'allows' @allows.(rest) and @dirty = true when 'denies' @denies.(rest) and @dirty = true else raise ArgumentError.new("Could not remove permission for type: #{grant} of #{perm}") end end |
#serialize ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/rushiro/access_control_hash.rb', line 41 def serialize unless @dirty @original else Hash[:allows, @allows.serialize, :denies, @denies.serialize] end end |