Class: AppCache::SystemParam

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/app_cache/system_param.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.cache_updateObject



14
15
16
17
18
# File 'app/models/app_cache/system_param.rb', line 14

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

.get_cacheObject



20
21
22
23
# File 'app/models/app_cache/system_param.rb', line 20

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

.get_level_params(level_id) ⇒ Object



69
70
71
72
73
74
75
# File 'app/models/app_cache/system_param.rb', line 69

def self.get_level_params(level_id)
  if AppCache.storage
    self.get_level_params_cache(level_id)
  else
    self.get_level_params_db(level_id)
  end
end

.get_level_params_cache(level_id) ⇒ Object



34
35
36
37
38
39
40
41
42
43
# File 'app/models/app_cache/system_param.rb', line 34

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

.get_level_params_db(level_id) ⇒ Object



53
54
55
56
57
58
59
# File 'app/models/app_cache/system_param.rb', line 53

def self.get_level_params_db(level_id)
  h = {}
  AppCache::SystemParam.where(:param_level_id => level_id).each do |sp|
    h.store(sp.param_code, sp.param_value)
  end
  h
end

.get_param_value(key) ⇒ Object



77
78
79
80
81
# File 'app/models/app_cache/system_param.rb', line 77

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

.get_paramsObject



61
62
63
64
65
66
67
# File 'app/models/app_cache/system_param.rb', line 61

def self.get_params
  if AppCache.storage
    self.get_params_cache
  else
    self.get_params_db
  end
end

.get_params_cacheObject



25
26
27
28
29
30
31
32
# File 'app/models/app_cache/system_param.rb', line 25

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

.get_params_dbObject



45
46
47
48
49
50
51
# File 'app/models/app_cache/system_param.rb', line 45

def self.get_params_db
  h = {}
  AppCache::SystemParam.all.each do |sp|
    h.store(sp.param_code, sp.param_value)
  end
  h
end

Instance Method Details

#auto_cache_updateObject



6
7
8
9
10
11
12
# File 'app/models/app_cache/system_param.rb', line 6

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