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.
75 76 77 |
# File 'lib/ae_users.rb', line 75 def initialize @cache = {} end |
Instance Method Details
#invalidate(person, permissioned, permission) ⇒ Object
91 92 93 94 95 |
# File 'lib/ae_users.rb', line 91 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
97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/ae_users.rb', line 97 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
79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/ae_users.rb', line 79 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 |