Class: Propensity::Preferences::StoreInstance
- Inherits:
-
Object
- Object
- Propensity::Preferences::StoreInstance
- Defined in:
- app/models/propensity/preferences/store.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#persistence ⇒ Object
Returns the value of attribute persistence.
Instance Method Summary collapse
- #delete(key) ⇒ Object
- #exist?(key) ⇒ Boolean
- #get(key) ⇒ Object
-
#initialize ⇒ StoreInstance
constructor
A new instance of StoreInstance.
- #set(key, value, type) ⇒ Object
Constructor Details
#initialize ⇒ StoreInstance
Returns a new instance of StoreInstance.
13 14 15 16 17 |
# File 'app/models/propensity/preferences/store.rb', line 13 def initialize @cache = Rails.cache @persistence = true load_preferences end |
Instance Attribute Details
#persistence ⇒ Object
Returns the value of attribute persistence.
11 12 13 |
# File 'app/models/propensity/preferences/store.rb', line 11 def persistence @persistence end |
Instance Method Details
#delete(key) ⇒ Object
33 34 35 36 |
# File 'app/models/propensity/preferences/store.rb', line 33 def delete(key) @cache.delete(key) destroy(key) end |
#exist?(key) ⇒ Boolean
24 25 26 |
# File 'app/models/propensity/preferences/store.rb', line 24 def exist?(key) Propensity::Preference.exists?(key: key) end |
#get(key) ⇒ Object
28 29 30 31 |
# File 'app/models/propensity/preferences/store.rb', line 28 def get(key) #@cache.read(key) Propensity::Preference.find_or_initialize_by(key: key).value end |
#set(key, value, type) ⇒ Object
19 20 21 22 |
# File 'app/models/propensity/preferences/store.rb', line 19 def set(key, value, type) @cache.write(key, value) persist(key, value, type) end |