memories 0.2.14 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +10 -7
- data/lib/memories/milestones_proxy.rb +5 -6
- data/lib/memories/versions_proxy.rb +49 -54
- metadata +4 -4
data/README.markdown
CHANGED
@@ -105,10 +105,11 @@ Notice that we annotated our milestone; we gave it a name, and some notes. You c
|
|
105
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.milestones.last.version # ==> 1
|
109
|
-
a.milestones.last.
|
110
|
-
a.milestones.last.annotations.name ==> "First publish."
|
111
|
-
a.milestones.last.annotations.notes ==> "Passed all relevant editing. Signed off by moonmaster 10000"
|
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
|
112
113
|
|
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
|
114
115
|
at at the first milestone. How do we do that? Simple!
|
@@ -152,9 +153,11 @@ with matching names will be versioned.
|
|
152
153
|
|
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.
|
154
155
|
|
155
|
-
@doc.versions[1] # ==> returns version 1 of your document
|
156
|
-
@doc.versions[
|
157
|
-
@doc.versions[
|
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
|
158
161
|
@doc.versions.count # ==> returns the number of versions of your document
|
159
162
|
@doc.versions.last # ==> returns the latest version of your document
|
160
163
|
@doc.versions.first # ==> returns the first version of your document
|
@@ -35,8 +35,8 @@ module Memories
|
|
35
35
|
#Now that we've created a milestone, let's inspect it via the `milestones` array:
|
36
36
|
#
|
37
37
|
# a.milestones.count #==> 1
|
38
|
-
# a.milestones.last.version # ==> 1
|
39
|
-
# a.milestones.last.
|
38
|
+
# a.milestones.last.version # ==> 'rev-1-reiwurieowu9340289032804932krew'
|
39
|
+
# a.milestones.last.version_number # ==> 1
|
40
40
|
# a.milestones.last.annotations.name ==> "First publish."
|
41
41
|
# a.milestones.last.annotations.notes ==> "Passed all relevant editing. Signed off by moonmaster10000"
|
42
42
|
#
|
@@ -75,15 +75,14 @@ module Memories
|
|
75
75
|
end
|
76
76
|
end
|
77
77
|
|
78
|
-
class MilestoneProxy
|
78
|
+
class MilestoneProxy < VersionProxy
|
79
79
|
def initialize(doc, milestone_metadata)
|
80
80
|
@doc = doc
|
81
81
|
@milestone_metadata = milestone_metadata
|
82
|
+
@version_number = @doc.version_number @milestone_metadata.version
|
82
83
|
end
|
83
84
|
|
84
|
-
def
|
85
|
-
@doc.versions[@milestone_metadata.version]
|
86
|
-
end
|
85
|
+
def milestone?; true; end
|
87
86
|
|
88
87
|
def method_missing(method_name, *args, &block)
|
89
88
|
@milestone_metadata.send method_name, *args, &block
|
@@ -3,81 +3,76 @@ module Memories
|
|
3
3
|
# A Memories::VersionsProxy is automatically initialized, memoized,
|
4
4
|
# and returned when you call the `versions` method on your document.
|
5
5
|
# doc = Book.create :name => '2001'
|
6
|
+
# doc.name = '2001: A Space Odyssey'
|
7
|
+
# doc.milestone!
|
6
8
|
# doc.versions.class # ==> ::Memories::VersionsProxy
|
9
|
+
#
|
10
|
+
# You can access versions by version number
|
11
|
+
# doc.versions[0] #==> nil
|
12
|
+
# doc.versions[1].revision #==> 'rev-1-io329uidlrew098320'
|
13
|
+
# doc.versions[1].instance.name #==> '2001'
|
14
|
+
# doc.versions[1].milestone? #==> false
|
15
|
+
# doc.versions[2].instance.name #==> '2001: A Space Odyssey'
|
16
|
+
# doc.versions[2].milestone? #==> true
|
17
|
+
# doc.versions[2].version_number # ==> 2
|
18
|
+
#
|
7
19
|
def initialize(doc)
|
8
20
|
@doc = doc
|
9
|
-
@versions =
|
21
|
+
@versions = []
|
10
22
|
end
|
11
|
-
|
12
|
-
# Returns the number of versions of your document.
|
13
|
-
# doc = Book.create :name => '2001'
|
14
|
-
# doc.name = '2001: A Space Odyssey'
|
15
|
-
# doc.save
|
16
|
-
# doc.versions.count # ==> 2
|
23
|
+
|
17
24
|
def count
|
18
|
-
|
25
|
+
populate_proxies
|
26
|
+
@versions.count - 1
|
19
27
|
end
|
20
28
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
29
|
+
def [](arg)
|
30
|
+
populate_proxies
|
31
|
+
|
32
|
+
if arg.kind_of?(String)
|
33
|
+
@versions[@doc.version_number arg]
|
34
|
+
else
|
35
|
+
@versions[arg]
|
36
|
+
end
|
28
37
|
end
|
29
38
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
# doc.save
|
34
|
-
# doc.versions.last.name # ==> '2001: A Space Odyssey'
|
35
|
-
def last
|
36
|
-
@doc.dup
|
39
|
+
def method_missing(method_name, *args, &block)
|
40
|
+
populate_proxies
|
41
|
+
@versions.send(method_name, *args, &block)
|
37
42
|
end
|
38
43
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
# @doc.versions.first # ==> returns the first version of your document
|
46
|
-
def [](arg)
|
47
|
-
case arg.class.to_s
|
48
|
-
when "Range" then version_range arg
|
49
|
-
when "Fixnum" then version_num arg
|
50
|
-
when "String" then version_id arg
|
51
|
-
else raise "Invalid argument."
|
44
|
+
private
|
45
|
+
def populate_proxies
|
46
|
+
if (@versions.count - 1) < @doc.current_version.to_i
|
47
|
+
(1..@doc.current_version.to_i).each do |i|
|
48
|
+
@versions[i] ||= VersionProxy.new @doc, i
|
49
|
+
end
|
52
50
|
end
|
53
51
|
end
|
52
|
+
end
|
54
53
|
|
55
|
-
|
56
|
-
|
57
|
-
def each(&block)
|
58
|
-
version_range(1..@doc.current_version).each &block
|
59
|
-
end
|
54
|
+
class VersionProxy
|
55
|
+
attr_reader :version_number
|
60
56
|
|
61
|
-
|
62
|
-
|
63
|
-
|
57
|
+
def initialize(doc, version_number)
|
58
|
+
@doc = doc
|
59
|
+
@version_number = version_number
|
60
|
+
end
|
61
|
+
|
62
|
+
def version
|
63
|
+
@version ||= @doc.version_id @version_number
|
64
64
|
end
|
65
65
|
|
66
|
-
def
|
67
|
-
|
68
|
-
@versions[num] ||= @doc.dup.revert_to(num)
|
66
|
+
def revision
|
67
|
+
version
|
69
68
|
end
|
70
69
|
|
71
|
-
def
|
72
|
-
|
73
|
-
return [] if range.first > @doc.current_version
|
74
|
-
first = [1, range.first].max
|
75
|
-
last = [range.last, @doc.current_version].min
|
76
|
-
(first..last)
|
70
|
+
def milestone?
|
71
|
+
@is_milestone ||= @doc.milestones.collect(&:version).include? version
|
77
72
|
end
|
78
73
|
|
79
|
-
def
|
80
|
-
|
74
|
+
def instance
|
75
|
+
@instance ||= @doc.dup.revert_to @version_number
|
81
76
|
end
|
82
77
|
end
|
83
78
|
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: 19
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
8
|
+
- 3
|
9
|
+
- 0
|
10
|
+
version: 0.3.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Matt Parker
|