madeleine

http://madeleine.sourceforge.net/
rubyでの Object Prevalence ライブラリ。
Object Prevalenceが何かということはよくわかっていません。
要はオブジェクトの永続化?オブジェクトの取得/セットのタイミングで自動的に永続化準備されて、実際の永続化は、take_snapshotを適当に発行すればよい、のかな?
Wikiページの保存や更新に使うとよさげかも。(ってWikiの妄想ばっかだな)

保存をYAMLでできるとこがポイント高いか。

簡単なサンプルを張りつけ。
んーこのサンプルだと、オブジェクトを一つしか保存してないなあ。複数保存したいときはどうするのだろ。

require 'madeleine'
 
class CountData
  attr_accessor :count
  def initialize
    @count = 0
  end
end
 
class CountInc
  def execute(data)
    data.count += 1
  end
end
 
class CountShow
  def execute(data)
    data.count
  end
end
 
m = SnapshotMadeleine.new('./test_storage') {
  CountData.new
}
 
Thread.start {
  loop {
    sleep 10
    m.take_snapshot
  }
}
 
while line = gets
  case line
  when /^inc/
     printf("count -> %d \n ", m.execute_command(CountInc.new))
  when /^show/
    printf("count: %d\n",m.execute_query(CountShow.new))
  end
end