Permalink
Browse files

Version 0.9.3 from SVN to Git/GitHub

  • Loading branch information...
mmower committed Jan 28, 2008
0 parents commit 3d56171519d1c940f8a0bae1da99bc74ee3e1efa
45 CHANGES
@@ -0,0 +1,45 @@
+0.9.3 - 28-01-2008
+
+Fixed #version_number to versioned instances as a shortcut
+
+0.9.2 - 28-01-2008
+
+Fixed :exclude => :column now equivalent to :exclude => [:column]
+
+0.9.1 - 24-01-2008
+
+Improved implementation of revert_to_version with further tests.
+Provided clean aliases for methods in VersionProxy.
+
+0.9 - 24-01-2008
+
+Added an :exclude option (default: [])
+
+0.8 - 08-01-2008
+
+Added an :automatic option (default: true)
+
+0.7 - 04-01-2008
+
+The without_versioning method becomes with_versioning( exp )
+
+0.6 - 01-01-2008
+
+The default is now to keep all versions, specify :keep if you want to set a limit.
+Dropped the updated_at column from revisions as unnecessary.
+
+0.5 - 30-12-2007
+
+The revert_to_version call now takes an :except => [:name,:and,:so,:on] list of attributes whose value will not be reverted. The defautl is [:created_at,:updated_at].
+
+0.4 - 30-12-2007
+
+Changed some method names to reduce possibility of conflicts. Added more tests. Changed some method implementations w.r.t. empty versions to try and tease out a bug in production.
+
+0.3 - 30-12-2007
+
+Added versioning_enabled? and without_versioning( &block ) to allow save without a version being generated.
+
+0.2 - 30-12-2007
+
+Added a test & some documentation, shaved a yak or two
@@ -0,0 +1,20 @@
+Copyright (c) 2007 Matt Mower
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
129 README
@@ -0,0 +1,129 @@
+SimplyVersioned
+===============
+
+Release: 0.9.3
+Date: 28-01-2008
+Author: Matt Mower <self@mattmower.com>
+
+SimplyVersioned is a simple, non-invasive, approach to versioning ActiveRecord models.
+
+SimplyVersioned does not require any structural change to the models to be versioned and requires only one versions table to be created (a migration generator is supplied with the plugin) regardless of the number of models being versioned.
+
+The plugin introduces a 'Version' ActiveRecord model (that reflects changes to model attributes) to which versioned models are polymorphically associated. Version records store the model information as a YAML hash.
+
+SimplyVersioned meets a simple need for model versioning. If your needs are more complex maybe try Rick Olsen's acts_as_versioned (http://svn.techno-weenie.net/projects/plugins/acts_as_versioned/).
+
+SimplyVersioned is (so far) actively tested with Rails 2.0.2 and Ruby 1.8.6p111 on MacOSX.
+
+Usage
+=====
+
+1. Install the plugin
+
+ ./script/plugin install http://rubymatt.rubyforge.org/svn/simply_versioned
+
+2. Generate the migration
+
+ ./script/generate simply_versioned_migration
+
+ Note that the migration defaults to storing the version info in a TEXT field. On MySQL this will default to a
+ limit of 64K. If you are versioning particularly large models you will want to modify the migration to include
+ a :limit => n condition to promote the yaml column to a MEDIUMTEXT or (god forbid) a LONGTEXT.
+
+3. Create the versions table
+
+ rake db:migrate
+
+4. Annotate the models you want to version specifying how many versions to keep
+
+ class Thing < ActiveRecord::Base
+ simply_versioned :keep => 10
+ end
+
+ If you do not specify a limit then old versions are never automatically deleted. You can
+ manually delete them like this:
+
+ thing.versions.purge( 10 )
+
+ which would delete all the but the last ten versions.
+
+ If you want fine-grained control over when versions are created you can use:
+
+ class Thing < ActiveRecord::Base
+ simply_versioned :automatic => false
+ end
+
+ and new versions will no longer be created by default. You will then need to use
+ the with_versioning method to create a version.
+
+ Lastly you can control which columns will be versioned by specifying an exclude parameter.
+
+ class Thing < ActiveRecord::Base
+ simply_versioned :exclude => :awkward_column
+ end
+
+ or
+
+ class Thing < ActiveRecord::Base
+ simply_versioned :exclude => [:first_awkward_column,:second_awkward_column,...]
+ end
+
+ This may be helpful if you run into conflicts with other plugins which try to manage columns.
+
+5. Create versions
+
+ thing = Thing.create!( :foo => bar ) # creates v1
+ thing.foo = baz
+ thing.save! # creates v2
+
+ If you need to control whether a version is created or not, use #with_versioning. For example:
+
+ thing.with_versioning( false ) do |t|
+ t.save!
+ end
+
+ or, using the "magic pen" (http://dablog.rubypal.com/2007/2/18/the-magic-pens-of-ruby thanks hmj):
+
+ thing.with_versioning( false, &:save! )
+
+6. Find versions
+
+ thing.versions.each do |version| ... end
+ render :partial => 'thing_version', :collection => thing.versions
+ thing.versions.current
+ thing.versions.first
+ thing.versions.get( 3 )
+
+ To find a version number:
+
+ thing.version_number
+
+7. Revert to a previous version
+
+ thing.revert_to_version( 5 )
+
+ If a specific reversion needs to avoid overwriting some column values pass
+ an :except option, e.g.
+
+ thing.revert_to_version( 1, :except => [:name,:age] )
+
+ The revert_to_version method also takes an existing Version instance, e.g.
+
+ version = thing.versions.find( ... )
+ thing.revert_to_version( version )
+
+8. Traverse versions
+
+ thing.versions.current.previous
+ thing.versions.first.next
+
+9. Obtain a copy of a previous versioned model
+
+ thing.versions.first.model # => Instantiated Thing with versioned values
+
+Thanks to:
+
+ Josh Susser (http://blog.hasmanythrough.com/) for useful suggestions and feedback
+ Rick Olson (http://techno-weenie.net/) for all the many plugins whose code i've read
+
+Copyright (c) 2007 Matt Mower <self@mattmower.com> and released under the MIT license
@@ -0,0 +1,31 @@
+require 'rake'
+require 'rake/testtask'
+require 'rake/rdoctask'
+
+desc 'Default: run unit tests.'
+task :default => :test
+
+desc 'Test the simply_versioned plugin.'
+Rake::TestTask.new(:test) do |t|
+ t.libs << 'lib'
+ t.pattern = 'test/**/*_test.rb'
+ t.verbose = true
+end
+
+desc 'Generate documentation for the simply_versioned plugin.'
+Rake::RDocTask.new(:rdoc) do |rdoc|
+ rdoc.rdoc_dir = 'rdoc'
+ rdoc.title = 'SimplyVersioned'
+ rdoc.options << '--line-numbers' << '--inline-source'
+ rdoc.rdoc_files.include('README')
+ rdoc.rdoc_files.include('lib/**/*.rb')
+end
+
+desc 'Measures test coverage using rcov'
+task :rcov do
+ rm_f "coverage"
+ rm_f "coverage.data"
+ rcov = "rcov --rails --aggregate coverage.data --text-summary -Ilib"
+ system("#{rcov} --html #{Dir.glob('test/**/*_test.rb').join(' ')}")
+ system("open coverage/index.html") if PLATFORM['darwin']
+end
@@ -0,0 +1,11 @@
+class SimplyVersionedMigrationGenerator < Rails::Generator::Base
+ def manifest
+ record do |m|
+ m.migration_template 'migration.rb', 'db/migrate'
+ end
+ end
+
+ def file_name
+ "simply_versioned_migration"
+ end
+end
@@ -0,0 +1,18 @@
+class SimplyVersionedMigration < ActiveRecord::Migration
+
+ def self.up
+ create_table :versions do |t|
+ t.integer :versionable_id
+ t.string :versionable_type
+ t.integer :number
+ t.text :yaml
+ t.datetime :created_at
+ end
+
+ add_index :versions, [:versionable_id, :versionable_type]
+ end
+
+ def self.down
+ drop_table :versions
+ end
+end
@@ -0,0 +1 @@
+require 'simply_versioned'
@@ -0,0 +1 @@
+# Install hook code here
Oops, something went wrong.

0 comments on commit 3d56171

Please sign in to comment.