mongoid-autoinc 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. data/README.rdoc +14 -13
  2. data/lib/autoinc/version.rb +1 -1
  3. data/lib/autoinc.rb +16 -20
  4. metadata +38 -13
data/README.rdoc CHANGED
@@ -3,6 +3,7 @@
3
3
  A mongoid plugin to add auto incrementing fields to your documents.
4
4
 
5
5
  {<img src="https://secure.travis-ci.org/80beans/mongoid-autoinc.png" />}[http://travis-ci.org/#!/80beans/mongoid-autoinc]
6
+ {<img src="https://codeclimate.com/badge.png" />}[https://codeclimate.com/github/80beans/mongoid-autoinc]
6
7
 
7
8
  == Installation
8
9
 
@@ -53,27 +54,27 @@ You can scope on document fields. For example:
53
54
  === Custom Increment Trigger
54
55
 
55
56
  You can trigger the assignment of an increment field manually by passing:
56
- `:auto => false` to the increment field.
57
+ +:auto => false+ to the increment field.
57
58
  This allows for more flexible assignment of your increment number:
58
59
 
59
- class Intern
60
- include Mongoid::Document
61
- include Mongoid::Autoinc
60
+ class Intern
61
+ include Mongoid::Document
62
+ include Mongoid::Autoinc
62
63
 
63
- field :name
64
- field :number
64
+ field :name
65
+ field :number
65
66
 
66
- increments :number, :auto => false
67
+ increments :number, :auto => false
67
68
 
68
- after_save :assign_number_to_jd
69
+ after_save :assign_number_to_jd
69
70
 
70
- protected
71
+ protected
71
72
 
72
- def assign_number_to_jd
73
- assign!(:number) if number.blank? && name == 'J.D.'
74
- end
73
+ def assign_number_to_jd
74
+ assign!(:number) if number.blank? && name == 'J.D.'
75
+ end
75
76
 
76
- end
77
+ end
77
78
 
78
79
  === Development
79
80
 
@@ -1,3 +1,3 @@
1
1
  module Mongoid::Autoinc
2
- VERSION = "0.0.4"
2
+ VERSION = "0.1.1"
3
3
  end
data/lib/autoinc.rb CHANGED
@@ -25,29 +25,25 @@ module Mongoid
25
25
 
26
26
  end
27
27
 
28
- module InstanceMethods
29
-
30
- def assign!(field)
31
- options = self.class.incrementing_fields[field]
32
- raise AutoIncrementsError if options[:auto]
33
- raise AlreadyAssignedError if send(field).present?
34
- increment!(field, options)
35
- end
36
-
37
- def update_auto_increments
38
- self.class.incrementing_fields.each do |field, options|
39
- increment!(field, options) if options[:auto]
40
- end
41
- end
28
+ def assign!(field)
29
+ options = self.class.incrementing_fields[field]
30
+ raise AutoIncrementsError if options[:auto]
31
+ raise AlreadyAssignedError if send(field).present?
32
+ increment!(field, options)
33
+ end
42
34
 
43
- def increment!(field, options)
44
- scope_key = options[:scope] ? send(options[:scope]) : nil
45
- write_attribute(
46
- field.to_sym,
47
- Mongoid::Autoinc::Incrementor.new(self.class.name, field, scope_key).inc
48
- )
35
+ def update_auto_increments
36
+ self.class.incrementing_fields.each do |field, options|
37
+ increment!(field, options) if options[:auto]
49
38
  end
39
+ end
50
40
 
41
+ def increment!(field, options)
42
+ scope_key = options[:scope] ? send(options[:scope]) : nil
43
+ write_attribute(
44
+ field.to_sym,
45
+ Mongoid::Autoinc::Incrementor.new(self.class.name, field, scope_key).inc
46
+ )
51
47
  end
52
48
 
53
49
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongoid-autoinc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,11 +10,11 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-07-03 00:00:00.000000000 Z
13
+ date: 2012-08-14 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: mongoid
17
- requirement: &2152268260 !ruby/object:Gem::Requirement
17
+ requirement: !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ! '>='
@@ -22,10 +22,15 @@ dependencies:
22
22
  version: '0'
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *2152268260
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ! '>='
29
+ - !ruby/object:Gem::Version
30
+ version: '0'
26
31
  - !ruby/object:Gem::Dependency
27
32
  name: bson_ext
28
- requirement: &2152267720 !ruby/object:Gem::Requirement
33
+ requirement: !ruby/object:Gem::Requirement
29
34
  none: false
30
35
  requirements:
31
36
  - - ! '>='
@@ -33,10 +38,15 @@ dependencies:
33
38
  version: '0'
34
39
  type: :runtime
35
40
  prerelease: false
36
- version_requirements: *2152267720
41
+ version_requirements: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ! '>='
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
37
47
  - !ruby/object:Gem::Dependency
38
48
  name: rspec
39
- requirement: &2152267180 !ruby/object:Gem::Requirement
49
+ requirement: !ruby/object:Gem::Requirement
40
50
  none: false
41
51
  requirements:
42
52
  - - ! '>='
@@ -44,10 +54,15 @@ dependencies:
44
54
  version: '0'
45
55
  type: :runtime
46
56
  prerelease: false
47
- version_requirements: *2152267180
57
+ version_requirements: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ! '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
48
63
  - !ruby/object:Gem::Dependency
49
64
  name: activesupport
50
- requirement: &2152266400 !ruby/object:Gem::Requirement
65
+ requirement: !ruby/object:Gem::Requirement
51
66
  none: false
52
67
  requirements:
53
68
  - - ! '>='
@@ -55,10 +70,15 @@ dependencies:
55
70
  version: '0'
56
71
  type: :runtime
57
72
  prerelease: false
58
- version_requirements: *2152266400
73
+ version_requirements: !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ! '>='
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
59
79
  - !ruby/object:Gem::Dependency
60
80
  name: rake
61
- requirement: &2152265640 !ruby/object:Gem::Requirement
81
+ requirement: !ruby/object:Gem::Requirement
62
82
  none: false
63
83
  requirements:
64
84
  - - ! '>='
@@ -66,7 +86,12 @@ dependencies:
66
86
  version: '0'
67
87
  type: :runtime
68
88
  prerelease: false
69
- version_requirements: *2152265640
89
+ version_requirements: !ruby/object:Gem::Requirement
90
+ none: false
91
+ requirements:
92
+ - - ! '>='
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
70
95
  description: Think auto incrementing field from MySQL for mongoid.
71
96
  email:
72
97
  - robert@80beans.com
@@ -99,7 +124,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
99
124
  version: '0'
100
125
  requirements: []
101
126
  rubyforge_project:
102
- rubygems_version: 1.8.10
127
+ rubygems_version: 1.8.19
103
128
  signing_key:
104
129
  specification_version: 3
105
130
  summary: Add auto incrementing fields to mongoid documents