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)



11
12
13
14
15
16
17
# File 'lib/rails-settings/cached_settings.rb', line 11

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

+ (Object) save_default(key, value)



19
20
21
22
23
# File 'lib/rails-settings/cached_settings.rb', line 19

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

Instance Method Details

- (Object) rewrite_cache



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

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