Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/swanandp/simple_versioning
A vanilla versioning interface for active_record
https://github.com/swanandp/simple_versioning
Last synced: 3 months ago
JSON representation
A vanilla versioning interface for active_record
- Host: GitHub
- URL: https://github.com/swanandp/simple_versioning
- Owner: swanandp
- Created: 2011-03-28T10:22:19.000Z (almost 14 years ago)
- Default Branch: master
- Last Pushed: 2011-03-28T16:01:51.000Z (almost 14 years ago)
- Last Synced: 2024-09-30T14:09:54.310Z (3 months ago)
- Language: Ruby
- Homepage:
- Size: 475 KB
- Stars: 3
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.markdown
Awesome Lists containing this project
README
# simple_versioning for ActiveRecord
Simple versioning is a plain vanilla versioning support. It simply tracks all your attributes in a polymorphically associated model.
## Installation
In the Gemfile:
gem 'simple_versioning'
Next, generate a simple migration, call it anything you like, the content needs to be (I'll add a generator in a couple of days):
def self.up
create_table :versions do |t|
t.belongs_to :versioned, :polymorphic => true
t.text :yaml
t.integer :number
t.timestamps
end
change_table :versions do |t|
t.index [:versioned_id, :versioned_type]
t.index :number
t.index :created_at
end
end
def self.down
drop_table :versions
end## Example
To version an ActiveRecord model, simply add `track` to your class like so:
class User < ActiveRecord::Base
track
validates_presence_of :first_name, :last_name
def name
"#{first_name} #{last_name}"
end
end
Thats it!>> u = User.create(:first_name => "Yukihiro", :last_name => "Matsumoto")
=> #
>> u.version_number
=> 1
>> u.update_attribute(:last_name, "Matz")
=> true
>> u.name
=> "Yukihiro Matz"
>> u.version_number
=> 2
>> u.revert_to(1)
=> 1
>> u.name
=> "Yukihiro Matsumoto"
>> u.version_number
=> 1
>> u.save
=> true
>> u.version_number
=> 3
>> u.update_attribute(:last_name, "Matsumoto II")
=> true
>> u.name
=> "Yukihiro Matsumoto II"
>> u.version_number
=> 4### What is coming in 0.0.2
- Save without versioning
- Mutator methods### Thanks!
Thanks to [laserlemon](http://github.com/laserlemon "") and his [`vestal_versions`](https://github.com/laserlemon/vestal_versions "") gem!