memories 0.2.7 → 0.2.8
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 +4 -1
- data/README.rdoc +1 -0
- data/lib/memories/base.rb +7 -0
- data/lib/memories/versions_proxy.rb +36 -2
- metadata +4 -4
data/README.markdown
CHANGED
|
@@ -145,4 +145,7 @@ You can access old versions of your document via the "versions" method; it will
|
|
|
145
145
|
|
|
146
146
|
@doc.versions[1] # ==> returns version 1 of your document
|
|
147
147
|
@doc.versions['rev-1-kjfdsla3289430289432'] # ==> returns version 1 of your document
|
|
148
|
-
@doc.versions[
|
|
148
|
+
@doc.versions[5..20] # ==> returns versions 5 through 20 of your document
|
|
149
|
+
@doc.versions.count # ==> returns the number of versions of your document
|
|
150
|
+
@doc.versions.last # ==> returns the latest version of your document
|
|
151
|
+
@doc.versions.first # ==> returns the first version of your document
|
data/README.rdoc
CHANGED
|
@@ -147,3 +147,4 @@ You can access old versions of your document via the "versions" method; it will
|
|
|
147
147
|
@doc.versions[1] # ==> returns version 1 of your document
|
|
148
148
|
@doc.versions['rev-1-kjfdsla3289430289432'] # ==> returns version 1 of your document
|
|
149
149
|
@doc.versions[1..20] # ==> returns versions 1 through 20 of your document
|
|
150
|
+
@doc.versions.count # ==> returns the number of versions of your document
|
data/lib/memories/base.rb
CHANGED
|
@@ -216,6 +216,13 @@ module Memories
|
|
|
216
216
|
version_number rev
|
|
217
217
|
end
|
|
218
218
|
|
|
219
|
+
# Provides array-like and hash-like access to the versions of your document.
|
|
220
|
+
# @doc.versions[1] # ==> returns version 1 of your document
|
|
221
|
+
# @doc.versions['rev-1-kjfdsla3289430289432'] # ==> returns version 1 of your document
|
|
222
|
+
# @doc.versions[5..20] # ==> returns versions 5 through 20 of your document
|
|
223
|
+
# @doc.versions.count # ==> returns the number of versions of your document
|
|
224
|
+
# @doc.versions.last # ==> returns the latest version of your document
|
|
225
|
+
# @doc.versions.first # ==> returns the first version of your document
|
|
219
226
|
def versions
|
|
220
227
|
@versions ||= VersionsProxy.new self
|
|
221
228
|
end
|
|
@@ -1,14 +1,48 @@
|
|
|
1
1
|
module Memories
|
|
2
2
|
class VersionsProxy
|
|
3
|
+
# A Memories::VersionsProxy is automatically initialized, memoized,
|
|
4
|
+
# and returned when you call the `versions` method on your document.
|
|
5
|
+
# doc = Book.create :name => '2001'
|
|
6
|
+
# doc.versions.class # ==> ::Memories::VersionsProxy
|
|
3
7
|
def initialize(doc)
|
|
4
8
|
@doc = doc
|
|
5
9
|
@versions = {}
|
|
6
10
|
end
|
|
7
|
-
|
|
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
|
|
8
17
|
def count
|
|
9
18
|
@doc.current_version
|
|
10
19
|
end
|
|
11
20
|
|
|
21
|
+
# Returns the first version of your document
|
|
22
|
+
# doc = Book.create :name => '2001'
|
|
23
|
+
# doc.name => '2001: A Space Odyssey'
|
|
24
|
+
# doc.save
|
|
25
|
+
# doc.versions.first.name # ==> '2001'
|
|
26
|
+
def first
|
|
27
|
+
@doc.current_version == 1 ? @doc.dup : version_num(1)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
# Returns the last version of your document (which should be the same as your document)
|
|
31
|
+
# doc = Book.create :name => '2001'
|
|
32
|
+
# doc.name => '2001: A Space Odyssey'
|
|
33
|
+
# doc.save
|
|
34
|
+
# doc.versions.last.name # ==> '2001: A Space Odyssey'
|
|
35
|
+
def last
|
|
36
|
+
@doc.dup
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
# Provides array-like and hash-like access to the versions of your document.
|
|
40
|
+
# @doc.versions[1] # ==> returns version 1 of your document
|
|
41
|
+
# @doc.versions['rev-1-kjfdsla3289430289432'] # ==> returns version 1 of your document
|
|
42
|
+
# @doc.versions[5..20] # ==> returns versions 5 through 20 of your document
|
|
43
|
+
# @doc.versions.count # ==> returns the number of versions of your document
|
|
44
|
+
# @doc.versions.last # ==> returns the latest version of your document
|
|
45
|
+
# @doc.versions.first # ==> returns the first version of your document
|
|
12
46
|
def [](arg)
|
|
13
47
|
case arg.class.to_s
|
|
14
48
|
when "Range" then version_range arg
|
|
@@ -30,7 +64,7 @@ module Memories
|
|
|
30
64
|
|
|
31
65
|
def version_num(num)
|
|
32
66
|
return nil if !num.kind_of?(Fixnum) or num >= @doc.current_version or num < 1
|
|
33
|
-
@versions[num] ||= @doc.revert_to(num)
|
|
67
|
+
@versions[num] ||= @doc.dup.revert_to(num)
|
|
34
68
|
end
|
|
35
69
|
|
|
36
70
|
def version_id(id)
|
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: 7
|
|
5
5
|
prerelease: false
|
|
6
6
|
segments:
|
|
7
7
|
- 0
|
|
8
8
|
- 2
|
|
9
|
-
-
|
|
10
|
-
version: 0.2.
|
|
9
|
+
- 8
|
|
10
|
+
version: 0.2.8
|
|
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-27 00:00:00 -05:00
|
|
20
20
|
default_executable:
|
|
21
21
|
dependencies:
|
|
22
22
|
- !ruby/object:Gem::Dependency
|