mongoid_auto_increment_id 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/mongoid_auto_increment_id.rb +10 -3
  2. metadata +5 -5
@@ -1,10 +1,13 @@
1
1
  module Mongoid
2
- class Identity
2
+ class Identity
3
+ def identify
4
+ nil
5
+ end
6
+
3
7
  # Generate auto increment id
4
8
  def generate_id
5
9
  counter = Mongoid.master.collection("mongoid.auto_increment_ids")
6
- table_name = @document.class.to_s.tableize
7
- o = counter.find_and_modify({:query => {:_id => table_name},
10
+ o = counter.find_and_modify({:query => {:_id => document.collection_name},
8
11
  :update => {:$inc => {:c => 1}},
9
12
  :new => true,
10
13
  :upsert => true})
@@ -13,11 +16,15 @@ module Mongoid
13
16
  end
14
17
 
15
18
  module Document
19
+ # define Integer for id field
16
20
  included do
17
21
  identity :type => Integer
18
22
  end
19
23
 
24
+ # hack id nil when Document.new
20
25
  def identify
26
+ Identity.new(self).create
27
+ nil
21
28
  end
22
29
 
23
30
  alias_method :super_as_document,:as_document
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongoid_auto_increment_id
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-10-18 00:00:00.000000000Z
12
+ date: 2011-11-06 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: mongoid
16
- requirement: &2156434260 !ruby/object:Gem::Requirement
16
+ requirement: &70101329139860 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,7 +21,7 @@ dependencies:
21
21
  version: 2.2.0
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *2156434260
24
+ version_requirements: *70101329139860
25
25
  description: This gem for change Mongoid id field as Integer like MySQL.
26
26
  email:
27
27
  - huacnlee@gmail.com
@@ -51,7 +51,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
51
51
  version: '0'
52
52
  requirements: []
53
53
  rubyforge_project:
54
- rubygems_version: 1.8.6
54
+ rubygems_version: 1.8.10
55
55
  signing_key:
56
56
  specification_version: 3
57
57
  summary: Override id field with MySQL like auto increment for Mongoid