mongo_mapper_versioned 0.2.6 → 0.2.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,7 +2,7 @@
2
2
  module MongoMapper
3
3
  module Plugins
4
4
  module Versioned
5
- Version = '0.2.6'
5
+ Version = '0.2.7'
6
6
  end
7
7
  end
8
8
  end
@@ -2,17 +2,22 @@ module MongoMapper
2
2
  module Plugins
3
3
  module Versioned
4
4
 
5
+
6
+
5
7
  extend ActiveSupport::Concern
6
8
 
7
9
 
8
10
 
9
- # ----------------------------------------------------------------------
11
+ # =====================================================================
12
+
13
+
14
+
10
15
  module ClassMethods
11
16
  def versioned(options={})
12
17
  configuration = { :ignored_keys => %w(_id version_number) }
13
18
  configuration[:ignored_keys].concat(options[:ignored_keys]).uniq if options.key?(:ignored_keys)
14
19
 
15
- key :version_number, Integer, :default => 1, :index => true
20
+ key :version_number, Integer, :default => 1
16
21
  many :versions, :class => MongoMapper::Plugins::Versioned::Version, :foreign_key => :versioned_id, :dependent => :destroy, :order => :version_number.asc
17
22
 
18
23
  after_create :create_version, :if => :should_create_initial_version?
@@ -26,47 +31,70 @@ module MongoMapper
26
31
 
27
32
 
28
33
 
29
- # ----------------------------------------------------------------------
30
- module InstanceMethods
31
-
32
- def create_version
33
- self.version_number = self.versions.empty? ? 1 : self.versions.last.version_number+1
34
- self.versions << current_version
35
- end
36
-
37
- def revert_to(target_version_number)
38
- return if self.version_number == target_version_number
39
- if target_version = version_at(target_version_number)
40
- self.attributes = target_version.data
41
- self.version_number = target_version.version_number
42
- end
43
- end
44
-
45
- def last_version?
46
- return true if versions.empty?
47
- self.version_number == versions.last.version_number
48
- end
49
-
50
- def current_version
51
- Version.new(:data => self.attributes.slice!(*ignored_keys), :versioned_id => self.id, :version_number => self.version_number)
52
- end
53
-
54
- def version_at(target_version_number)
55
- versions.where(:version_number => target_version_number).first
56
- end
34
+ # =====================================================================
35
+
36
+
57
37
 
58
- def should_create_initial_version?
59
- versions.empty?
60
- end
61
-
62
- # this method might be overwritten
63
- # by something more sophisticated (esp. in case of EmbeddedDocuments)
64
- def should_create_version?
65
- changes.slice!(*ignored_keys).size > 0
38
+ def create_version
39
+ self.version_number = self.versions.empty? ? 1 : self.versions.last.version_number+1
40
+ self.versions << current_version
41
+ end
42
+
43
+
44
+
45
+ # ---------------------------------------------------------------------
46
+
47
+
48
+
49
+ def revert_to(target_version_number)
50
+ return if self.version_number == target_version_number
51
+ if target_version = version_at(target_version_number)
52
+ self.attributes = target_version.data
53
+ self.version_number = target_version.version_number
66
54
  end
67
-
68
55
  end
69
-
56
+
57
+
58
+
59
+ # ---------------------------------------------------------------------
60
+
61
+
62
+
63
+ def last_version?
64
+ return true if versions.empty?
65
+ self.version_number == versions.last.version_number
66
+ end
67
+
68
+ def current_version
69
+ Version.new(:data => self.attributes.slice!(*ignored_keys), :versioned_id => self.id, :version_number => self.version_number)
70
+ end
71
+
72
+ def version_at(target_version_number)
73
+ versions.where(:version_number => target_version_number).first
74
+ end
75
+
76
+
77
+
78
+ # ---------------------------------------------------------------------
79
+
80
+
81
+
82
+ def should_create_initial_version?
83
+ versions.empty?
84
+ end
85
+
86
+ # this method might be overwritten
87
+ # by something more sophisticated (esp. in case of EmbeddedDocuments)
88
+ def should_create_version?
89
+ changes.slice!(*ignored_keys).size > 0
90
+ end
91
+
92
+
93
+
94
+ # ---------------------------------------------------------------------
95
+
96
+
97
+
70
98
  end
71
99
  end
72
100
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongo_mapper_versioned
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 6
10
- version: 0.2.6
9
+ - 7
10
+ version: 0.2.7
11
11
  platform: ruby
12
12
  authors:
13
13
  - Tomas Celizna
@@ -15,12 +15,11 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-02-20 00:00:00 +01:00
18
+ date: 2011-04-30 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
22
  type: :runtime
23
- name: mongo_mapper
24
23
  requirement: &id001 !ruby/object:Gem::Requirement
25
24
  none: false
26
25
  requirements:
@@ -30,11 +29,11 @@ dependencies:
30
29
  segments:
31
30
  - 0
32
31
  version: "0"
32
+ name: mongo_mapper
33
33
  prerelease: false
34
34
  version_requirements: *id001
35
35
  - !ruby/object:Gem::Dependency
36
36
  type: :development
37
- name: rake
38
37
  requirement: &id002 !ruby/object:Gem::Requirement
39
38
  none: false
40
39
  requirements:
@@ -44,6 +43,7 @@ dependencies:
44
43
  segments:
45
44
  - 0
46
45
  version: "0"
46
+ name: rake
47
47
  prerelease: false
48
48
  version_requirements: *id002
49
49
  description: