Class: RailsSettings::CachedSettings

Inherits:
Settings
  • Object
show all
Defined in:
lib/rails-settings/cached_settings.rb

Class Method Summary (collapse)

Instance Method Summary (collapse)

Methods inherited from Settings

[]=, destroy, get_all, merge!, method_missing, object, thing_scoped, #value, #value=, where

Class Method Details

+ (Object) [](var_name)



13
14
15
16
17
18
19
20
21
22
# File 'lib/rails-settings/cached_settings.rb', line 13

def self.[](var_name)
  cache_key = "settings:#{var_name}"
  obj = Rails.cache.read(cache_key)
  if obj == nil
    obj = super(var_name)
  end
  
  return @@defaults[var_name.to_s] if obj == nil
  obj
end

+ (Object) save_default(key, value)



24
25
26
27
# File 'lib/rails-settings/cached_settings.rb', line 24

def self.save_default(key,value)
  return false if self.send(key) != nil
  self.send("#{key}=",value)
end

Instance Method Details

- (Object) expire_cache



9
10
11
# File 'lib/rails-settings/cached_settings.rb', line 9

def expire_cache
  Rails.cache.delete("settings:#{self.var}")
end

- (Object) rewrite_cache



4
5
6
# File 'lib/rails-settings/cached_settings.rb', line 4

def rewrite_cache
  Rails.cache.write("settings:#{self.var}", self.value)
end