Permalink
Browse files

repackage as a gem; Rails 3 compatible

  • Loading branch information...
1 parent ec437bd commit 49de967b90d0bb4a469888a849050aaf8bd7615a Brian Durand committed Jun 22, 2010
View
@@ -0,0 +1 @@
+pkg
View
@@ -1,4 +1,4 @@
-Copyright (c) 2007 Brian Durand
+Copyright (c) 2010 Brian Durand
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
@@ -1,6 +1,6 @@
= Acts As Revisionable
-This plugin can handle automatically keeping revisions of a model each time it is updated. It is intended to allow you to keep a history of changes that can be reviewed or restored. The functionality is very similar to that offered by the ActsAsVersioned[http://wiki.rubyonrails.org/rails/pages/ActsAsVersioned] plugin. However the implementation is quite different with several advantages for some applications. Associations revisions can be tracked from the main record and the storage implementation is simpler and requires less space from your database.
+This gem can handle automatically keeping revisions of a model each time it is updated. It is intended to allow you to keep a history of changes that can be reviewed or restored. This implementation has the advantages that it can track associations with a parent record and that it takes less space in the database to store the revisions.
To make any ActiveRecord model revisionable, simply declare acts_as_revisionable in the class definition. Revisions are only added when a record is updated, so newly created records don't have revisions. This is intentional to reduce the number of revisions that need to be kept. In many applications, the majority of records are created once and never edited and adding the revision on create ends up at least doubling your storage needs. The attributes of the original record are serialized and compressed for in the revision record to minimize the amount of disk space used. Finally, you can limit the number of associations that are kept at any one time by supplying a :limit option to the acts_as_revisionable statement:
@@ -41,14 +41,16 @@ If you are revisioning associations, you should always call restore_revision! in
== Serialization
-By default revisions are serialized using Ruby's Marshal class. This is the most reliable mechanism, but the least portable. As an alternative, you can specify :encoding => :yaml in the acts_as_revisionalbe options. This will store the data as YAML. There are some issues with the Ruby 1.8 YAML parser where some values are not deserialized properly, so only use this option if you really need the portability. You can specify :encoding => :xml to store the revisions as XML. This should work fine unless the record contains binary data.
+By default revisions are serialized using Ruby's Marshal class. This is the most reliable mechanism, but the least portable. As an alternative, you can specify <tt>:encoding => :yaml</tt> in the acts_as_revisionable options. This will store the data as YAML. There are some issues with the Ruby 1.8 YAML parser where some values are not deserialized properly, so only use this option if you really need the portability. You can also specify <tt>:encoding => :xml</tt> to store the revisions as XML. This should work fine unless the record contains binary data.
-== Migration
+== Setup
-Migrations are included in the migrations directory which must be run before using this plugin.
+To create the table structure for ActsAsRevisionable::RevisionRecord, simply add a migration to your project that calls
+
+ ActsAsRevisionable::RevisionRecord.create_table
== Destroying
-By default, the revision history of a record is destroyed along with the record, you could be at risk of losing your revision history. However, this plugin was developed as a companion to the ActsAsTrashable[http://actsastrashable.rubyforge.org/] plugin. With this plugin, you can store destroyed records for a set period along with all dependent associations. Both plugins use similar code and interfaces. It is recommended that you always use ActsAsTrashable along side of ActsAsRevisioned.
+By default, the revision history of a record is destroyed along with the record, you could be at risk of losing your revision history. However, this gem was developed as a companion to the acts_as_trashable[http://github.com/bdurand/acts_as_trashable] gem. With this gem, you can store destroyed records for a set period along with all dependent associations. Both gems use similar code and interfaces. It is recommended that you always use acts_as_trashable along side of acts_as_revisionable.
Alternatively, you can specify the :dependent => :keep in options of the acts_as_revisionable call to keep all the revisions after a record is destroyed.
View
@@ -1,20 +1,47 @@
+require 'rubygems'
require 'rake'
require 'rake/rdoctask'
-require 'spec/rake/spectask'
desc 'Default: run unit tests.'
task :default => :test
-desc 'Test the acts_as_revisionable plugin.'
-Spec::Rake::SpecTask.new(:test) do |t|
- t.spec_files = 'spec/**/*_spec.rb'
+begin
+ require 'spec/rake/spectask'
+ desc 'Test the gem.'
+ Spec::Rake::SpecTask.new(:test) do |t|
+ t.spec_files = FileList.new('spec/**/*_spec.rb')
+ end
+rescue LoadError
+ tast :test do
+ STDERR.puts "You must have rspec >= 1.3.0 to run the tests"
+ end
end
-desc 'Generate documentation for the acts_as_revisionable plugin.'
+desc 'Generate documentation for the gem.'
Rake::RDocTask.new(:rdoc) do |rdoc|
rdoc.rdoc_dir = 'rdoc'
- rdoc.title = 'Acts As Revisionable'
- rdoc.options << '--line-numbers' << '--inline-source'
- rdoc.rdoc_files.include('README')
+ rdoc.options << '--title' << 'Acts As Revisionable' << '--line-numbers' << '--inline-source' << '--main' << 'README.rdoc'
+ rdoc.rdoc_files.include('README.rdoc')
rdoc.rdoc_files.include('lib/**/*.rb')
end
+
+begin
+ require 'jeweler'
+ Jeweler::Tasks.new do |gem|
+ gem.name = "acts_as_revisionable"
+ gem.summary = %Q{ActiveRecord extension that provides revision support so that history can be tracked and changes can be reverted.}
+ gem.description = %Q(ActiveRecord extension that provides revision support so that history can be tracked and changes can be reverted. Emphasis for this plugin versus similar ones is including associations, saving on storage, and extensibility of the model.)
+ gem.email = "brian@embellishedvisions.com"
+ gem.homepage = "http://github.com/bdurand/acts_as_revisionable"
+ gem.authors = ["Brian Durand"]
+ gem.rdoc_options = ["--charset=UTF-8", "--main", "README.rdoc"]
+
+ gem.add_dependency('activerecord', '>= 2.2')
+ gem.add_development_dependency('sqlite3')
+ gem.add_development_dependency('rspec', '>= 1.3.0')
+ gem.add_development_dependency('jeweler')
+ end
+
+ Jeweler::GemcutterTasks.new
+rescue LoadError
+end
View
@@ -0,0 +1 @@
+1.0.3
@@ -0,0 +1,61 @@
+# Generated by jeweler
+# DO NOT EDIT THIS FILE DIRECTLY
+# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
+# -*- encoding: utf-8 -*-
+
+Gem::Specification.new do |s|
+ s.name = %q{acts_as_revisionable}
+ s.version = "1.0.3"
+
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
+ s.authors = ["Brian Durand"]
+ s.date = %q{2010-06-22}
+ s.description = %q{ActiveRecord extension that provides revision support so that history can be tracked and changes can be reverted. Emphasis for this plugin versus similar ones is including associations, saving on storage, and extensibility of the model.}
+ s.email = %q{brian@embellishedvisions.com}
+ s.extra_rdoc_files = [
+ "README.rdoc"
+ ]
+ s.files = [
+ "MIT-LICENSE",
+ "Rakefile",
+ "lib/acts_as_revisionable.rb",
+ "spec/acts_as_revisionable_spec.rb",
+ "spec/full_spec.rb",
+ "spec/revision_record_spec.rb",
+ "spec/spec_helper.rb"
+ ]
+ s.homepage = %q{http://github.com/bdurand/acts_as_revisionable}
+ s.rdoc_options = ["--charset=UTF-8", "--main", "README.rdoc"]
+ s.require_paths = ["lib"]
+ s.rubygems_version = %q{1.3.7}
+ s.summary = %q{ActiveRecord extension that provides revision support so that history can be tracked and changes can be reverted.}
+ s.test_files = [
+ "spec/acts_as_revisionable_spec.rb",
+ "spec/full_spec.rb",
+ "spec/revision_record_spec.rb",
+ "spec/spec_helper.rb"
+ ]
+
+ if s.respond_to? :specification_version then
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
+ s.specification_version = 3
+
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
+ s.add_runtime_dependency(%q<activerecord>, [">= 2.2"])
+ s.add_development_dependency(%q<sqlite3>, [">= 0"])
+ s.add_development_dependency(%q<rspec>, [">= 1.3.0"])
+ s.add_development_dependency(%q<jeweler>, [">= 0"])
+ else
+ s.add_dependency(%q<activerecord>, [">= 2.2"])
+ s.add_dependency(%q<sqlite3>, [">= 0"])
+ s.add_dependency(%q<rspec>, [">= 1.3.0"])
+ s.add_dependency(%q<jeweler>, [">= 0"])
+ end
+ else
+ s.add_dependency(%q<activerecord>, [">= 2.2"])
+ s.add_dependency(%q<sqlite3>, [">= 0"])
+ s.add_dependency(%q<rspec>, [">= 1.3.0"])
+ s.add_dependency(%q<jeweler>, [">= 0"])
+ end
+end
+
View
@@ -1 +0,0 @@
-ActiveRecord::Base.send(:include, ActsAsRevisionable)
@@ -1,5 +1,10 @@
+require 'active_record'
+require 'active_support/all'
+
module ActsAsRevisionable
+ autoload :RevisionRecord, File.expand_path('../acts_as_revisionable/revision_record', __FILE__)
+
def self.included (base)
base.extend(ActsMethods)
end
@@ -24,7 +29,7 @@ def acts_as_revisionable (options = {})
class_inheritable_reader(:acts_as_revisionable_options)
extend ClassMethods
include InstanceMethods
- has_many_options = {:as => :revisionable, :order => 'revision DESC'}
+ has_many_options = {:as => :revisionable, :order => 'revision DESC', :class_name => "ActsAsRevisionable::RevisionRecord"}
has_many_options[:dependent] = :destroy unless options[:dependent] == :keep
has_many :revision_records, has_many_options
alias_method_chain :update, :revision if options[:on_update]
@@ -183,5 +188,6 @@ def update_with_revision
end
end
end
-
end
+
+ActiveRecord::Base.send(:include, ActsAsRevisionable)
Oops, something went wrong.

0 comments on commit 49de967

Please sign in to comment.