Class: Preflex::PreferenceCache
- Inherits:
-
Object
- Object
- Preflex::PreferenceCache
- Defined in:
- app/models/preflex/preference_cache.rb
Class Method Summary collapse
Instance Method Summary collapse
- #for(klass, owner) ⇒ Object
-
#initialize ⇒ PreferenceCache
constructor
A new instance of PreferenceCache.
Constructor Details
#initialize ⇒ PreferenceCache
Returns a new instance of PreferenceCache.
3 4 5 |
# File 'app/models/preflex/preference_cache.rb', line 3 def initialize @cache = {} end |
Class Method Details
.current ⇒ Object
16 17 18 |
# File 'app/models/preflex/preference_cache.rb', line 16 def self.current Preflex::Current.preference_cache ||= new end |
.for(klass, owner) ⇒ Object
12 13 14 |
# File 'app/models/preflex/preference_cache.rb', line 12 def self.for(klass, owner) self.current.for(klass, owner) end |
Instance Method Details
#for(klass, owner) ⇒ Object
7 8 9 10 |
# File 'app/models/preflex/preference_cache.rb', line 7 def for(klass, owner) @cache[klass] ||= {} @cache[klass][owner] ||= klass.find_or_initialize_by(owner: owner) end |