Class: Permissable::PermissionsCache
- Inherits:
-
Object
- Object
- Permissable::PermissionsCache
- Defined in:
- lib/permissable/permissions_cache.rb
Instance Attribute Summary collapse
-
#_permissions ⇒ Object
Returns the value of attribute _permissions.
-
#_query_results ⇒ Object
Returns the value of attribute _query_results.
Instance Method Summary collapse
- #all ⇒ Object
- #exists? ⇒ Boolean
- #for_member(member) ⇒ Object
- #for_resource(resource) ⇒ Object
-
#initialize(permission_list) ⇒ PermissionsCache
constructor
A new instance of PermissionsCache.
- #with_permission_to(methods) ⇒ Object
Constructor Details
#initialize(permission_list) ⇒ PermissionsCache
Returns a new instance of PermissionsCache.
8 9 10 11 |
# File 'lib/permissable/permissions_cache.rb', line 8 def initialize() @_permissions = @_query_results = nil end |
Instance Attribute Details
#_permissions ⇒ Object
Returns the value of attribute _permissions.
5 6 7 |
# File 'lib/permissable/permissions_cache.rb', line 5 def @_permissions end |
#_query_results ⇒ Object
Returns the value of attribute _query_results.
6 7 8 |
# File 'lib/permissable/permissions_cache.rb', line 6 def _query_results @_query_results end |
Instance Method Details
#all ⇒ Object
44 45 46 47 48 |
# File 'lib/permissable/permissions_cache.rb', line 44 def all results = @_query_results || [] @_query_results = nil results end |
#exists? ⇒ Boolean
50 51 52 53 54 |
# File 'lib/permissable/permissions_cache.rb', line 50 def exists? results = @_query_results || [] @_query_results = nil !results.empty? end |
#for_member(member) ⇒ Object
13 14 15 16 17 18 19 20 21 |
# File 'lib/permissable/permissions_cache.rb', line 13 def for_member(member) arr = create_result_array @_query_results = arr.find_all do |perm| (member.key?(:member_type) ? true : perm.member_type == member[:member_type]) && [member[:member_id]].flatten.uniq.include?(perm.member_id) end return self end |
#for_resource(resource) ⇒ Object
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/permissable/permissions_cache.rb', line 23 def for_resource(resource) arr = create_result_array resource = Permissable.flatten_resource(resource) @_query_results = arr.find_all do |perm| [resource[:resource_id]].flatten.include?(perm.resource_id) && [resource[:resource_type]].flatten.include?(perm.resource_type) end return self end |
#with_permission_to(methods) ⇒ Object
34 35 36 37 38 39 40 41 42 |
# File 'lib/permissable/permissions_cache.rb', line 34 def (methods) arr = create_result_array @_query_results = arr.find_all do |perm| [methods].flatten.collect{ |m| m.to_s }.include?(perm.) end return self end |