mongomapper_id2 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,8 +1,8 @@
1
1
  = mongomapper_id2
2
2
 
3
- It’s a MongoMapper’s plugin to add auto incremented id to your MongoMapper’s documents
3
+ It’s a MongoMapper’s plugin to add auto incremented id in MongoMapper’s documents.
4
4
 
5
- This gem is inspired in this blog post http://ihswebdesign.com/blog/autoincrement-in-mongodb-with-ruby/
5
+ This gem was based on this post http://ihswebdesign.com/blog/autoincrement-in-mongodb-with-ruby/
6
6
 
7
7
  == Installation
8
8
 
@@ -35,12 +35,28 @@ This gem is inspired in this blog post http://ihswebdesign.com/blog/autoincremen
35
35
  movie2 = Movie.create(:title => 'Pirates of Silicon Valley')
36
36
  movie2.id2 # 2
37
37
 
38
+ == Overriding the default id
39
+
40
+ If you want to override the default id, just add the option ":override => true"
41
+
42
+ # app/models/movie.rb
43
+ class Movie
44
+ include MongoMapper::Document
45
+
46
+ key :title, String
47
+ # Here is the mongomapper_id2
48
+ auto_increment! :override => true
49
+ end
50
+
51
+ Activating this option the default id will be replaced by an auto incremented id
52
+
53
+ movie = Movie.create(:title => 'Pirates of Silicon Valley')
54
+ movie.id # 1
55
+
38
56
  == Do you want to improve mongomapper_id2
39
57
 
40
58
  You’re welcome to make your contributions and send them as a pull request
41
59
 
42
- http://pablocantero.com/blog/contato
43
-
44
60
  === Development
45
61
 
46
62
  $ gem install bundler (if you don't have it)
@@ -15,19 +15,16 @@ module MongoMapper
15
15
  end
16
16
  end
17
17
  end
18
- module InstanceMethods
19
- private
20
- def update_auto_increment
21
- self.id2 = MongomapperId2::Incrementor[self.class.name].inc
22
- end
23
- def update_auto_increment_override
24
- update_auto_increment
25
- self.id = self.id2.to_s
26
- end
18
+ private
19
+ def update_auto_increment
20
+ self.id2 = MongomapperId2::Incrementor[self.class.name].inc
21
+ end
22
+ def update_auto_increment_override
23
+ update_auto_increment
24
+ self.id = self.id2.to_s
27
25
  end
28
26
  end
29
27
  end
30
28
  end
31
29
 
32
30
  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.4"
2
+ VERSION = "0.0.5"
3
3
  end
@@ -8,13 +8,13 @@ class AutoIncrementTest < Test::Unit::TestCase
8
8
  setup do
9
9
  @klass = Doc do
10
10
  key :title, String
11
+ auto_increment!
11
12
  end
12
- @klass.auto_increment!
13
-
13
+
14
14
  @klass_override = Doc do
15
15
  key :title, String
16
+ auto_increment! :override => true
16
17
  end
17
- @klass_override.auto_increment! :override => true
18
18
  end
19
19
 
20
20
  should 'set id2 on create' do
@@ -0,0 +1,44 @@
1
+ # File.expand_path("../lib/mongomapper_id2.rb", __FILE__)
2
+ #
3
+ # require 'test_helper'
4
+ # require 'mongomapper_id2'
5
+ #
6
+ # class AutoIncrementTest < Test::Unit::TestCase
7
+ # context 'autoincrementing' do
8
+ # setup do
9
+ # @klass = EDoc do
10
+ # key :title, String
11
+ # auto_increment!
12
+ # end
13
+ #
14
+ # @klass_override = EDoc do
15
+ # key :title, String
16
+ # auto_increment! :override => true
17
+ # end
18
+ # end
19
+ #
20
+ # should 'set id2 on create' do
21
+ # doc = @klass.new(:title => 'The Simpsons Movie')
22
+ # doc.id2.should be(nil)
23
+ # doc.save
24
+ # doc.id2.should_not be(nil)
25
+ # id2 = doc.id2
26
+ # doc.save
27
+ # doc.id2.should eql id2
28
+ # end
29
+ #
30
+ # should 'auto increment id2' do
31
+ # doc = @klass.new(:title => 'Pirates of Silicon Valley')
32
+ # doc.save
33
+ # doc2 = @klass.new(:title => 'Tropa de Elite')
34
+ # doc2.save
35
+ # (doc.id2 + 1).should eql doc2.id2
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
43
+ # end
44
+ # end
metadata CHANGED
@@ -1,98 +1,125 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: mongomapper_id2
3
- version: !ruby/object:Gem::Version
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.5
4
5
  prerelease:
5
- version: 0.0.4
6
6
  platform: ruby
7
- authors:
7
+ authors:
8
8
  - Pablo Cantero
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
-
13
- date: 2011-06-16 00:00:00 Z
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
12
+ date: 2012-05-29 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
16
15
  name: mongo_mapper
17
- prerelease: false
18
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
19
17
  none: false
20
- requirements:
21
- - - ">="
22
- - !ruby/object:Gem::Version
23
- version: "0"
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
24
22
  type: :runtime
25
- version_requirements: *id001
26
- - !ruby/object:Gem::Dependency
27
- name: log_buddy
28
23
  prerelease: false
29
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: !ruby/object:Gem::Requirement
30
25
  none: false
31
- requirements:
32
- - - ">="
33
- - !ruby/object:Gem::Version
34
- version: "0"
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: log_buddy
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
35
38
  type: :development
36
- version_requirements: *id002
37
- - !ruby/object:Gem::Dependency
38
- name: jnunemaker-matchy
39
39
  prerelease: false
40
- requirement: &id003 !ruby/object:Gem::Requirement
40
+ version_requirements: !ruby/object:Gem::Requirement
41
41
  none: false
42
- requirements:
43
- - - ">="
44
- - !ruby/object:Gem::Version
45
- version: "0"
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: jnunemaker-matchy
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
46
54
  type: :development
47
- version_requirements: *id003
48
- - !ruby/object:Gem::Dependency
49
- name: shoulda
50
55
  prerelease: false
51
- requirement: &id004 !ruby/object:Gem::Requirement
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: shoulda
64
+ requirement: !ruby/object:Gem::Requirement
52
65
  none: false
53
- requirements:
54
- - - ">="
55
- - !ruby/object:Gem::Version
56
- version: "0"
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
57
70
  type: :development
58
- version_requirements: *id004
59
- - !ruby/object:Gem::Dependency
60
- name: timecop
61
71
  prerelease: false
62
- requirement: &id005 !ruby/object:Gem::Requirement
72
+ version_requirements: !ruby/object:Gem::Requirement
63
73
  none: false
64
- requirements:
65
- - - ">="
66
- - !ruby/object:Gem::Version
67
- version: "0"
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: timecop
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
68
86
  type: :development
69
- version_requirements: *id005
70
- - !ruby/object:Gem::Dependency
71
- name: mocha
72
87
  prerelease: false
73
- requirement: &id006 !ruby/object:Gem::Requirement
88
+ version_requirements: !ruby/object:Gem::Requirement
74
89
  none: false
75
- requirements:
76
- - - ">="
77
- - !ruby/object:Gem::Version
78
- version: "0"
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: mocha
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
79
102
  type: :development
80
- version_requirements: *id006
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
81
110
  description:
82
- email:
111
+ email:
83
112
  - pablo@pablocantero
84
113
  executables: []
85
-
86
114
  extensions: []
87
-
88
115
  extra_rdoc_files: []
89
-
90
- files:
116
+ files:
91
117
  - lib/incrementor.rb
92
118
  - lib/mongomapper_id2/version.rb
93
119
  - lib/mongomapper_id2.rb
94
120
  - test/_NOTE_ON_TESTING
95
- - test/functional/test_auto_increment.rb
121
+ - test/functional/test_auto_increment_doc.rb
122
+ - test/functional/test_auto_increment_embed.rb
96
123
  - test/models.rb
97
124
  - test/test_active_model_lint.rb
98
125
  - test/test_helper.rb
@@ -100,30 +127,27 @@ files:
100
127
  - README.rdoc
101
128
  homepage: https://github.com/phstc/mongomapper_id2
102
129
  licenses: []
103
-
104
130
  post_install_message:
105
131
  rdoc_options: []
106
-
107
- require_paths:
132
+ require_paths:
108
133
  - lib
109
- required_ruby_version: !ruby/object:Gem::Requirement
134
+ required_ruby_version: !ruby/object:Gem::Requirement
110
135
  none: false
111
- requirements:
112
- - - ">="
113
- - !ruby/object:Gem::Version
114
- version: "0"
115
- required_rubygems_version: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - ! '>='
138
+ - !ruby/object:Gem::Version
139
+ version: '0'
140
+ required_rubygems_version: !ruby/object:Gem::Requirement
116
141
  none: false
117
- requirements:
118
- - - ">="
119
- - !ruby/object:Gem::Version
120
- version: "0"
142
+ requirements:
143
+ - - ! '>='
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
121
146
  requirements: []
122
-
123
147
  rubyforge_project: mongomapper_id2
124
- rubygems_version: 1.8.5
148
+ rubygems_version: 1.8.24
125
149
  signing_key:
126
150
  specification_version: 3
127
- summary: "It\xE2\x80\x99s a MongoMapper\xE2\x80\x99s plugin to add auto incremented id to your MongoMapper\xE2\x80\x99s documents"
151
+ summary: It is a MongoMapper's plugin to add auto incremented id in MongoMapper's
152
+ documents.
128
153
  test_files: []
129
-