Sha256: c7a6a1fbb978bae25fc7a58f5ba7f1bbe4431664d81a68a92718720634746fb2

Contents?: true

Size: 959 Bytes

Versions: 1

Compression:

Stored size: 959 Bytes

Contents

module AppCache
  class SystemParam < ActiveRecord::Base
    validates_presence_of :param_code
    after_save :auto_cache_update

    def auto_cache_update
      if AppCache.storage
        params = AppCache::SystemParam.all.to_json
        AppCache.storage.del "system_params"
        AppCache.storage.set("system_params", params)
      end
    end

    def self.cache_update
      params = AppCache::SystemParam.all.to_json
      AppCache.storage.del "system_params"
      AppCache.storage.set("system_params", params)
    end

    def self.get_cache
      params = JSON.load AppCache.storage.get "system_params"
      params
    end

    def self.get_params_cache
      json = self.get_cache
      h = {}
      json.each do |sp|
        h.store(sp['param_code'], sp['param_value'])
      end
      return h
    end

    def self.get_param_value(key)
      params = self.get_params_cache
      param_val = params[key] || ''
      param_val
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
app_cache-0.1.0 app/models/app_cache/system_param.rb