Sha256: b053fef6f9f4b009412802156c09f517b4fa892d3739be3463b65258b6857613
Contents?: true
Size: 918 Bytes
Versions: 2
Compression:
Stored size: 918 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
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
wlog-1.2.1 | lib/wlog/domain/key_value.rb |
wlog-1.2.0 | lib/wlog/domain/key_value.rb |