Class: AppData

Inherits:
Object
  • Object
show all
Defined in:
lib/pig-media-server/model/data.rb,
lib/pig-media-server/model/data_use_rdb.rb

Class Method Summary collapse

Class Method Details

.allObject



26
27
28
29
30
# File 'lib/pig-media-server/model/data.rb', line 26

def self.all
  Groonga['Datas'].select.to_a.map{|x|
    {key: x.original_key, value: parse(x.body)}
  }
end

.find(key) ⇒ Object



12
13
14
15
16
17
# File 'lib/pig-media-server/model/data.rb', line 12

def self.find key
  key = Digest::MD5.hexdigest(key)
  parse(Groonga['Datas'][key].body)
rescue
  nil
end

.parse(val) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/pig-media-server/model/data.rb', line 32

def self.parse val
  case val
  when 'true'
    true
  when 'false'
    false
  else
    JSON.parse val
  end

rescue
  if val.class == String
    val.gsub(/^"|"$/, '')
  else
    val
  end
end

.set(key, value) ⇒ Object



19
20
21
22
23
24
# File 'lib/pig-media-server/model/data.rb', line 19

def self.set key, value
  g_key = Digest::MD5.hexdigest(key)
  Groonga['Datas'].add g_key
  Groonga['Datas'][g_key].body = value.to_json
  Groonga['Datas'][g_key].original_key = key
end