mm-versionable 0.2.4 → 0.2.5

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -18,73 +18,77 @@ Usage
18
18
  -----
19
19
  The following example should demonstrate how to use versioning well :
20
20
 
21
- <pre>
22
- class Thing
23
- include MongoMapper::Document
21
+ require 'mongo_mapper'
22
+ require 'config' # Since versionable defines it's own Version model and has a few indexes defined for the same,
23
+ # we need to load & configure mongo_mapper before we can load versionable.
24
+ require 'versionable'
25
+ # gem 'mm-versionable', :require => 'versionable' -- Put this in your Gemfile if you're using bundler
24
26
 
25
- enable_versioning :limit => 20
26
- #:limit here defines the size of the version history that will be loaded into memory,
27
- #By default, if not specified, the value is 10, if you wish to load all versions set it to 0
27
+ class Thing
28
+ include MongoMapper::Document
28
29
 
29
- key :name, String, :required => true
30
- key :date, Time
31
- end
30
+ enable_versioning :limit => 20
31
+ #:limit here defines the size of the version history that will be loaded into memory,
32
+ #By default, if not specified, the value is 10, if you wish to load all versions set it to 0
32
33
 
33
- thing = Thing.create(:name => 'Dhruva Sagar', :date => Time.now)
34
+ key :name, String, :required => true
35
+ key :date, Time
36
+ end
34
37
 
35
- thing.name = 'Change Thing'
36
- thing.save
38
+ thing = Thing.create(:name => 'Dhruva Sagar', :date => Time.now)
37
39
 
38
- #Alternatively you can also pass in a "updater_id" to the save method which will be saved within the version, this can be used to track who made changes
39
- #example :
40
- #thing.save :updater_id => "4cef9936f61aa33717000001"
40
+ thing.name = 'Change Thing'
41
+ thing.save
41
42
 
42
- thing.versions_count
43
- #=> 2
43
+ #Alternatively you can also pass in a "updater_id" to the save method which will be saved within the version, this can be used to track who made changes
44
+ #example :
45
+ #thing.save :updater_id => "4cef9936f61aa33717000001"
44
46
 
45
- thing.versions
46
- #=&gt; [#&lt;Version _id: BSON::ObjectId('4cef96c4f61aa33621000002'), data: {&quot;_id&quot;=&gt;BSON::ObjectId('4cef96c4f61aa33621000001'), &quot;version_message&quot;=&gt;nil, &quot;version_number&quot;=&gt;nil, &quot;name&quot;=&gt;&quot;Dhruva Sagar&quot;, &quot;date&quot;=&gt;2010-11-26 11:15:16 UTC}, date: 2010-11-26 11:15:16 UTC, pos: 0, doc_id: &quot;4cef96c4f61aa33621000001&quot;, message: nil, updater_id: nil&gt;, #&lt;Version _id: BSON::ObjectId('4cef96c4f61aa33621000003'), data: {&quot;_id&quot;=&gt;BSON::ObjectId('4cef96c4f61aa33621000001'), &quot;version_message&quot;=&gt;nil, &quot;version_number&quot;=&gt;nil, &quot;name&quot;=&gt;&quot;Change Thing&quot;, &quot;date&quot;=&gt;2010-11-26 11:15:16 UTC}, date: 2010-11-26 11:15:16 UTC, pos: 1, doc_id: &quot;4cef96c4f61aa33621000001&quot;, message: nil, updater_id: nil&gt;]
47
+ thing.versions_count
48
+ #=> 2
47
49
 
48
- thing.all_versions
49
- #=&gt; #&lt;Plucky::Query doc_id: &quot;4cef96c4f61aa33621000001&quot;, sort: [[&quot;pos&quot;, -1]]&gt;
50
+ thing.versions
51
+ #=&gt; [#&lt;Version _id: BSON::ObjectId('4cef96c4f61aa33621000002'), data: {&quot;_id&quot;=&gt;BSON::ObjectId('4cef96c4f61aa33621000001'), &quot;version_message&quot;=&gt;nil, &quot;version_number&quot;=&gt;nil, &quot;name&quot;=&gt;&quot;Dhruva Sagar&quot;, &quot;date&quot;=&gt;2010-11-26 11:15:16 UTC}, date: 2010-11-26 11:15:16 UTC, pos: 0, doc_id: &quot;4cef96c4f61aa33621000001&quot;, message: nil, updater_id: nil&gt;, #&lt;Version _id: BSON::ObjectId('4cef96c4f61aa33621000003'), data: {&quot;_id&quot;=&gt;BSON::ObjectId('4cef96c4f61aa33621000001'), &quot;version_message&quot;=&gt;nil, &quot;version_number&quot;=&gt;nil, &quot;name&quot;=&gt;&quot;Change Thing&quot;, &quot;date&quot;=&gt;2010-11-26 11:15:16 UTC}, date: 2010-11-26 11:15:16 UTC, pos: 1, doc_id: &quot;4cef96c4f61aa33621000001&quot;, message: nil, updater_id: nil&gt;]
50
52
 
51
- thing.rollback(:first)
52
- #=&gt; #&lt;Thing _id: BSON::ObjectId('4cef96c4f61aa33621000001'), version_message: nil, version_number: 0, name: &quot;Dhruva Sagar&quot;, date: 2010-11-26 11:15:16 UTC&gt;
53
+ thing.all_versions
54
+ #=&gt; #&lt;Plucky::Query doc_id: &quot;4cef96c4f61aa33621000001&quot;, sort: [[&quot;pos&quot;, -1]]&gt;
53
55
 
54
- thing.rollback(:last)
55
- #=&gt; #&lt;Thing _id: BSON::ObjectId('4cef96c4f61aa33621000001'), version_message: nil, version_number: 0, name: &quot;Dhruva Sagar&quot;, date: 2010-11-26 11:15:16 UTC&gt;
56
+ thing.rollback(:first)
57
+ #=&gt; #&lt;Thing _id: BSON::ObjectId('4cef96c4f61aa33621000001'), version_message: nil, version_number: 0, name: &quot;Dhruva Sagar&quot;, date: 2010-11-26 11:15:16 UTC&gt;
56
58
 
57
- thing.rollback!(:latest)
58
- #=&gt; #&lt;Thing _id: BSON::ObjectId('4cef96c4f61aa33621000001'), version_message: nil, version_number: 1, name: &quot;Change Thing&quot;, date: 2010-11-26 11:15:16 UTC&gt;
59
- #rollback! saves the document as well
59
+ thing.rollback(:last)
60
+ #=&gt; #&lt;Thing _id: BSON::ObjectId('4cef96c4f61aa33621000001'), version_message: nil, version_number: 0, name: &quot;Dhruva Sagar&quot;, date: 2010-11-26 11:15:16 UTC&gt;
60
61
 
61
- thing.diff(:name, 0, 1)
62
- #=&gt; &quot;&lt;del class=\&quot;differ\&quot;&gt;Change&lt;/del&gt;&lt;ins class=\&quot;differ\&quot;&gt;Dhruva&lt;/ins&gt; &lt;del class=\&quot;differ\&quot;&gt;Thing&lt;/del&gt;&lt;ins class=\&quot;differ\&quot;&gt;Sagar&lt;/ins&gt;&quot;
62
+ thing.rollback!(:latest)
63
+ #=&gt; #&lt;Thing _id: BSON::ObjectId('4cef96c4f61aa33621000001'), version_message: nil, version_number: 1, name: &quot;Change Thing&quot;, date: 2010-11-26 11:15:16 UTC&gt;
64
+ #rollback! saves the document as well
63
65
 
64
- thing.diff(:name, 0, 1, :ascii)
65
- #=&gt; &quot;{\&quot;Change\&quot; &gt;&gt; \&quot;Dhruva\&quot;} {\&quot;Thing\&quot; &gt;&gt; \&quot;Sagar\&quot;}&quot;
66
+ thing.diff(:name, 0, 1)
67
+ #=&gt; &quot;&lt;del class=\&quot;differ\&quot;&gt;Change&lt;/del&gt;&lt;ins class=\&quot;differ\&quot;&gt;Dhruva&lt;/ins&gt; &lt;del class=\&quot;differ\&quot;&gt;Thing&lt;/del&gt;&lt;ins class=\&quot;differ\&quot;&gt;Sagar&lt;/ins&gt;&quot;
66
68
 
67
- thing.diff(:name, 0, 1, :color)
68
- #=&gt; &quot;\e[31mChange\e[0m\e[32mDhruva\e[0m \e[31mThing\e[0m\e[32mSagar\e[0m&quot;
69
+ thing.diff(:name, 0, 1, :ascii)
70
+ #=&gt; &quot;{\&quot;Change\&quot; &gt;&gt; \&quot;Dhruva\&quot;} {\&quot;Thing\&quot; &gt;&gt; \&quot;Sagar\&quot;}&quot;
69
71
 
70
- thing.current_version
71
- #=&gt; #&lt;Version _id: BSON::ObjectId('4cf03822f61aa30fd8000004'), data: {&quot;_id&quot;=&gt;BSON::ObjectId('4cf03816f61aa30fd8000001'), &quot;version_message&quot;=&gt;nil, &quot;version_number&quot;=&gt;nil, &quot;name&quot;=&gt;&quot;Change Thing&quot;, &quot;date&quot;=&gt;2010-11-26 22:43:34 UTC}, date: 2010-11-26 22:43:46 UTC, pos: nil, doc_id: &quot;4cf03816f61aa30fd8000001&quot;, message: nil, updater_id: nil&gt;
72
+ thing.diff(:name, 0, 1, :color)
73
+ #=&gt; &quot;\e[31mChange\e[0m\e[32mDhruva\e[0m \e[31mThing\e[0m\e[32mSagar\e[0m&quot;
72
74
 
73
- thing.version_at(:first)
74
- #=&gt; #&lt;Version _id: BSON::ObjectId('4cef96c4f61aa33621000002'), data: {&quot;_id&quot;=&gt;BSON::ObjectId('4cef96c4f61aa33621000001'), &quot;version_message&quot;=&gt;nil, &quot;version_number&quot;=&gt;nil, &quot;name&quot;=&gt;&quot;Dhruva Sagar&quot;, &quot;date&quot;=&gt;2010-11-26 11:15:16 UTC}, date: 2010-11-26 11:15:16 UTC, pos: 0, doc_id: &quot;4cef96c4f61aa33621000001&quot;, message: nil, updater_id: nil&gt;
75
+ thing.current_version
76
+ #=&gt; #&lt;Version _id: BSON::ObjectId('4cf03822f61aa30fd8000004'), data: {&quot;_id&quot;=&gt;BSON::ObjectId('4cf03816f61aa30fd8000001'), &quot;version_message&quot;=&gt;nil, &quot;version_number&quot;=&gt;nil, &quot;name&quot;=&gt;&quot;Change Thing&quot;, &quot;date&quot;=&gt;2010-11-26 22:43:34 UTC}, date: 2010-11-26 22:43:46 UTC, pos: nil, doc_id: &quot;4cf03816f61aa30fd8000001&quot;, message: nil, updater_id: nil&gt;
75
77
 
76
- thing.version_at(:current)
77
- #=&gt; #&lt;Version _id: BSON::ObjectId('4cef986df61aa33621000004'), data: {&quot;_id&quot;=&gt;BSON::ObjectId('4cef96c4f61aa33621000001'), &quot;version_message&quot;=&gt;nil, &quot;version_number&quot;=&gt;1, &quot;name&quot;=&gt;&quot;Change Thing&quot;, &quot;date&quot;=&gt;2010-11-26 11:15:16 UTC}, date: 2010-11-26 11:22:21 UTC, pos: nil, doc_id: &quot;4cef96c4f61aa33621000001&quot;, message: nil, updater_id: nil&gt;
78
+ thing.version_at(:first)
79
+ #=&gt; #&lt;Version _id: BSON::ObjectId('4cef96c4f61aa33621000002'), data: {&quot;_id&quot;=&gt;BSON::ObjectId('4cef96c4f61aa33621000001'), &quot;version_message&quot;=&gt;nil, &quot;version_number&quot;=&gt;nil, &quot;name&quot;=&gt;&quot;Dhruva Sagar&quot;, &quot;date&quot;=&gt;2010-11-26 11:15:16 UTC}, date: 2010-11-26 11:15:16 UTC, pos: 0, doc_id: &quot;4cef96c4f61aa33621000001&quot;, message: nil, updater_id: nil&gt;
78
80
 
79
- thing.version_at(:last)
80
- #=&gt; #&lt;Version _id: BSON::ObjectId('4cef96c4f61aa33621000002'), data: {&quot;_id&quot;=&gt;BSON::ObjectId('4cef96c4f61aa33621000001'), &quot;version_message&quot;=&gt;nil, &quot;version_number&quot;=&gt;nil, &quot;name&quot;=&gt;&quot;Dhruva Sagar&quot;, &quot;date&quot;=&gt;2010-11-26 11:15:16 UTC}, date: 2010-11-26 11:15:16 UTC, pos: 0, doc_id: &quot;4cef96c4f61aa33621000001&quot;, message: nil, updater_id: nil&gt;
81
+ thing.version_at(:current)
82
+ #=&gt; #&lt;Version _id: BSON::ObjectId('4cef986df61aa33621000004'), data: {&quot;_id&quot;=&gt;BSON::ObjectId('4cef96c4f61aa33621000001'), &quot;version_message&quot;=&gt;nil, &quot;version_number&quot;=&gt;1, &quot;name&quot;=&gt;&quot;Change Thing&quot;, &quot;date&quot;=&gt;2010-11-26 11:15:16 UTC}, date: 2010-11-26 11:22:21 UTC, pos: nil, doc_id: &quot;4cef96c4f61aa33621000001&quot;, message: nil, updater_id: nil&gt;
81
83
 
82
- thing.version_at(:latest)
83
- #=&gt; #&lt;Version _id: BSON::ObjectId('4cef96c4f61aa33621000003'), data: {&quot;_id&quot;=&gt;BSON::ObjectId('4cef96c4f61aa33621000001'), &quot;version_message&quot;=&gt;nil, &quot;version_number&quot;=&gt;nil, &quot;name&quot;=&gt;&quot;Change Thing&quot;, &quot;date&quot;=&gt;2010-11-26 11:15:16 UTC}, date: 2010-11-26 11:15:16 UTC, pos: 1, doc_id: &quot;4cef96c4f61aa33621000001&quot;, message: nil, updater_id: nil&gt;
84
+ thing.version_at(:last)
85
+ #=&gt; #&lt;Version _id: BSON::ObjectId('4cef96c4f61aa33621000002'), data: {&quot;_id&quot;=&gt;BSON::ObjectId('4cef96c4f61aa33621000001'), &quot;version_message&quot;=&gt;nil, &quot;version_number&quot;=&gt;nil, &quot;name&quot;=&gt;&quot;Dhruva Sagar&quot;, &quot;date&quot;=&gt;2010-11-26 11:15:16 UTC}, date: 2010-11-26 11:15:16 UTC, pos: 0, doc_id: &quot;4cef96c4f61aa33621000001&quot;, message: nil, updater_id: nil&gt;
84
86
 
85
- thing.version_at(10)
86
- #=> nil
87
- </pre>
87
+ thing.version_at(:latest)
88
+ #=&gt; #&lt;Version _id: BSON::ObjectId('4cef96c4f61aa33621000003'), data: {&quot;_id&quot;=&gt;BSON::ObjectId('4cef96c4f61aa33621000001'), &quot;version_message&quot;=&gt;nil, &quot;version_number&quot;=&gt;nil, &quot;name&quot;=&gt;&quot;Change Thing&quot;, &quot;date&quot;=&gt;2010-11-26 11:15:16 UTC}, date: 2010-11-26 11:15:16 UTC, pos: 1, doc_id: &quot;4cef96c4f61aa33621000001&quot;, message: nil, updater_id: nil&gt;
89
+
90
+ thing.version_at(10)
91
+ #=> nil
88
92
 
89
93
  Problems or Questions?
90
94
  ----------------------
@@ -1,4 +1,4 @@
1
- require 'versionable/models/version'
1
+ autoload :Version, 'versionable/models/version'
2
2
 
3
3
  module Versionable
4
4
  extend ActiveSupport::Concern
@@ -1,3 +1,3 @@
1
1
  module Versionable
2
- VERSION = '0.2.4'
2
+ VERSION = '0.2.5'
3
3
  end
data/test/test_helper.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  $LOAD_PATH.unshift('.') unless $LOAD_PATH.include?('.')
2
2
 
3
- require 'test/config/config'
4
3
  require File.expand_path(File.dirname(__FILE__) + '/../lib/versionable')
4
+ require 'test/config/config'
5
5
 
6
6
  require 'pp'
7
7
  require 'shoulda'
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: mm-versionable
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.2.4
5
+ version: 0.2.5
6
6
  platform: ruby
7
7
  authors:
8
8
  - Dhruva Sagar
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-06-16 00:00:00 +05:30
13
+ date: 2011-06-18 00:00:00 +05:30
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency