DataMapper用のバージョン管理プラグイン、 dm-has-versions をリリースしました。

dm-is-versionedというライブラリが既にあるのですが、Railsで慣れ親しんだacts_as_versionedと微妙に挙動が違うのと、revert_toやversion=ができないなど、細かいところが足りない感じがしたので作りました。

USAGE:

以下のコードをご覧の通りです。

   1  class Story
   2    include DataMapper::Resource
   3          
   4    property :id, Integer, :serial => true
   5    property :title, String
   6    property :updated_at, DateTime
   7  
   8    has_versions :ignore => [:updated_at]
   9  end
  10  
  11  Story.auto_upgrade!
  12  
  13  story = Story.create(:title => 'hello')
  14  story.version #=> 0
  15  story.update_attributes :title => 'good night'
  16  story.version #=> 1
  17  story.title #=> 'good night'
  18  story.version = 0
  19  story.title #=> 'hello'

auto_upgrade!は最初に一回だけ必要です。

posted by Png genki on Fri 16 Jan 2009 at 03:42

Comments:

or Preview
Social Bookmarks
  • Delicious
  • B_entry1220
  • Clip_16_12_w
Services from s21g
twpro(ツイプロ)
Twitterプロフィールを快適検索
地価2009
土地の値段を調べてみよう
MyRestaurant
自分だけのレストラン手帳
Formula
ブログに数式を埋め込める数式コミュニティ