16th Fri
dm-has-versions-0.1.0をリリース
DataMapper用のバージョン管理プラグイン、
dm-has-versions
をリリースしました。
dm-is-versionedというライブラリが既にあるのですが、Railsで慣れ親しんだacts_as_versionedと微妙に挙動が違うのと、revert_toやversion=ができないなど、細かいところが足りない感じがしたので作りました。
USAGE:
以下のコードをご覧の通りです。
ruby>>
class Story
include DataMapper::Resource
property :id, Integer, :serial => true
property :title, String
property :updated_at, DateTime
has_versions :ignore => [:updated_at]
end
Story.auto_upgrade!
story = Story.create(:title => 'hello')
story.version #=> 0
story.update_attributes :title => 'good night'
story.version #=> 1
story.title #=> 'good night'
story.version = 0
story.title #=> 'hello'
<<--
auto_upgrade!は最初に一回だけ必要です。
posted by
genki on Fri 16 Jan 2009 at 03:37 with 0 comments