Sha256: 88cc4ecb28353d4975238b3d58f29239beaf4d018139980847ac06c681e4d273

Contents?: true

Size: 915 Bytes

Versions: 1

Compression:

Stored size: 915 Bytes

Contents

require 'active_record'
module Wlog
# An active record that stores keys with values. Keys and values are strings.
# convert as you need them.
#
# Note the behaviour on this; it's exactly like a ruby hash, so if you store
# a string 'jon' as a key with value '12', and then you store 'jon' with value
# '42', when looking up 'jon' you will retrieve only the latter (42).
#
# @author Simon Symeonidis
class KeyValue < ActiveRecord::Base

  # Insert a key in the storage. If exists, replace the value with new one
  # @return nil
  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

  # Get a certain value by key
  # @return the value given the key. nil if not found
  def self.get(key)
    ret = find_by_key(key)
    ret = ret ? ret.value : nil
  end

private
end
end # module Wlog

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
wlog-1.2.2 lib/wlog/domain/key_value.rb