Class: Controlist::Permissions::OrderedPackage
- Inherits:
-
Object
- Object
- Controlist::Permissions::OrderedPackage
- Defined in:
- lib/controlist/permissions/ordered_package.rb
Instance Attribute Summary collapse
-
#list_create ⇒ Object
readonly
Returns the value of attribute list_create.
-
#list_delete ⇒ Object
readonly
Returns the value of attribute list_delete.
-
#list_read ⇒ Object
readonly
Returns the value of attribute list_read.
-
#list_update ⇒ Object
readonly
Returns the value of attribute list_update.
-
#permissions ⇒ Object
readonly
Returns the value of attribute permissions.
Instance Method Summary collapse
- #add_permissions(*permissions) ⇒ Object
- #has_permission(klass, operation) ⇒ Object
-
#initialize(*permissions) ⇒ OrderedPackage
constructor
A new instance of OrderedPackage.
- #remove_permissions(*permissions) ⇒ Object
Constructor Details
#initialize(*permissions) ⇒ OrderedPackage
Returns a new instance of OrderedPackage.
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/controlist/permissions/ordered_package.rb', line 8 def initialize(*) .compact! @list_create = {} @list_read = {} @list_update = {} @list_delete = {} @permissions = @permissions.freeze # avoid bypassing add_permissions/remove_permissions * end |
Instance Attribute Details
#list_create ⇒ Object (readonly)
Returns the value of attribute list_create.
6 7 8 |
# File 'lib/controlist/permissions/ordered_package.rb', line 6 def list_create @list_create end |
#list_delete ⇒ Object (readonly)
Returns the value of attribute list_delete.
6 7 8 |
# File 'lib/controlist/permissions/ordered_package.rb', line 6 def list_delete @list_delete end |
#list_read ⇒ Object (readonly)
Returns the value of attribute list_read.
6 7 8 |
# File 'lib/controlist/permissions/ordered_package.rb', line 6 def list_read @list_read end |
#list_update ⇒ Object (readonly)
Returns the value of attribute list_update.
6 7 8 |
# File 'lib/controlist/permissions/ordered_package.rb', line 6 def list_update @list_update end |
#permissions ⇒ Object (readonly)
Returns the value of attribute permissions.
6 7 8 |
# File 'lib/controlist/permissions/ordered_package.rb', line 6 def @permissions end |
Instance Method Details
#add_permissions(*permissions) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/controlist/permissions/ordered_package.rb', line 19 def (*) @permissions += @permissions.freeze .each do || operations = .operations add @list_create, if operations.nil? || operations.include?(CREATE) add @list_read, if operations.nil? || operations.include?(READ) add @list_update, if operations.nil? || operations.include?(UPDATE) add @list_delete, if operations.nil? || operations.include?(DELETE) end end |
#has_permission(klass, operation) ⇒ Object
43 44 45 46 47 48 |
# File 'lib/controlist/permissions/ordered_package.rb', line 43 def (klass, operation) = instance_variable_get("@list_#{operation}") if && ( = [klass]) .any?(&:is_allowed) end end |
#remove_permissions(*permissions) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/controlist/permissions/ordered_package.rb', line 31 def (*) @permissions -= @permissions.freeze .each do || operations = .operations remove @list_create, if operations.nil? || operations.include?(CREATE) remove @list_read, if operations.nil? || operations.include?(READ) remove @list_update, if operations.nil? || operations.include?(UPDATE) remove @list_delete, if operations.nil? || operations.include?(DELETE) end end |