Skip to content

Commit

Permalink
Extend active record concern for mm0.9.x
Browse files Browse the repository at this point in the history
  • Loading branch information
stengland committed Jun 3, 2011
1 parent e28dab1 commit ce26218
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
8 changes: 1 addition & 7 deletions lib/versionable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,4 @@
require 'mongo_mapper'
require 'versionable/plugins/versionable'

module VersionablePlugin
def self.included(model)
model.plugin Versionable
end
end

MongoMapper::Document.append_inclusions(VersionablePlugin)
MongoMapper::Document.plugin(Versionable)
6 changes: 4 additions & 2 deletions lib/versionable/plugins/versionable.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
require 'versionable/models/version'

module Versionable
extend ActiveSupport::Concern

module InstanceMethods
# Save new versions but only if the data changes
def save(options={})
Expand Down Expand Up @@ -70,7 +72,7 @@ def enable_versioning(opts={})
self.version_number = version.pos
self
end

define_method(:rollback!) do |pos = nil|
self.rollback(pos)

Expand Down Expand Up @@ -110,7 +112,7 @@ def enable_versioning(opts={})
index = self.versions.index {|v| v.pos == pos}
version = self.versions[index] if index
version ||= Version.first(:user_id => self._id.to_s, :pos => pos)
version
version
end
end
end
Expand Down

0 comments on commit ce26218

Please sign in to comment.