memories 0.3.5 → 0.3.6

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/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.3.6
@@ -23,7 +23,7 @@ module Memories
23
23
 
24
24
  def count
25
25
  populate_proxies
26
- @versions.count - 1
26
+ @versions.count == 0 ? 0 : @versions.count - 1
27
27
  end
28
28
 
29
29
  def [](arg)
@@ -43,7 +43,7 @@ module Memories
43
43
 
44
44
  private
45
45
  def populate_proxies
46
- if (@versions.count - 1) < @doc.current_version.to_i
46
+ if !@doc.new_record? && (@versions.count - 1) < @doc.current_version.to_i
47
47
  (1..@doc.current_version.to_i).each do |i|
48
48
  @versions[i] ||= VersionProxy.new @doc, i
49
49
  end
@@ -0,0 +1,191 @@
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 via the `milestones` array:
106
+
107
+ a.milestones.count #==> 1
108
+ a.milestones.last.version # ==> 'rev-1-893428ifldlfds9832'
109
+ a.milestones.last.version_number # ==> 1
110
+ a.milestones.last.annotations.name # ==> "First publish."
111
+ a.milestones.last.annotations.notes # ==> "Passed all relevant editing. Signed off by moonmaster 10000"
112
+ a.milestones.last.instance.title # ==> Memories gem makes versioning simple
113
+
114
+ 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
115
+ at at the first milestone. How do we do that? Simple!
116
+
117
+ a.revert_to_milestone! 1
118
+
119
+ And now our document properties are back to the where they were when we first published the document.
120
+
121
+ If you want to access the version instance of a milestone, simply use the "instance" method:
122
+
123
+ a.milestones.first.instance.title #==> returns the "title" attribute on the first milestone
124
+ a.milestones.each do |m|
125
+ puts "Version: " + m.version
126
+ puts "Title: " + m.instance.title
127
+ end
128
+
129
+ ## Attachments
130
+
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
+ class definition:
133
+
134
+ class MyDoc < CouchRest::Model::Base
135
+ use_database MY_DB
136
+ include Memories
137
+
138
+ remember_attachments!
139
+ end
140
+
141
+ If you only want specific attachments versioned, pass
142
+ strings and/or regular expressions to this macro. Any attachments
143
+ with matching names will be versioned.
144
+
145
+ class HtmlPage < CouchRest::Model::Base
146
+ use_database MY_DB
147
+ include Memories
148
+
149
+ remember_attachments! "image.png", %r{stylesheets/.*}
150
+ end
151
+
152
+ ## Accessing Previous Versions
153
+
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
+
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
+
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: 25
4
+ hash: 31
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 3
9
- - 5
10
- version: 0.3.5
9
+ - 6
10
+ version: 0.3.6
11
11
  platform: ruby
12
12
  authors:
13
13
  - Matt Parker
@@ -16,8 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2011-03-16 00:00:00 -04:00
20
- default_executable:
19
+ date: 2011-07-26 00:00:00 Z
21
20
  dependencies:
22
21
  - !ruby/object:Gem::Dependency
23
22
  name: couchrest_model
@@ -35,7 +34,35 @@ dependencies:
35
34
  version: 1.0.0
36
35
  type: :runtime
37
36
  version_requirements: *id001
38
- description: CouchDB has built in document versioning, but you can't rely on it for version control. This is an implementation of a version-as-attachments approach created by @jchris.moonmaster9000@gmail.com
37
+ - !ruby/object:Gem::Dependency
38
+ name: cucumber
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ hash: 3
46
+ segments:
47
+ - 0
48
+ version: "0"
49
+ type: :development
50
+ version_requirements: *id002
51
+ - !ruby/object:Gem::Dependency
52
+ name: rspec
53
+ prerelease: false
54
+ requirement: &id003 !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ hash: 3
60
+ segments:
61
+ - 0
62
+ version: "0"
63
+ type: :development
64
+ version_requirements: *id003
65
+ description: CouchDB has built in document versioning, but you can't rely on it for version control. This is an implementation of a version-as-attachments approach created by @jchris.
39
66
  email: moonmaster9000@gmail.com
40
67
  executables: []
41
68
 
@@ -44,13 +71,14 @@ extensions: []
44
71
  extra_rdoc_files: []
45
72
 
46
73
  files:
47
- - lib/memories.rb
48
74
  - lib/memories/annotation.rb
49
75
  - lib/memories/attachment.rb
50
76
  - lib/memories/base.rb
51
77
  - lib/memories/milestones_proxy.rb
52
78
  - lib/memories/versions_proxy.rb
53
- has_rdoc: true
79
+ - lib/memories.rb
80
+ - VERSION
81
+ - readme.markdown
54
82
  homepage: http://github.com/moonmaster9000/memories
55
83
  licenses: []
56
84
 
@@ -80,7 +108,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
80
108
  requirements: []
81
109
 
82
110
  rubyforge_project:
83
- rubygems_version: 1.5.0
111
+ rubygems_version: 1.8.5
84
112
  signing_key:
85
113
  specification_version: 3
86
114
  summary: Versioning for your couchrest_model documents.