Class: AeUsers::PermissionCache
- Inherits:
-
Object
- Object
- AeUsers::PermissionCache
- Defined in:
- lib/ae_users.rb
Instance Method Summary collapse
-
#initialize ⇒ PermissionCache
constructor
A new instance of PermissionCache.
- #invalidate(person, permissioned, permission) ⇒ Object
- #invalidate_all(options = {}) ⇒ Object
- #permitted?(person, permissioned, permission) ⇒ Boolean
Constructor Details
#initialize ⇒ PermissionCache
Returns a new instance of PermissionCache.
70 71 72 |
# File 'lib/ae_users.rb', line 70 def initialize @cache = {} end |
Instance Method Details
#invalidate(person, permissioned, permission) ⇒ Object
86 87 88 89 90 |
# File 'lib/ae_users.rb', line 86 def invalidate(person, , ) RAILS_DEFAULT_LOGGER.debug "Permission cache invalidating result for #{person}, #{}, #{}" pcache = person_cache(person) pcache.delete(pcache_key(, )) end |
#invalidate_all(options = {}) ⇒ Object
92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/ae_users.rb', line 92 def invalidate_all(={}) if [:person] RAILS_DEFAULT_LOGGER.debug "Permission cache invalidating all results for #{[:person]}" @cache.delete([:person]) elsif [:permission] and [:permissioned] RAILS_DEFAULT_LOGGER.debug "Permission cache invalidating all results for #{[:permissioned]}, #{[:permission]}" @cache.each_value do |pcache| pcache.delete(pcache_key([:permissioned], [:permission])) end else RAILS_DEFAULT_LOGGER.debug "Permission cache invalidating all results!" @cache = {} end end |
#permitted?(person, permissioned, permission) ⇒ Boolean
74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/ae_users.rb', line 74 def permitted?(person, , ) RAILS_DEFAULT_LOGGER.debug "Permission cache looking up result for #{person}, #{}, #{}" pcache = person_cache(person) key = pcache_key(, ) unless pcache.has_key?(key) RAILS_DEFAULT_LOGGER.debug "Cache miss! Loading uncached permission." pcache[key] = person.uncached_permitted?(, ) end RAILS_DEFAULT_LOGGER.debug "Result is #{pcache[key]}" return pcache[key] end |