mm-versionable 0.2.1 → 0.2.2

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/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 Dhruva Sagar
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -8,18 +8,23 @@ $ gem install mm-versionable
8
8
 
9
9
  Note on Patches/Pull Requests
10
10
  -----------------------------
11
- *Fork the project
12
- *Make your feature addition or bug fix.
13
- *Add tests for it. This is critical so that things dont break unintentionally.
14
- *Commit, do not make any changes in the rakefile, version, or history. (If you want to have your own version, that is fine but bump the version in a commit by itself so I can ignore it when I pull)
15
- *Send me a pull requests.
11
+ * Fork the project
12
+ * Make your feature addition or bug fix.
13
+ * Add tests for it. This is critical so that things dont break unintentionally.
14
+ * Commit, do not make any changes in the rakefile, version, or history. (If you want to have your own version, that is fine but bump the version in a commit by itself so I can ignore it when I pull)
15
+ * Send me a pull request.
16
16
 
17
17
  Usage
18
18
  -----
19
+ The following example should demonstrate how to use versioning well :
20
+
21
+ <pre>
19
22
  class Thing
20
23
  include MongoMapper::Document
21
24
 
22
- enable_versioning :limit => 20 #:limit here defines the size of the version history that will be loaded into memory
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
23
28
 
24
29
  key :name, String, :required => true
25
30
  key :date, Time
@@ -38,51 +43,59 @@ thing.versions_count
38
43
  #=> 2
39
44
 
40
45
  thing.versions
41
- #=> [#<Version _id: BSON::ObjectId('4cef96c4f61aa33621000002'), data: {"_id"=>BSON::ObjectId('4cef96c4f61aa33621000001'), "version_message"=>nil, "version_number"=>nil, "name"=>"Dhruva Sagar", "date"=>2010-11-26 11:15:16 UTC}, date: 2010-11-26 11:15:16 UTC, pos: 0, doc_id: "4cef96c4f61aa33621000001", message: nil, updater_id: nil>, #<Version _id: BSON::ObjectId('4cef96c4f61aa33621000003'), data: {"_id"=>BSON::ObjectId('4cef96c4f61aa33621000001'), "version_message"=>nil, "version_number"=>nil, "name"=>"Change Thing", "date"=>2010-11-26 11:15:16 UTC}, date: 2010-11-26 11:15:16 UTC, pos: 1, doc_id: "4cef96c4f61aa33621000001", message: nil, updater_id: nil>]
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;]
42
47
 
43
48
  thing.all_versions
44
- #=> #<Plucky::Query doc_id: "4cef96c4f61aa33621000001", sort: [["pos", -1]]>
49
+ #=&gt; #&lt;Plucky::Query doc_id: &quot;4cef96c4f61aa33621000001&quot;, sort: [[&quot;pos&quot;, -1]]&gt;
45
50
 
46
51
  thing.rollback(:first)
47
- #=> #<Thing _id: BSON::ObjectId('4cef96c4f61aa33621000001'), version_message: nil, version_number: 0, name: "Dhruva Sagar", date: 2010-11-26 11:15:16 UTC>
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;
48
53
 
49
54
  thing.rollback(:last)
50
- #=> #<Thing _id: BSON::ObjectId('4cef96c4f61aa33621000001'), version_message: nil, version_number: 0, name: "Dhruva Sagar", date: 2010-11-26 11:15:16 UTC>
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;
51
56
 
52
57
  thing.rollback!(:latest)
53
- #=> #<Thing _id: BSON::ObjectId('4cef96c4f61aa33621000001'), version_message: nil, version_number: 1, name: "Change Thing", date: 2010-11-26 11:15:16 UTC>
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;
54
59
  #rollback! saves the document as well
55
60
 
56
61
  thing.diff(:name, 0, 1)
57
- #=> "<del class=\"differ\">Change</del><ins class=\"differ\">Dhruva</ins> <del class=\"differ\">Thing</del><ins class=\"differ\">Sagar</ins>"
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;
58
63
 
59
64
  thing.diff(:name, 0, 1, :ascii)
60
- #=> "{\"Change\" >> \"Dhruva\"} {\"Thing\" >> \"Sagar\"}"
65
+ #=&gt; &quot;{\&quot;Change\&quot; &gt;&gt; \&quot;Dhruva\&quot;} {\&quot;Thing\&quot; &gt;&gt; \&quot;Sagar\&quot;}&quot;
66
+
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;
61
69
 
62
70
  thing.current_version
63
- #=> "\e[31mChange\e[0m\e[32mDhruva\e[0m \e[31mThing\e[0m\e[32mSagar\e[0m"
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;
64
72
 
65
73
  thing.version_at(:first)
66
- #=> #<Version _id: BSON::ObjectId('4cef96c4f61aa33621000002'), data: {"_id"=>BSON::ObjectId('4cef96c4f61aa33621000001'), "version_message"=>nil, "version_number"=>nil, "name"=>"Dhruva Sagar", "date"=>2010-11-26 11:15:16 UTC}, date: 2010-11-26 11:15:16 UTC, pos: 0, doc_id: "4cef96c4f61aa33621000001", message: nil, updater_id: nil>
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;
67
75
 
68
76
  thing.version_at(:current)
69
- #=> #<Version _id: BSON::ObjectId('4cef986df61aa33621000004'), data: {"_id"=>BSON::ObjectId('4cef96c4f61aa33621000001'), "version_message"=>nil, "version_number"=>1, "name"=>"Change Thing", "date"=>2010-11-26 11:15:16 UTC}, date: 2010-11-26 11:22:21 UTC, pos: nil, doc_id: "4cef96c4f61aa33621000001", message: nil, updater_id: nil>
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;
70
78
 
71
79
  thing.version_at(:last)
72
- #=> #<Version _id: BSON::ObjectId('4cef96c4f61aa33621000002'), data: {"_id"=>BSON::ObjectId('4cef96c4f61aa33621000001'), "version_message"=>nil, "version_number"=>nil, "name"=>"Dhruva Sagar", "date"=>2010-11-26 11:15:16 UTC}, date: 2010-11-26 11:15:16 UTC, pos: 0, doc_id: "4cef96c4f61aa33621000001", message: nil, updater_id: nil>
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;
73
81
 
74
82
  thing.version_at(:latest)
75
- #=> #<Version _id: BSON::ObjectId('4cef96c4f61aa33621000003'), data: {"_id"=>BSON::ObjectId('4cef96c4f61aa33621000001'), "version_message"=>nil, "version_number"=>nil, "name"=>"Change Thing", "date"=>2010-11-26 11:15:16 UTC}, date: 2010-11-26 11:15:16 UTC, pos: 1, doc_id: "4cef96c4f61aa33621000001", message: nil, updater_id: nil>
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;
76
84
 
77
85
  thing.version_at(10)
78
86
  #=> nil
87
+ </pre>
79
88
 
80
89
  Problems or Questions?
81
90
  ----------------------
82
- Hit up on the mongomapper google group: http://groups.google.com/group/mongomapper
83
- Hop on IRC: irc://chat.freenode.net/#mongomapper
91
+ Hit up on the mongomapper google group:
92
+ http://groups.google.com/group/mongomapper
93
+
94
+ Hop on IRC:
95
+ irc://chat.freenode.net/#mongomapper
96
+
84
97
  I am available on IRC with the name dhruvasagar, you could alternatively also contact me directly on dhruva.sagar@gmail.com
85
98
 
86
99
  Copyright
87
100
  ---------
88
- See LICENCE for details.
101
+ See LICENSE for details.
@@ -3,8 +3,8 @@ class Version
3
3
 
4
4
  key :data, Hash
5
5
  key :date, Time
6
- key :pos, Integer
7
- key :doc_id, String
6
+ key :pos, Integer, :index => true
7
+ key :doc_id, String, :index => true
8
8
  key :message, String
9
9
  key :updater_id, String
10
10
 
@@ -32,9 +32,16 @@ module Versionable
32
32
  def enable_versioning(opts={})
33
33
  attr_accessor :rolling_back
34
34
 
35
- key :version_message, String
36
35
  key :version_number, Integer
37
36
 
37
+ define_method(:version_message) do
38
+ @version_message
39
+ end
40
+
41
+ define_method(:version_message=) do |message|
42
+ @version_message = message
43
+ end
44
+
38
45
  define_method(:versions_count) do
39
46
  @versions_count ||= Version.count(:doc_id => self._id.to_s)
40
47
  end
@@ -1,3 +1,3 @@
1
1
  module Versionable
2
- Version = '0.2.1'
2
+ Version = '0.2.2'
3
3
  end
@@ -5,17 +5,19 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{mm-versionable}
8
- s.version = "0.2"
8
+ s.version = "0.2.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Dhruva Sagar"]
12
- s.date = %q{2010-11-26}
12
+ s.date = %q{2011-01-18}
13
13
  s.description = %q{A MongoMapper extension that enables document versionable}
14
14
  s.email = %q{dhruva.sagar@gmail.com}
15
15
  s.extra_rdoc_files = [
16
+ "LICENSE",
16
17
  "README.md"
17
18
  ]
18
19
  s.files = [
20
+ "LICENSE",
19
21
  "README.md",
20
22
  "Rakefile",
21
23
  "config.ru",
@@ -1 +1,3 @@
1
- MongoMapper.database = YAML.load(File.read('config/database.yml'))[ENV['RACK_ENV']]['database'] rescue 'versionable_test'
1
+ require 'mongo_mapper'
2
+
3
+ MongoMapper.database = YAML.load(File.read('test/config/database.yml'))[ENV['RACK_ENV']]['database'] rescue 'versionable_test'
@@ -6,7 +6,6 @@ MongoMapper.database = 'versionable_performance'
6
6
 
7
7
  class Foo
8
8
  include MongoMapper::Document
9
- plugin Versionable
10
9
 
11
10
  enable_versioning
12
11
 
@@ -17,13 +16,28 @@ class Foo
17
16
  end
18
17
  Foo.collection.remove
19
18
 
20
- Benchmark.bm(5) do |x|
19
+ class Bar
20
+ include MongoMapper::Document
21
+
22
+ key :approved, Boolean
23
+ key :count, Integer
24
+ key :approved_at, Time
25
+ key :expire_on, Date
26
+ end
27
+ Bar.collection.remove
28
+
29
+ Benchmark.bm(22) do |x|
21
30
  ids = []
22
- hhids = []
23
- x.report("write ") do
31
+ x.report("write with versioning ") do
24
32
  1000.times { |i| ids << Foo.create(:count => 0, :approved => true, :approved_at => Time.now, :expire_on => Date.today).id }
25
33
  end
26
- x.report("read ") do
34
+ x.report("write without versioning") do
35
+ 1000.times { |i| ids << Bar.create(:count => 0, :approved => true, :approved_at => Time.now, :expire_on => Date.today).id }
36
+ end
37
+ x.report("read with versioning ") do
27
38
  ids.each { |id| Foo.first(:id => id) }
28
39
  end
40
+ x.report("read without versioning ") do
41
+ ids.each { |id| Bar.first(:id => id) }
42
+ end
29
43
  end
data/test/test_helper.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  $LOAD_PATH.unshift('.') unless $LOAD_PATH.include?('.')
2
2
 
3
+ require 'test/config/config'
3
4
  require File.expand_path(File.dirname(__FILE__) + '/../lib/versionable')
4
5
 
5
6
  require 'pp'
@@ -8,8 +9,6 @@ require 'shoulda'
8
9
  require 'test/models/post'
9
10
  require 'test/models/user'
10
11
 
11
- require 'config/config'
12
-
13
12
  User.delete_all
14
13
  u = User.create(:fname => 'dhruva', :lname => 'sagar', :email => 'dhruva.sagar@gmail.com')
15
14
  u.fname = 'Dhruva'
@@ -8,6 +8,9 @@ class VersioningTest < Test::Unit::TestCase
8
8
  should 'respond to method version_message' do
9
9
  assert @user.respond_to?(:version_message)
10
10
  end
11
+ should 'respond to method version_message=' do
12
+ assert @user.respond_to?(:version_message=)
13
+ end
11
14
  should 'respond to method version_number' do
12
15
  assert @user.respond_to?(:version_number)
13
16
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 2
8
- - 1
9
- version: 0.2.1
8
+ - 2
9
+ version: 0.2.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - Dhruva Sagar
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-11-26 00:00:00 +05:30
17
+ date: 2011-01-18 00:00:00 +05:30
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -50,8 +50,10 @@ executables: []
50
50
  extensions: []
51
51
 
52
52
  extra_rdoc_files:
53
+ - LICENSE
53
54
  - README.md
54
55
  files:
56
+ - LICENSE
55
57
  - README.md
56
58
  - Rakefile
57
59
  - config.ru