mongomapper_id2 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,6 @@
1
1
  = mongomapper_id2
2
2
 
3
- It’s a MongoMapper plugin to add auto incremented id to your MongoMapper documents
3
+ It’s a MongoMapper’s plugin to add auto incremented id to your MongoMapper’s documents
4
4
 
5
5
  This gem is inspired in this blog post http://ihswebdesign.com/blog/autoincrement-in-mongodb-with-ruby/
6
6
 
@@ -1,17 +1,18 @@
1
1
  require 'incrementor'
2
2
 
3
- module MongomapperId2
4
- # Your code goes here...
5
- end
6
-
7
- # Base on http://railstips.org/blog/archives/2010/02/21/mongomapper-07-plugins/
3
+ # Based on http://railstips.org/blog/archives/2010/02/21/mongomapper-07-plugins/
8
4
  module MongoMapper
9
5
  module Plugins
10
6
  module AutoIncrement
7
+ extend ActiveSupport::Concern
11
8
  module ClassMethods
12
- def auto_increment!
9
+ def auto_increment! options = {:override => false}
13
10
  key :id2
14
- class_eval { before_create class_eval { :update_auto_increment }}
11
+ if(options[:override])
12
+ class_eval { before_create class_eval { :update_auto_increment_override }}
13
+ else
14
+ class_eval { before_create class_eval { :update_auto_increment }}
15
+ end
15
16
  end
16
17
  end
17
18
  module InstanceMethods
@@ -19,14 +20,14 @@ module MongoMapper
19
20
  def update_auto_increment
20
21
  self.id2 = MongomapperId2::Incrementor[self.class.name].inc
21
22
  end
23
+ def update_auto_increment_override
24
+ update_auto_increment
25
+ self.id = self.id2.to_s
26
+ end
22
27
  end
23
28
  end
24
29
  end
25
30
  end
26
-
27
- module AutoIncrementPluginAddition
28
- def self.included(model)
29
- model.plugin MongoMapper::Plugins::AutoIncrement
30
- end
31
- end
32
- MongoMapper::Document.append_inclusions(AutoIncrementPluginAddition)
31
+
32
+ MongoMapper::Document.plugin(MongoMapper::Plugins::AutoIncrement)
33
+ MongoMapper::EmbeddedDocument.plugin(MongoMapper::Plugins::AutoIncrement)
@@ -1,3 +1,3 @@
1
1
  module MongomapperId2
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -4,15 +4,20 @@ require 'test_helper'
4
4
  require 'mongomapper_id2'
5
5
 
6
6
  class AutoIncrementTest < Test::Unit::TestCase
7
- context "autoincrementing" do
7
+ context 'autoincrementing' do
8
8
  setup do
9
9
  @klass = Doc do
10
10
  key :title, String
11
11
  end
12
12
  @klass.auto_increment!
13
+
14
+ @klass_override = Doc do
15
+ key :title, String
16
+ end
17
+ @klass_override.auto_increment! :override => true
13
18
  end
14
19
 
15
- should "set id2 on create" do
20
+ should 'set id2 on create' do
16
21
  doc = @klass.new(:title => 'The Simpsons Movie')
17
22
  doc.id2.should be(nil)
18
23
  doc.save
@@ -22,12 +27,18 @@ class AutoIncrementTest < Test::Unit::TestCase
22
27
  doc.id2.should eql id2
23
28
  end
24
29
 
25
- should "auto increment id2" do
30
+ should 'auto increment id2' do
26
31
  doc = @klass.new(:title => 'Pirates of Silicon Valley')
27
32
  doc.save
28
33
  doc2 = @klass.new(:title => 'Tropa de Elite')
29
34
  doc2.save
30
35
  (doc.id2 + 1).should eql doc2.id2
31
36
  end
37
+
38
+ should 'override id' do
39
+ doc2 = @klass_override.new(:title => 'Tropa de Elite')
40
+ doc2.save
41
+ doc2.id2.to_s.should eql doc2.id
42
+ end
32
43
  end
33
44
  end
metadata CHANGED
@@ -1,12 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongomapper_id2
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 0
8
- - 3
9
- version: 0.0.3
4
+ prerelease:
5
+ version: 0.0.4
10
6
  platform: ruby
11
7
  authors:
12
8
  - Pablo Cantero
@@ -14,8 +10,7 @@ autorequire:
14
10
  bindir: bin
15
11
  cert_chain: []
16
12
 
17
- date: 2011-01-01 00:00:00 -02:00
18
- default_executable:
13
+ date: 2011-06-16 00:00:00 Z
19
14
  dependencies:
20
15
  - !ruby/object:Gem::Dependency
21
16
  name: mongo_mapper
@@ -25,141 +20,64 @@ dependencies:
25
20
  requirements:
26
21
  - - ">="
27
22
  - !ruby/object:Gem::Version
28
- segments:
29
- - 0
30
23
  version: "0"
31
24
  type: :runtime
32
25
  version_requirements: *id001
33
26
  - !ruby/object:Gem::Dependency
34
- name: activesupport
27
+ name: log_buddy
35
28
  prerelease: false
36
29
  requirement: &id002 !ruby/object:Gem::Requirement
37
30
  none: false
38
31
  requirements:
39
32
  - - ">="
40
33
  - !ruby/object:Gem::Version
41
- segments:
42
- - 2
43
- - 3
44
- - 4
45
- version: 2.3.4
46
- type: :runtime
34
+ version: "0"
35
+ type: :development
47
36
  version_requirements: *id002
48
37
  - !ruby/object:Gem::Dependency
49
- name: jnunemaker-validatable
38
+ name: jnunemaker-matchy
50
39
  prerelease: false
51
40
  requirement: &id003 !ruby/object:Gem::Requirement
52
41
  none: false
53
42
  requirements:
54
- - - ~>
43
+ - - ">="
55
44
  - !ruby/object:Gem::Version
56
- segments:
57
- - 1
58
- - 8
59
- - 4
60
- version: 1.8.4
61
- type: :runtime
45
+ version: "0"
46
+ type: :development
62
47
  version_requirements: *id003
63
48
  - !ruby/object:Gem::Dependency
64
- name: plucky
49
+ name: shoulda
65
50
  prerelease: false
66
51
  requirement: &id004 !ruby/object:Gem::Requirement
67
52
  none: false
68
53
  requirements:
69
- - - ~>
54
+ - - ">="
70
55
  - !ruby/object:Gem::Version
71
- segments:
72
- - 0
73
- - 3
74
- - 6
75
- version: 0.3.6
76
- type: :runtime
56
+ version: "0"
57
+ type: :development
77
58
  version_requirements: *id004
78
59
  - !ruby/object:Gem::Dependency
79
- name: json
60
+ name: timecop
80
61
  prerelease: false
81
62
  requirement: &id005 !ruby/object:Gem::Requirement
82
63
  none: false
83
64
  requirements:
84
65
  - - ">="
85
66
  - !ruby/object:Gem::Version
86
- segments:
87
- - 0
88
67
  version: "0"
89
68
  type: :development
90
69
  version_requirements: *id005
91
70
  - !ruby/object:Gem::Dependency
92
- name: log_buddy
71
+ name: mocha
93
72
  prerelease: false
94
73
  requirement: &id006 !ruby/object:Gem::Requirement
95
74
  none: false
96
75
  requirements:
97
76
  - - ">="
98
77
  - !ruby/object:Gem::Version
99
- segments:
100
- - 0
101
78
  version: "0"
102
79
  type: :development
103
80
  version_requirements: *id006
104
- - !ruby/object:Gem::Dependency
105
- name: jnunemaker-matchy
106
- prerelease: false
107
- requirement: &id007 !ruby/object:Gem::Requirement
108
- none: false
109
- requirements:
110
- - - ~>
111
- - !ruby/object:Gem::Version
112
- segments:
113
- - 0
114
- - 4
115
- - 0
116
- version: 0.4.0
117
- type: :development
118
- version_requirements: *id007
119
- - !ruby/object:Gem::Dependency
120
- name: shoulda
121
- prerelease: false
122
- requirement: &id008 !ruby/object:Gem::Requirement
123
- none: false
124
- requirements:
125
- - - ~>
126
- - !ruby/object:Gem::Version
127
- segments:
128
- - 2
129
- - 11
130
- version: "2.11"
131
- type: :development
132
- version_requirements: *id008
133
- - !ruby/object:Gem::Dependency
134
- name: timecop
135
- prerelease: false
136
- requirement: &id009 !ruby/object:Gem::Requirement
137
- none: false
138
- requirements:
139
- - - ~>
140
- - !ruby/object:Gem::Version
141
- segments:
142
- - 0
143
- - 3
144
- - 1
145
- version: 0.3.1
146
- type: :development
147
- version_requirements: *id009
148
- - !ruby/object:Gem::Dependency
149
- name: mocha
150
- prerelease: false
151
- requirement: &id010 !ruby/object:Gem::Requirement
152
- none: false
153
- requirements:
154
- - - ~>
155
- - !ruby/object:Gem::Version
156
- segments:
157
- - 0
158
- - 9
159
- - 8
160
- version: 0.9.8
161
- type: :development
162
- version_requirements: *id010
163
81
  description:
164
82
  email:
165
83
  - pablo@pablocantero
@@ -180,7 +98,6 @@ files:
180
98
  - test/test_helper.rb
181
99
  - LICENSE
182
100
  - README.rdoc
183
- has_rdoc: true
184
101
  homepage: https://github.com/phstc/mongomapper_id2
185
102
  licenses: []
186
103
 
@@ -194,23 +111,19 @@ required_ruby_version: !ruby/object:Gem::Requirement
194
111
  requirements:
195
112
  - - ">="
196
113
  - !ruby/object:Gem::Version
197
- segments:
198
- - 0
199
114
  version: "0"
200
115
  required_rubygems_version: !ruby/object:Gem::Requirement
201
116
  none: false
202
117
  requirements:
203
118
  - - ">="
204
119
  - !ruby/object:Gem::Version
205
- segments:
206
- - 0
207
120
  version: "0"
208
121
  requirements: []
209
122
 
210
123
  rubyforge_project: mongomapper_id2
211
- rubygems_version: 1.3.7
124
+ rubygems_version: 1.8.5
212
125
  signing_key:
213
126
  specification_version: 3
214
- summary: "It\xE2\x80\x99s a MongoMapper plugin to add auto incremented id to your MongoMapper documents"
127
+ summary: "It\xE2\x80\x99s a MongoMapper\xE2\x80\x99s plugin to add auto incremented id to your MongoMapper\xE2\x80\x99s documents"
215
128
  test_files: []
216
129