Class: Smith::AclTypeCache
- Inherits:
-
Object
- Object
- Smith::AclTypeCache
- Includes:
- MurmurHash3, Singleton
- Defined in:
- lib/smith/messaging/acl_type_cache.rb
Instance Method Summary collapse
- #add(type) ⇒ Object
-
#clear! ⇒ Object
Clear the internal hashes.
-
#dump_hashes ⇒ Object
Dump the hashes hash.
-
#dump_types ⇒ Object
Dump the type hash.
- #get_by_hash(type) ⇒ Object
- #get_by_type(type) ⇒ Object
-
#include?(key, opts = {}) ⇒ Boolean
Look the key up in the cache.
-
#initialize ⇒ AclTypeCache
constructor
A new instance of AclTypeCache.
Constructor Details
#initialize ⇒ AclTypeCache
Returns a new instance of AclTypeCache.
13 14 15 |
# File 'lib/smith/messaging/acl_type_cache.rb', line 13 def initialize clear! end |
Instance Method Details
#add(type) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/smith/messaging/acl_type_cache.rb', line 17 def add(type) if @types[type] false else h = to_murmur32(type) @types[type] = h @hashes[h] = type @legacy_types_by_hash[type.to_s.split(/::/)[-1].snake_case] = type true end end |
#clear! ⇒ Object
Clear the internal hashes.
54 55 56 57 58 |
# File 'lib/smith/messaging/acl_type_cache.rb', line 54 def clear! @types = {} @hashes = {} @legacy_types_by_hash = {} end |
#dump_hashes ⇒ Object
Dump the hashes hash
66 67 68 |
# File 'lib/smith/messaging/acl_type_cache.rb', line 66 def dump_hashes @hashes end |
#dump_types ⇒ Object
Dump the type hash
61 62 63 |
# File 'lib/smith/messaging/acl_type_cache.rb', line 61 def dump_types @types end |
#get_by_hash(type) ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/smith/messaging/acl_type_cache.rb', line 29 def get_by_hash(type) if @hashes[type] @hashes[type] elsif @legacy_types_by_hash[type.to_s] @legacy_types_by_hash[type.to_s] end end |
#get_by_type(type) ⇒ Object
37 38 39 |
# File 'lib/smith/messaging/acl_type_cache.rb', line 37 def get_by_type(type) @types[type] end |
#include?(key, opts = {}) ⇒ Boolean
Look the key up in the cache. This defaults to the key being the hash. If :by_type => true is passed in as the second argument then it will perform the lookup in the type hash.
45 46 47 48 49 50 51 |
# File 'lib/smith/messaging/acl_type_cache.rb', line 45 def include?(key, opts={}) if opts[:by_type] !get_by_type(key).nil? else !get_by_hash(key).nil? end end |