memories 0.3.0 → 0.3.1
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.markdown +46 -21
- data/lib/memories/base.rb +43 -0
- metadata +4 -6
- data/README.rdoc +0 -163
data/README.markdown
CHANGED
|
@@ -131,36 +131,61 @@ If you want to access the version instance of a milestone, simply use the "data"
|
|
|
131
131
|
By default, memories doesn't version attachments. If you'd like to version attachments, simply call the `remember_attachments!` class method in your
|
|
132
132
|
class definition:
|
|
133
133
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
134
|
+
class MyDoc < CouchRest::Model::Base
|
|
135
|
+
use_database MY_DB
|
|
136
|
+
include Memories
|
|
137
137
|
|
|
138
|
-
|
|
139
|
-
|
|
138
|
+
remember_attachments!
|
|
139
|
+
end
|
|
140
140
|
|
|
141
141
|
If you only want specific attachments versioned, pass
|
|
142
142
|
strings and/or regular expressions to this macro. Any attachments
|
|
143
143
|
with matching names will be versioned.
|
|
144
144
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
145
|
+
class HtmlPage < CouchRest::Model::Base
|
|
146
|
+
use_database MY_DB
|
|
147
|
+
include Memories
|
|
148
148
|
|
|
149
|
-
|
|
150
|
-
|
|
149
|
+
remember_attachments! "image.png", %r{stylesheets/.*}
|
|
150
|
+
end
|
|
151
151
|
|
|
152
152
|
## Accessing Previous Versions
|
|
153
153
|
|
|
154
154
|
You can access old versions of your document via the "versions" method; it will return a proxy with array-like and hash-like access to previous versions.
|
|
155
155
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
156
|
+
@doc.versions[1].instance # ==> returns version 1 of your document
|
|
157
|
+
@doc.versions[1].revision # ==> 'rev-1-jkfldsi32849032894032'
|
|
158
|
+
@doc.versions[1].version_number # ==> 1
|
|
159
|
+
@doc.versions['rev-1-kjfdsla3289430289432'].instance # ==> returns version 1 of your document
|
|
160
|
+
@doc.versions[1..7] # ==> returns version proxies 1 through 7 of your document
|
|
161
|
+
@doc.versions.count # ==> returns the number of versions of your document
|
|
162
|
+
@doc.versions.last # ==> returns a proxy for the latest version of your document
|
|
163
|
+
@doc.versions.first # ==> returns a proxy for the first version of your document
|
|
164
|
+
@doc.versions.each do |v|
|
|
165
|
+
puts v.instance.some_property
|
|
166
|
+
end
|
|
167
|
+
|
|
168
|
+
## Logical Revision Numbers
|
|
169
|
+
|
|
170
|
+
As of version 0.3.1, when you soft revert a document (#revert_to), you can access the logical revision and logical version numbers of that document.
|
|
171
|
+
|
|
172
|
+
For example, suppose you soft revert a document with 10 versions to version 2.
|
|
173
|
+
|
|
174
|
+
@doc.current_version # ==> 10
|
|
175
|
+
@doc.revert_to 2
|
|
176
|
+
|
|
177
|
+
When you ask the logical revision, you'll receive the revision number of version 2:
|
|
178
|
+
|
|
179
|
+
@doc.logical_revision #==> 'rev-2-kfdlsa432890432890432'
|
|
180
|
+
|
|
181
|
+
Similarly, the logical version number:
|
|
182
|
+
|
|
183
|
+
@doc.logical_version_number #==> 2
|
|
184
|
+
|
|
185
|
+
However, as soon as you save the document, the logical revision and logical version number will simply mirror those of the actual document
|
|
186
|
+
|
|
187
|
+
@doc.save
|
|
188
|
+
@doc.rev #==> '11-qwerty1234567890'
|
|
189
|
+
@doc.logical_revision #==> 'rev-11-qwerty1234567890'
|
|
190
|
+
@doc.logical_version_number #==> 11
|
|
191
|
+
|
data/lib/memories/base.rb
CHANGED
|
@@ -17,6 +17,8 @@ module Memories
|
|
|
17
17
|
base.before_update :add_version_attachment
|
|
18
18
|
base.after_save :decode_attachments
|
|
19
19
|
base.send :extend, ClassMethods
|
|
20
|
+
base.alias_method_chain :save, :destroying_logical_version_and_revision
|
|
21
|
+
base.alias_method_chain :save!, :destroying_logical_version_and_revision
|
|
20
22
|
end
|
|
21
23
|
|
|
22
24
|
module ClassMethods #:nodoc: all
|
|
@@ -313,6 +315,45 @@ module Memories
|
|
|
313
315
|
self.milestones.last
|
|
314
316
|
end
|
|
315
317
|
|
|
318
|
+
# When you soft revert a document, you can ask what the logical revision of it is.
|
|
319
|
+
# For example, suppose you soft revert a document with 10 versions to version 2.
|
|
320
|
+
# @doc.revert_to 2
|
|
321
|
+
# When you ask the logical revision, you'll receive the revision number of version 2:
|
|
322
|
+
# @doc.logical_revision #==> 'rev-2-kfdlsa432890432890432'
|
|
323
|
+
# However, as soon as you save the document, the logical_revision will simply mirror the actual revision
|
|
324
|
+
# @doc.save
|
|
325
|
+
# @doc.rev #==> '11-qwerty1234567890'
|
|
326
|
+
# @doc.logical_revision #==> 'rev-11-qwerty1234567890'
|
|
327
|
+
def logical_revision
|
|
328
|
+
@logical_revision || "rev-" + self.rev
|
|
329
|
+
end
|
|
330
|
+
|
|
331
|
+
# When you soft revert a document, you can ask what the logical version number of it is.
|
|
332
|
+
# For example, suppose you soft revert a document with 10 versions to version 2.
|
|
333
|
+
# @doc.revert_to 2
|
|
334
|
+
# When you ask the logical version number, you'll receive 2:
|
|
335
|
+
# @doc.logical_version_number #==> 2
|
|
336
|
+
# However, as soon as you save the document, the logical_revision will simply mirror the actual revision
|
|
337
|
+
# @doc.save
|
|
338
|
+
# @doc.current_version #==> 11
|
|
339
|
+
# @doc.logical_version_number #==> 11
|
|
340
|
+
def logical_version_number
|
|
341
|
+
@logical_version_number || self.current_version
|
|
342
|
+
end
|
|
343
|
+
|
|
344
|
+
def save_with_destroying_logical_version_and_revision
|
|
345
|
+
@logical_version_number = nil
|
|
346
|
+
@logical_revision = nil
|
|
347
|
+
save_without_destroying_logical_version_and_revision
|
|
348
|
+
end
|
|
349
|
+
|
|
350
|
+
def save_with_destroying_logical_version_and_revision!
|
|
351
|
+
@logical_version_number = nil
|
|
352
|
+
@logical_revision = nil
|
|
353
|
+
save_without_destroying_logical_version_and_revision!
|
|
354
|
+
end
|
|
355
|
+
|
|
356
|
+
|
|
316
357
|
private
|
|
317
358
|
def verify_milestone_exists(n)
|
|
318
359
|
raise StandardError, "This document does not have any milestones." if self.milestones.empty?
|
|
@@ -333,6 +374,8 @@ module Memories
|
|
|
333
374
|
if properties = JSON.parse(self.read_attachment(version_id version))
|
|
334
375
|
revert_attachments properties
|
|
335
376
|
self.update_attributes_without_saving properties
|
|
377
|
+
@logical_version_number = version
|
|
378
|
+
@logical_revision = self.version_id version
|
|
336
379
|
self.save if revert_type == :hard
|
|
337
380
|
end
|
|
338
381
|
end
|
metadata
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: memories
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
hash:
|
|
4
|
+
hash: 17
|
|
5
5
|
prerelease: false
|
|
6
6
|
segments:
|
|
7
7
|
- 0
|
|
8
8
|
- 3
|
|
9
|
-
-
|
|
10
|
-
version: 0.3.
|
|
9
|
+
- 1
|
|
10
|
+
version: 0.3.1
|
|
11
11
|
platform: ruby
|
|
12
12
|
authors:
|
|
13
13
|
- Matt Parker
|
|
@@ -16,7 +16,7 @@ autorequire:
|
|
|
16
16
|
bindir: bin
|
|
17
17
|
cert_chain: []
|
|
18
18
|
|
|
19
|
-
date: 2011-01-
|
|
19
|
+
date: 2011-01-15 00:00:00 -05:00
|
|
20
20
|
default_executable:
|
|
21
21
|
dependencies:
|
|
22
22
|
- !ruby/object:Gem::Dependency
|
|
@@ -44,9 +44,7 @@ extensions: []
|
|
|
44
44
|
|
|
45
45
|
extra_rdoc_files:
|
|
46
46
|
- README.markdown
|
|
47
|
-
- README.rdoc
|
|
48
47
|
files:
|
|
49
|
-
- README.rdoc
|
|
50
48
|
- lib/memories.rb
|
|
51
49
|
- lib/memories/annotation.rb
|
|
52
50
|
- lib/memories/attachment.rb
|
data/README.rdoc
DELETED
|
@@ -1,163 +0,0 @@
|
|
|
1
|
-
= Introduction
|
|
2
|
-
|
|
3
|
-
A simple gem for adding versioning to your CouchRest::Model::Base documents. When you update a document, the previous version gets
|
|
4
|
-
stored as an attachment on the document. This versioning strategy was originally created here: http://blog.couch.io/post/632718824/simple-document-versioning-with-couchdb
|
|
5
|
-
|
|
6
|
-
== Installation
|
|
7
|
-
|
|
8
|
-
$ gem install memories
|
|
9
|
-
|
|
10
|
-
== Documentation
|
|
11
|
-
|
|
12
|
-
Browse the documentation on rubydoc.info: http://rubydoc.info/gems/memories/frames
|
|
13
|
-
|
|
14
|
-
== How does it work?
|
|
15
|
-
|
|
16
|
-
Just "include Memories" in your "CouchRest::Model::Base" classes and let the auto-versioning begin.
|
|
17
|
-
|
|
18
|
-
=== Basic Versioning
|
|
19
|
-
|
|
20
|
-
Here's how basic versioning works. Every time you save your document, you get a new version. You have the ability to roll back to a previous version.
|
|
21
|
-
|
|
22
|
-
class Book < CouchRest::Model::Base
|
|
23
|
-
include Memories
|
|
24
|
-
use_database SOME_DATABASE
|
|
25
|
-
|
|
26
|
-
property :name
|
|
27
|
-
view_by :name
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
b = Book.create :name => "2001"
|
|
31
|
-
b.current_version #==> 1
|
|
32
|
-
b.name = "2001: A Space Odyssey"
|
|
33
|
-
b.save
|
|
34
|
-
b.current_version #==> 2
|
|
35
|
-
b.previous_version #==> 1
|
|
36
|
-
b.name #==> "2001: A Space Odyssey"
|
|
37
|
-
b.revert_to! 1
|
|
38
|
-
b.name #==> "2001"
|
|
39
|
-
b.current_version #==> 3
|
|
40
|
-
|
|
41
|
-
If you'd like to exclude certain properties from versioning, use the #forget class method:
|
|
42
|
-
|
|
43
|
-
class Book < CouchRest::Model::Base
|
|
44
|
-
include Memories
|
|
45
|
-
use_database SOME_DATABASE
|
|
46
|
-
|
|
47
|
-
forget :notes
|
|
48
|
-
|
|
49
|
-
property :name
|
|
50
|
-
property :notes
|
|
51
|
-
view_by :name
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
b = Book.create :name => "2001", :notes => "creating the book."
|
|
55
|
-
b.current_version #==> 1
|
|
56
|
-
b.name = "2001: A Space Odyssey"
|
|
57
|
-
b.notes += "updating the title. might ship today. 9/2/2010. MKP"
|
|
58
|
-
b.save
|
|
59
|
-
b.current_version #==> 2
|
|
60
|
-
b.previous_version #==> 1
|
|
61
|
-
p b.name #==> "2001: A Space Odyssey"
|
|
62
|
-
p b.notes # ==> "creating the book. updating the title. might ship today. 9/2/2010. MKP"
|
|
63
|
-
b.revert_to! 1
|
|
64
|
-
p b.name #==> "2001"
|
|
65
|
-
p b.notes # ==> "creating the book. updating the title. might ship today. 9/2/2010. MKP"
|
|
66
|
-
b.current_version #==> 3
|
|
67
|
-
|
|
68
|
-
If you'd like to explicitly define which properties to version, use the #remember method. It works just like #forget, but in reverse. Duh.
|
|
69
|
-
|
|
70
|
-
=== Milestones
|
|
71
|
-
|
|
72
|
-
As of version 0.2.0, Memories also supports milestones. Milestones are special versions that you want to flag in some way.
|
|
73
|
-
For example, suppose you were creating a content management system, and every time someone publishes an article to the website, you want to flag the version
|
|
74
|
-
they published as a milestone.
|
|
75
|
-
|
|
76
|
-
class Article < CouchRest::Model::Base
|
|
77
|
-
include Memories
|
|
78
|
-
use_database SOME_DATABASE
|
|
79
|
-
|
|
80
|
-
property :title
|
|
81
|
-
property :author
|
|
82
|
-
property :body
|
|
83
|
-
|
|
84
|
-
def publish!
|
|
85
|
-
# .... publishing logic
|
|
86
|
-
end
|
|
87
|
-
end
|
|
88
|
-
|
|
89
|
-
a = Article.create(
|
|
90
|
-
:title => "Memories gem makes versioning simple",
|
|
91
|
-
:author => "moonmaster9000",
|
|
92
|
-
:body => <<-ARTICLE
|
|
93
|
-
Check it out at http://github.com/moonmaster9000/memories
|
|
94
|
-
ARTICLE
|
|
95
|
-
)
|
|
96
|
-
a.save
|
|
97
|
-
a.publish!
|
|
98
|
-
a.current_version #==> 1
|
|
99
|
-
a.milestone! do
|
|
100
|
-
name "First publish."
|
|
101
|
-
notes "Passed all relevant editing. Signed off by moonmaster10000"
|
|
102
|
-
end
|
|
103
|
-
|
|
104
|
-
Notice that we annotated our milestone; we gave it a name, and some notes. You can annotate with whatever properties you desire. The annotation do block is entirely optional.
|
|
105
|
-
Now that we've created a milestone, let's inspect it:
|
|
106
|
-
|
|
107
|
-
a.milestones.count #==> 1
|
|
108
|
-
a.latest_milestone.version # ==> 1
|
|
109
|
-
a.latest_milestone.annotations.name ==> "First publish."
|
|
110
|
-
a.latest_milestone.annotations.notes ==> "Passed all relevant editing. Signed off by moonmaster 10000"
|
|
111
|
-
|
|
112
|
-
Now, let's imagine that we've made some more edits / saves to the document, but they don't get approved. Now we want to revert to the version the document was
|
|
113
|
-
at at the first milestone. How do we do that? Simple!
|
|
114
|
-
|
|
115
|
-
a.revert_to_milestone! 1
|
|
116
|
-
|
|
117
|
-
And now our document properties are back to the where they were when we first published the document.
|
|
118
|
-
|
|
119
|
-
If you want to access the version instance of a milestone, simply use the "data" method:
|
|
120
|
-
|
|
121
|
-
a.milestones.first.data.title #==> returns the "title" attribute on the first milestone
|
|
122
|
-
a.milestones.each do |m|
|
|
123
|
-
puts "Version: " + m.version
|
|
124
|
-
puts "Title: " + m.data.title
|
|
125
|
-
end
|
|
126
|
-
|
|
127
|
-
== Attachments
|
|
128
|
-
|
|
129
|
-
By default, memories doesn't version attachments. If you'd like to version attachments, simply call the `remember\_attachments!` class method in your
|
|
130
|
-
class definition:
|
|
131
|
-
|
|
132
|
-
class MyDoc < CouchRest::Model::Base
|
|
133
|
-
use_database MY_DB
|
|
134
|
-
include Memories
|
|
135
|
-
|
|
136
|
-
remember_attachments!
|
|
137
|
-
end
|
|
138
|
-
|
|
139
|
-
If you only want specific attachments versioned, pass
|
|
140
|
-
strings and/or regular expressions to this macro. Any attachments
|
|
141
|
-
with matching names will be versioned.
|
|
142
|
-
|
|
143
|
-
class HtmlPage < CouchRest::Model::Base
|
|
144
|
-
use_database MY_DB
|
|
145
|
-
include Memories
|
|
146
|
-
|
|
147
|
-
remember_attachments! "image.png", %r{stylesheets/.*}
|
|
148
|
-
end
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
== Accessing Previous Versions
|
|
152
|
-
|
|
153
|
-
You can access old versions of your document via the "versions" method; it will return a proxy with array-like and hash-like access to previous versions.
|
|
154
|
-
|
|
155
|
-
@doc.versions[1] # ==> returns version 1 of your document
|
|
156
|
-
@doc.versions['rev-1-kjfdsla3289430289432'] # ==> returns version 1 of your document
|
|
157
|
-
@doc.versions[1..20] # ==> returns versions 1 through 20 of your document
|
|
158
|
-
@doc.versions.count # ==> returns the number of versions of your document
|
|
159
|
-
@doc.versions.last # ==> returns the latest version of your document
|
|
160
|
-
@doc.versions.first # ==> returns the first version of your document
|
|
161
|
-
@doc.versions.each do |v|
|
|
162
|
-
puts v.some_property
|
|
163
|
-
end
|