mongo_mapper_acts_as_versioned 0.0.12 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  Basic MongoMapper port of technoweenie's [acts_as_versioned](http://github.com/technoweenie/acts_as_versioned). Stores changed attributes in a Hash key inside an Embedded Document instead of copying all keys from the original model.
4
4
 
5
+ *Note:* This plugin is intended for MongoMapper 0.8.6. The plugin architecture must be slightly changed for it to work on 0.9+.
6
+
5
7
  ## Usage
6
8
 
7
9
  ### Basic Example
@@ -1,38 +1,39 @@
1
- require 'active_support/concern' unless defined?(ActiveSupport)
2
-
3
1
  module MongoMapper
4
2
  module Acts
5
3
  module Versioned
6
- extend ActiveSupport::Concern
7
-
8
- VERSION = '0.0.12'
4
+ VERSION = '0.1.0'
9
5
  CALLBACKS = [:save_version, :clear_old_versions]
10
6
 
11
- included do
12
- cattr_accessor :versioned_class_name, :non_versioned_keys, :max_version_limit
7
+ def self.configure(model)
8
+ model.class_eval do
9
+ cattr_accessor :versioned_class_name,
10
+ :non_versioned_keys, :max_version_limit
13
11
 
14
- self.versioned_class_name = :Version
15
- self.max_version_limit = 0
16
- self.non_versioned_keys = %w(
17
- _id _type created_at updated_at creator_id updater_id version
18
- )
12
+ self.versioned_class_name = :Version
13
+ self.max_version_limit = 0
14
+ self.non_versioned_keys = %w[
15
+ _id _type created_at updated_at
16
+ creator_id updater_id version
17
+ ]
19
18
 
20
- const_set(versioned_class_name, Class.new).class_eval do
21
- include MongoMapper::EmbeddedDocument
19
+ const_set(versioned_class_name, Class.new).class_eval do
20
+ include MongoMapper::EmbeddedDocument
22
21
 
23
- key :version, Integer
24
- key :modified, Hash
25
- end
22
+ key :version, Integer
23
+ key :modified, Hash
24
+ end
26
25
 
27
- many :versions, :class => "#{self}::#{versioned_class_name}".constantize do
28
- def [](version)
29
- detect { |doc| doc.version.to_s == version.to_s }
26
+ class_name = "#{self}::#{versioned_class_name}"
27
+ many :versions, :class => class_name.constantize do
28
+ def [](version)
29
+ detect { |doc| doc.version.to_s == version.to_s }
30
+ end
30
31
  end
31
- end
32
32
 
33
- key :version, Integer
34
- before_save :save_version
35
- before_save :clear_old_versions
33
+ key :version, Integer
34
+ before_save :save_version
35
+ before_save :clear_old_versions
36
+ end
36
37
  end
37
38
 
38
39
  module InstanceMethods
@@ -111,9 +112,10 @@ module MongoMapper
111
112
  protected
112
113
 
113
114
  def next_version
114
- new_record? || versions.empty? ? 1 : versions.map(&:version).max.next
115
+ new_record? || versions.empty? ?
116
+ 1 : versions.map(&:version).max.next
115
117
  end
116
- end
118
+ end # InstanceMethods
117
119
 
118
120
  module ClassMethods
119
121
  def versioned_class
@@ -124,6 +126,10 @@ module MongoMapper
124
126
  keys.keys - non_versioned_keys
125
127
  end
126
128
 
129
+ def do_not_version(*args)
130
+ self.non_versioned_keys = non_versioned_keys | args
131
+ end
132
+
127
133
  def without_revision
128
134
  class_eval do
129
135
  CALLBACKS.each do |attr_name|
@@ -139,7 +145,7 @@ module MongoMapper
139
145
  end
140
146
  end
141
147
  end
142
- end
143
- end
144
- end
145
- end
148
+ end # ClassMethods
149
+ end # Versioned
150
+ end # Acts
151
+ end # MongoMapper
@@ -7,8 +7,7 @@ describe MongoMapper::Acts::Versioned do
7
7
  include MongoMapper::Document
8
8
 
9
9
  plugin MongoMapper::Acts::Versioned
10
-
11
- self.non_versioned_keys << 'depth'
10
+ do_not_version 'depth'
12
11
 
13
12
  key :title, String
14
13
  key :depth, Integer
@@ -1,4 +1,6 @@
1
1
  require 'mongo_mapper'
2
+ require 'mongo_mapper/version'
3
+ puts MongoMapper::Version
2
4
  require 'rspec'
3
5
  require File.expand_path('../../lib/acts_as_versioned', __FILE__)
4
6
 
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: mongo_mapper_acts_as_versioned
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.12
5
+ version: 0.1.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - Gigamo