Class: Propensity::Preferences::StoreInstance

Inherits:
Object
  • Object
show all
Defined in:
app/models/propensity/preferences/store.rb

Direct Known Subclasses

Store

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeStoreInstance

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

#persistenceObject

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

Returns:

  • (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