Class: Jinx::UniquifierCache
- Includes:
- Singleton
- Defined in:
- lib/jinx/resource/uniquifier_cache.rb
Overview
A utility class to cache key value qualifiers.
Instance Method Summary collapse
-
#clear ⇒ Object
Clears all cache entries.
-
#get(obj, value) ⇒ String
Returns the unique value generated for the given object and value.
-
#initialize ⇒ UniquifierCache
constructor
A new instance of UniquifierCache.
Constructor Details
#initialize ⇒ UniquifierCache
Returns a new instance of UniquifierCache.
10 11 12 |
# File 'lib/jinx/resource/uniquifier_cache.rb', line 10 def initialize @cache = Jinx::LazyHash.new { Hash.new } end |
Instance Method Details
#clear ⇒ Object
Clears all cache entries.
30 31 32 |
# File 'lib/jinx/resource/uniquifier_cache.rb', line 30 def clear @cache.clear end |
#get(obj, value) ⇒ String
Returns the unique value generated for the given object and value. Successive calls to this method for domain objects of the same class and a given value return the same result.
25 26 27 |
# File 'lib/jinx/resource/uniquifier_cache.rb', line 25 def get(obj, value) @cache[obj.class][value] ||= StringUniquifier.uniquify(value) end |