memories 0.2.10 → 0.2.11
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +14 -5
- data/README.rdoc +9 -1
- data/lib/memories.rb +1 -0
- data/lib/memories/base.rb +56 -4
- data/lib/memories/milestones_proxy.rb +92 -0
- data/lib/memories/versions_proxy.rb +3 -2
- metadata +5 -4
data/README.markdown
CHANGED
@@ -9,7 +9,7 @@ stored as an attachment on the document. This versioning strategy was originally
|
|
9
9
|
|
10
10
|
## Documentation
|
11
11
|
|
12
|
-
Browse the documentation on
|
12
|
+
Browse the documentation on rubydoc.info: http://rubydoc.info/gems/memories/frames
|
13
13
|
|
14
14
|
##How does it work?
|
15
15
|
|
@@ -102,12 +102,13 @@ they published as a milestone.
|
|
102
102
|
end
|
103
103
|
|
104
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:
|
105
|
+
Now that we've created a milestone, let's inspect it via the `milestones` array:
|
106
106
|
|
107
107
|
a.milestones.count #==> 1
|
108
|
-
a.
|
109
|
-
a.
|
110
|
-
a.
|
108
|
+
a.milestones.last.version # ==> 1
|
109
|
+
a.milestones.last.version # ==> 1
|
110
|
+
a.milestones.last.annotations.name ==> "First publish."
|
111
|
+
a.milestones.last.annotations.notes ==> "Passed all relevant editing. Signed off by moonmaster 10000"
|
111
112
|
|
112
113
|
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
114
|
at at the first milestone. How do we do that? Simple!
|
@@ -116,6 +117,14 @@ at at the first milestone. How do we do that? Simple!
|
|
116
117
|
|
117
118
|
And now our document properties are back to the where they were when we first published the document.
|
118
119
|
|
120
|
+
If you want to access the data from a milestone, simply use the "data" method:
|
121
|
+
|
122
|
+
a.milestones.first.data.title #==> returns the "title" attribute on the first milestone
|
123
|
+
a.milestones.each do |m|
|
124
|
+
puts "Version: " + m.version
|
125
|
+
puts "Title: " + m.data.title
|
126
|
+
end
|
127
|
+
|
119
128
|
## Attachments
|
120
129
|
|
121
130
|
By default, memories doesn't version attachments. If you'd like to version attachments, simply call the `remember_attachments!` class method in your
|
data/README.rdoc
CHANGED
@@ -9,7 +9,7 @@ stored as an attachment on the document. This versioning strategy was originally
|
|
9
9
|
|
10
10
|
== Documentation
|
11
11
|
|
12
|
-
Browse the documentation on
|
12
|
+
Browse the documentation on rubydoc.info: http://rubydoc.info/gems/memories/frames
|
13
13
|
|
14
14
|
== How does it work?
|
15
15
|
|
@@ -116,6 +116,14 @@ at at the first milestone. How do we do that? Simple!
|
|
116
116
|
|
117
117
|
And now our document properties are back to the where they were when we first published the document.
|
118
118
|
|
119
|
+
If you want to access the data from 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
|
+
|
119
127
|
== Attachments
|
120
128
|
|
121
129
|
By default, memories doesn't version attachments. If you'd like to version attachments, simply call the `remember\_attachments!` class method in your
|
data/lib/memories.rb
CHANGED
data/lib/memories/base.rb
CHANGED
@@ -241,11 +241,63 @@ module Memories
|
|
241
241
|
self.save
|
242
242
|
end
|
243
243
|
|
244
|
-
#
|
245
|
-
#
|
246
|
-
#
|
244
|
+
#As of version 0.2.0, Memories also supports milestones. Milestones are special versions that you want to flag in some way.
|
245
|
+
#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
|
246
|
+
#they published as a milestone.
|
247
|
+
#
|
248
|
+
# class Article < CouchRest::Model::Base
|
249
|
+
# include Memories
|
250
|
+
# use_database SOME_DATABASE
|
251
|
+
#
|
252
|
+
# property :title
|
253
|
+
# property :author
|
254
|
+
# property :body
|
255
|
+
#
|
256
|
+
# def publish!
|
257
|
+
# # .... publishing logic
|
258
|
+
# end
|
259
|
+
# end
|
260
|
+
#
|
261
|
+
# a = Article.create(
|
262
|
+
# :title => "Memories gem makes versioning simple",
|
263
|
+
# :author => "moonmaster9000",
|
264
|
+
# :body => <<-ARTICLE
|
265
|
+
# Check it out at http://github.com/moonmaster9000/memories
|
266
|
+
# ARTICLE
|
267
|
+
# )
|
268
|
+
# a.save
|
269
|
+
# a.publish!
|
270
|
+
# a.current_version #==> 1
|
271
|
+
# a.milestone! do
|
272
|
+
# name "First publish."
|
273
|
+
# notes "Passed all relevant editing. Signed off by moonmaster10000"
|
274
|
+
# end
|
275
|
+
#
|
276
|
+
#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.
|
277
|
+
#Now that we've created a milestone, let's inspect it via the `milestones` array:
|
278
|
+
#
|
279
|
+
# a.milestones.count #==> 1
|
280
|
+
# a.milestones.last.version # ==> 1
|
281
|
+
# a.milestones.last.version # ==> 1
|
282
|
+
# a.milestones.last.annotations.name ==> "First publish."
|
283
|
+
# a.milestones.last.annotations.notes ==> "Passed all relevant editing. Signed off by moonmaster10000"
|
284
|
+
#
|
285
|
+
#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
|
286
|
+
#at at the first milestone. How do we do that? Simple!
|
287
|
+
#
|
288
|
+
# a.revert_to_milestone! 1
|
289
|
+
#
|
290
|
+
#And now our document properties are back to the where they were when we first published the document.
|
291
|
+
#
|
292
|
+
#If you want to access the data from a milestone, simply use the "data" method:
|
293
|
+
#
|
294
|
+
# a.milestones.first.data.title #==> returns the "title" attribute on the first milestone
|
295
|
+
# a.milestones.each do |m|
|
296
|
+
# puts "Version: " + m.version
|
297
|
+
# puts "Title: " + m.data.title
|
298
|
+
# end
|
247
299
|
def milestones
|
248
|
-
self
|
300
|
+
@milestones_proxy ||= MilestonesProxy.new self
|
249
301
|
end
|
250
302
|
|
251
303
|
# Returns the metadata (version, annotations) for the latest milestone created.
|
@@ -0,0 +1,92 @@
|
|
1
|
+
module Memories
|
2
|
+
#As of version 0.2.0, Memories also supports milestones. Milestones are special versions that you want to flag in some way.
|
3
|
+
#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
|
4
|
+
#they published as a milestone.
|
5
|
+
#
|
6
|
+
# class Article < CouchRest::Model::Base
|
7
|
+
# include Memories
|
8
|
+
# use_database SOME_DATABASE
|
9
|
+
#
|
10
|
+
# property :title
|
11
|
+
# property :author
|
12
|
+
# property :body
|
13
|
+
#
|
14
|
+
# def publish!
|
15
|
+
# # .... publishing logic
|
16
|
+
# end
|
17
|
+
# end
|
18
|
+
#
|
19
|
+
# a = Article.create(
|
20
|
+
# :title => "Memories gem makes versioning simple",
|
21
|
+
# :author => "moonmaster9000",
|
22
|
+
# :body => <<-ARTICLE
|
23
|
+
# Check it out at http://github.com/moonmaster9000/memories
|
24
|
+
# ARTICLE
|
25
|
+
# )
|
26
|
+
# a.save
|
27
|
+
# a.publish!
|
28
|
+
# a.current_version #==> 1
|
29
|
+
# a.milestone! do
|
30
|
+
# name "First publish."
|
31
|
+
# notes "Passed all relevant editing. Signed off by moonmaster10000"
|
32
|
+
# end
|
33
|
+
#
|
34
|
+
#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.
|
35
|
+
#Now that we've created a milestone, let's inspect it via the `milestones` array:
|
36
|
+
#
|
37
|
+
# a.milestones.count #==> 1
|
38
|
+
# a.milestones.last.version # ==> 1
|
39
|
+
# a.milestones.last.version # ==> 1
|
40
|
+
# a.milestones.last.annotations.name ==> "First publish."
|
41
|
+
# a.milestones.last.annotations.notes ==> "Passed all relevant editing. Signed off by moonmaster10000"
|
42
|
+
#
|
43
|
+
#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
|
44
|
+
#at at the first milestone. How do we do that? Simple!
|
45
|
+
#
|
46
|
+
# a.revert_to_milestone! 1
|
47
|
+
#
|
48
|
+
#And now our document properties are back to the where they were when we first published the document.
|
49
|
+
#
|
50
|
+
#If you want to access the data from a milestone, simply use the "data" method:
|
51
|
+
#
|
52
|
+
# a.milestones.first.data.title #==> returns the "title" attribute on the first milestone
|
53
|
+
# a.milestones.each do |m|
|
54
|
+
# puts "Version: " + m.version
|
55
|
+
# puts "Title: " + m.data.title
|
56
|
+
# end
|
57
|
+
class MilestonesProxy
|
58
|
+
def initialize(doc)
|
59
|
+
@doc = doc
|
60
|
+
@milestone_proxies = []
|
61
|
+
end
|
62
|
+
|
63
|
+
def method_missing(method_name, *args, &block)
|
64
|
+
populate_proxies
|
65
|
+
@milestone_proxies.send(method_name, *args, &block)
|
66
|
+
end
|
67
|
+
|
68
|
+
private
|
69
|
+
def populate_proxies
|
70
|
+
if @milestone_proxies.count < @doc.milestone_memories.count
|
71
|
+
(@milestone_proxies.count...@doc.milestone_memories.count).each do |i|
|
72
|
+
@milestone_proxies[i] = MilestoneProxy.new @doc, @doc.milestone_memories[i]
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
class MilestoneProxy
|
79
|
+
def initialize(doc, milestone_metadata)
|
80
|
+
@doc = doc
|
81
|
+
@milestone_metadata = milestone_metadata
|
82
|
+
end
|
83
|
+
|
84
|
+
def data
|
85
|
+
@doc.versions[@milestone_metadata.version]
|
86
|
+
end
|
87
|
+
|
88
|
+
def method_missing(method_name, *args, &block)
|
89
|
+
@milestone_metadata.send method_name, *args, &block
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
@@ -63,9 +63,10 @@ module Memories
|
|
63
63
|
end
|
64
64
|
|
65
65
|
def sanitize_range(range)
|
66
|
+
raise StandardError, "Sorry, but we don't allow negative numbers in the range." if range.first < 0 or range.last < 0
|
66
67
|
return [] if range.first > @doc.current_version
|
67
|
-
first =
|
68
|
-
last
|
68
|
+
first = [1, range.first].max
|
69
|
+
last = [range.last, @doc.current_version].min
|
69
70
|
(first..last)
|
70
71
|
end
|
71
72
|
|
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: 1
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 0.2.
|
9
|
+
- 11
|
10
|
+
version: 0.2.11
|
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: 2010-12-
|
19
|
+
date: 2010-12-28 00:00:00 -05:00
|
20
20
|
default_executable:
|
21
21
|
dependencies:
|
22
22
|
- !ruby/object:Gem::Dependency
|
@@ -51,6 +51,7 @@ files:
|
|
51
51
|
- lib/memories/annotation.rb
|
52
52
|
- lib/memories/attachment.rb
|
53
53
|
- lib/memories/base.rb
|
54
|
+
- lib/memories/milestones_proxy.rb
|
54
55
|
- lib/memories/versions_proxy.rb
|
55
56
|
- README.markdown
|
56
57
|
has_rdoc: true
|