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 +20 -0
- data/README.md +34 -21
- data/lib/versionable/models/version.rb +2 -2
- data/lib/versionable/plugins/versionable.rb +8 -1
- data/lib/versionable/version.rb +1 -1
- data/mm-versionable.gemspec +4 -2
- data/test/config/config.rb +3 -1
- data/test/performance/read_write.rb +19 -5
- data/test/test_helper.rb +1 -2
- data/test/unit/test_versioning.rb +3 -0
- metadata +5 -3
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
|
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
|
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
|
-
|
46
|
+
#=> [#<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>]
|
42
47
|
|
43
48
|
thing.all_versions
|
44
|
-
|
49
|
+
#=> #<Plucky::Query doc_id: "4cef96c4f61aa33621000001", sort: [["pos", -1]]>
|
45
50
|
|
46
51
|
thing.rollback(:first)
|
47
|
-
|
52
|
+
#=> #<Thing _id: BSON::ObjectId('4cef96c4f61aa33621000001'), version_message: nil, version_number: 0, name: "Dhruva Sagar", date: 2010-11-26 11:15:16 UTC>
|
48
53
|
|
49
54
|
thing.rollback(:last)
|
50
|
-
|
55
|
+
#=> #<Thing _id: BSON::ObjectId('4cef96c4f61aa33621000001'), version_message: nil, version_number: 0, name: "Dhruva Sagar", date: 2010-11-26 11:15:16 UTC>
|
51
56
|
|
52
57
|
thing.rollback!(:latest)
|
53
|
-
|
58
|
+
#=> #<Thing _id: BSON::ObjectId('4cef96c4f61aa33621000001'), version_message: nil, version_number: 1, name: "Change Thing", date: 2010-11-26 11:15:16 UTC>
|
54
59
|
#rollback! saves the document as well
|
55
60
|
|
56
61
|
thing.diff(:name, 0, 1)
|
57
|
-
|
62
|
+
#=> "<del class=\"differ\">Change</del><ins class=\"differ\">Dhruva</ins> <del class=\"differ\">Thing</del><ins class=\"differ\">Sagar</ins>"
|
58
63
|
|
59
64
|
thing.diff(:name, 0, 1, :ascii)
|
60
|
-
|
65
|
+
#=> "{\"Change\" >> \"Dhruva\"} {\"Thing\" >> \"Sagar\"}"
|
66
|
+
|
67
|
+
thing.diff(:name, 0, 1, :color)
|
68
|
+
#=> "\e[31mChange\e[0m\e[32mDhruva\e[0m \e[31mThing\e[0m\e[32mSagar\e[0m"
|
61
69
|
|
62
70
|
thing.current_version
|
63
|
-
|
71
|
+
#=> #<Version _id: BSON::ObjectId('4cf03822f61aa30fd8000004'), data: {"_id"=>BSON::ObjectId('4cf03816f61aa30fd8000001'), "version_message"=>nil, "version_number"=>nil, "name"=>"Change Thing", "date"=>2010-11-26 22:43:34 UTC}, date: 2010-11-26 22:43:46 UTC, pos: nil, doc_id: "4cf03816f61aa30fd8000001", message: nil, updater_id: nil>
|
64
72
|
|
65
73
|
thing.version_at(:first)
|
66
|
-
|
74
|
+
#=> #<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>
|
67
75
|
|
68
76
|
thing.version_at(:current)
|
69
|
-
|
77
|
+
#=> #<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>
|
70
78
|
|
71
79
|
thing.version_at(:last)
|
72
|
-
|
80
|
+
#=> #<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>
|
73
81
|
|
74
82
|
thing.version_at(:latest)
|
75
|
-
|
83
|
+
#=> #<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>
|
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:
|
83
|
-
|
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
|
101
|
+
See LICENSE for details.
|
@@ -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
|
data/lib/versionable/version.rb
CHANGED
data/mm-versionable.gemspec
CHANGED
@@ -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{
|
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",
|
data/test/config/config.rb
CHANGED
@@ -1 +1,3 @@
|
|
1
|
-
|
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
|
-
|
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
|
-
|
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("
|
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
|
-
-
|
9
|
-
version: 0.2.
|
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:
|
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
|