memories 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,11 @@
1
+ module Memories
2
+ class Annotation < Hash
3
+ def method_missing(method_name, *args, &block)
4
+ if args.empty?
5
+ self[method_name]
6
+ else
7
+ self[method_name] = args[0]
8
+ end
9
+ end
10
+ end
11
+ end
data/lib/memories/base.rb CHANGED
@@ -1,10 +1,15 @@
1
1
  module Memories
2
2
  def self.included(base)
3
+ base.property(:milestone_memories) do |milestone_memory|
4
+ milestone_memory.property :version, Fixnum
5
+ milestone_memory.property :annotations, Memories::Annotation
6
+ end
7
+
3
8
  base.before_update :add_version_attachment
4
9
  base.after_update :decode_attachments
5
10
  end
6
11
 
7
- VERSION_REGEX = /(?:rev-)?(\d)+-[a-zA-Z0-9]+/
12
+ VERSION_REGEX = /(?:rev-)?(\d+)-[a-zA-Z0-9]+/
8
13
 
9
14
  def revert_to!(version=nil)
10
15
  version ||= previous_version
@@ -16,6 +21,10 @@ module Memories
16
21
  self.update_attributes properties
17
22
  end
18
23
  end
24
+
25
+ def revert_to_milestone!(n)
26
+ self.revert_to! self.milestones[n.to_i-1].version
27
+ end
19
28
 
20
29
  def version_id(version_num)
21
30
  self["_attachments"].keys.sort {|a,b| version_number(a) <=> version_number(b)}[version_num - 1] if self["_attachments"]
@@ -33,19 +42,34 @@ module Memories
33
42
  version_number rev
34
43
  end
35
44
 
45
+ def milestone!(&block)
46
+ annotations = Memories::Annotation.new
47
+ annotations.instance_eval(&block) if block
48
+ self.milestone_memories << {:version => self.current_version, :annotations => annotations}
49
+ self.save
50
+ end
51
+
52
+ def milestones
53
+ self.milestone_memories
54
+ end
55
+
56
+ def latest_milestone
57
+ self.milestone_memories.last
58
+ end
59
+
36
60
  private
37
61
  def add_version_attachment
38
- current_version = Attachment.new prep_for_versioning(self.database.get(self.id, :rev => self.rev)).to_json
62
+ current_document_version = Attachment.new prep_for_versioning(self.database.get(self.id, :rev => self.rev)).to_json
39
63
 
40
64
  self.create_attachment(
41
- :file => current_version,
65
+ :file => current_document_version,
42
66
  :content_type => "application/json",
43
67
  :name => "rev-#{self.rev}"
44
68
  )
45
69
  end
46
70
 
47
71
  def prep_for_versioning(doc)
48
- doc.dup.delete_if {|k,v| ["couchrest-type", "_id", "_rev", "_attachments"].include? k}
72
+ doc.dup.delete_if {|k,v| ["couchrest-type", "_id", "_rev", "_attachments", "milestone_memories"].include? k}
49
73
  end
50
74
 
51
75
  def decode_attachments
data/lib/memories.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'base64'
2
2
  require 'couchrest_model'
3
- require 'memories/attachment.rb'
4
- require 'memories/base.rb'
3
+ require 'memories/annotation'
4
+ require 'memories/attachment'
5
+ require 'memories/base'
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: 27
4
+ hash: 23
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 1
8
+ - 2
9
9
  - 0
10
- version: 0.1.0
10
+ version: 0.2.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Matt Parker
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-07-26 00:00:00 -04:00
18
+ date: 2010-08-28 00:00:00 -04:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -45,6 +45,7 @@ extra_rdoc_files: []
45
45
 
46
46
  files:
47
47
  - lib/memories.rb
48
+ - lib/memories/annotation.rb
48
49
  - lib/memories/attachment.rb
49
50
  - lib/memories/base.rb
50
51
  has_rdoc: true