Class: Wlog::KeyValue

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/wlog/domain/key_value.rb

Overview

Author:

  • Simon Symeonidis

Class Method Summary collapse

Class Method Details

.get(key) ⇒ Object

Get a certain value by key

Returns:

  • the value given the key. nil if not found



26
27
28
29
# File 'lib/wlog/domain/key_value.rb', line 26

def self.get(key)
  ret = find_by_key(key)
  ret = ret ? ret.value : nil
end

.put!(key, value) ⇒ Object

Insert a key in the storage. If exists, replace the value with new one

Returns:

  • nil



15
16
17
18
19
20
21
22
# File 'lib/wlog/domain/key_value.rb', line 15

def self.put!(key, value)
  if ret = KeyValue.find_by_key(key)
    ret.value = value
  else 
    ret = KeyValue.new(:key => key, :value => value)
  end
  ret.save
nil end