Skip to content

Commit

Permalink
Added a "revisable_changes" column to the model being revised
Browse files Browse the repository at this point in the history
  Column records information generated from ActiveRecord's instance class "changes" on save
  • Loading branch information
bsimpson committed Jul 27, 2010
1 parent 32b7d3d commit bc0f537
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
Expand Up @@ -10,7 +10,8 @@ def manifest
["revisable_current_at", "datetime"],
["revisable_revised_at", "datetime"],
["revisable_deleted_at", "datetime"],
["revisable_is_current", "boolean", 1]
["revisable_is_current", "boolean", 1],
["revisable_changes", "string"]
]

m.migration_template 'migration.rb', 'db/migrate',
Expand Down
4 changes: 4 additions & 0 deletions lib/acts_as_revisable/acts/revisable.rb
Expand Up @@ -24,8 +24,10 @@ class << base
base.class_inheritable_hash :revisable_shared_objects
base.revisable_shared_objects = {}


base.instance_eval do
attr_accessor :revisable_new_params, :revisable_revision
serialize :revisable_changes

define_callbacks :before_revise, :after_revise, :before_revert, :after_revert, :before_changeset, :after_changeset, :after_branch_created

Expand Down Expand Up @@ -296,6 +298,7 @@ def save(*args) #:nodoc:
def before_revisable_create #:nodoc:
self[:revisable_is_current] = true
self.revision_number ||= 0
self.revisable_changes = self.changes
end

# Checks whether or not a +Revisable+ should be revised.
Expand All @@ -319,6 +322,7 @@ def before_revisable_update #:nodoc:
return false
end

self.revisable_changes = self.changes
self.revisable_revision = self.to_revision
end

Expand Down

0 comments on commit bc0f537

Please sign in to comment.