Module: Brown::ACLLookup
- Defined in:
- lib/brown/acl_lookup.rb
Class Method Summary collapse
- .clear! ⇒ Object
- .get_by_hash(type) ⇒ Object
- .get_by_type(type) ⇒ Object
- .hashes ⇒ Object
-
.include?(key, opts = {}) ⇒ Boolean
Look the key up in the cache.
-
.to_murmur32(type) ⇒ Object
Convert the name to a base 36 murmur hash.
Class Method Details
.clear! ⇒ Object
30 31 32 |
# File 'lib/brown/acl_lookup.rb', line 30 def clear! @hashes = nil end |
.get_by_hash(type) ⇒ Object
7 8 9 |
# File 'lib/brown/acl_lookup.rb', line 7 def get_by_hash(type) hashes[type] end |
.get_by_type(type) ⇒ Object
12 13 14 |
# File 'lib/brown/acl_lookup.rb', line 12 def get_by_type(type) to_murmur32(type) end |
.hashes ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'lib/brown/acl_lookup.rb', line 35 def hashes @hashes ||= begin map = ObjectSpace.each_object(Class).map do |k| [[to_murmur32(k), k], [k.to_s.split(/::/).last.snake_case, k]] end.flatten(1) Hash[map] end 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.
21 22 23 24 25 26 27 |
# File 'lib/brown/acl_lookup.rb', line 21 def include?(key, opts={}) if opts[:by_type] !get_by_type(key).nil? else !get_by_hash(key).nil? end end |
.to_murmur32(type) ⇒ Object
Convert the name to a base 36 murmur hash
48 49 50 |
# File 'lib/brown/acl_lookup.rb', line 48 def to_murmur32(type) MurmurHash3::V32.murmur3_32_str_hash(type.to_s).to_s(36) end |