mongoid-autoinc 0.3.2 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +9 -0
- data/lib/autoinc.rb +12 -2
- data/lib/autoinc/version.rb +1 -1
- metadata +25 -19
data/README.rdoc
CHANGED
@@ -58,6 +58,10 @@ You can scope on document fields. For example:
|
|
58
58
|
|
59
59
|
end
|
60
60
|
|
61
|
+
Scope can also be a Proc:
|
62
|
+
|
63
|
+
increments :number, :scope => lambda { patient.name }
|
64
|
+
|
61
65
|
=== Custom Increment Trigger
|
62
66
|
|
63
67
|
You can trigger the assignment of an increment field manually by passing:
|
@@ -89,6 +93,11 @@ This allows for more flexible assignment of your increment number:
|
|
89
93
|
$ bundle install
|
90
94
|
$ bundle exec spec
|
91
95
|
|
96
|
+
== Contributions
|
97
|
+
|
98
|
+
Thanks to Johnny Shields (@johnnyshields) for implementing proc support to scopes
|
99
|
+
|
100
|
+
|
92
101
|
== Copyright
|
93
102
|
|
94
103
|
See LICENSE for details
|
data/lib/autoinc.rb
CHANGED
@@ -43,13 +43,23 @@ module Mongoid
|
|
43
43
|
end
|
44
44
|
|
45
45
|
def increment!(field, options)
|
46
|
-
scope_key = options[:scope] ?
|
46
|
+
scope_key = options[:scope] ? evaluate_scope(options[:scope]) : nil
|
47
47
|
write_attribute(
|
48
|
-
|
48
|
+
field.to_sym, Mongoid::Autoinc::Incrementor.new(
|
49
49
|
self.class.model_name, field, scope_key).inc
|
50
50
|
)
|
51
51
|
end
|
52
52
|
|
53
|
+
def evaluate_scope(scope)
|
54
|
+
if scope.is_a? Symbol
|
55
|
+
send(scope)
|
56
|
+
elsif scope.is_a? Proc
|
57
|
+
instance_exec &scope
|
58
|
+
else
|
59
|
+
raise 'scope is not a Symbol or a Proc'
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
53
63
|
end
|
54
64
|
|
55
65
|
end
|
data/lib/autoinc/version.rb
CHANGED
metadata
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongoid-autoinc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.2
|
5
4
|
prerelease:
|
5
|
+
version: 0.4.0
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Robert Beekman
|
@@ -11,11 +11,17 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2013-
|
14
|
+
date: 2013-03-25 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
|
-
|
17
|
+
version_requirements: !ruby/object:Gem::Requirement
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '3.0'
|
22
|
+
none: false
|
18
23
|
prerelease: false
|
24
|
+
name: mongoid
|
19
25
|
requirement: !ruby/object:Gem::Requirement
|
20
26
|
requirements:
|
21
27
|
- - ~>
|
@@ -23,15 +29,15 @@ dependencies:
|
|
23
29
|
version: '3.0'
|
24
30
|
none: false
|
25
31
|
type: :runtime
|
32
|
+
- !ruby/object:Gem::Dependency
|
26
33
|
version_requirements: !ruby/object:Gem::Requirement
|
27
34
|
requirements:
|
28
|
-
- -
|
35
|
+
- - ! '>='
|
29
36
|
- !ruby/object:Gem::Version
|
30
|
-
version: '
|
37
|
+
version: '0'
|
31
38
|
none: false
|
32
|
-
- !ruby/object:Gem::Dependency
|
33
|
-
name: activesupport
|
34
39
|
prerelease: false
|
40
|
+
name: activesupport
|
35
41
|
requirement: !ruby/object:Gem::Requirement
|
36
42
|
requirements:
|
37
43
|
- - ! '>='
|
@@ -39,15 +45,15 @@ dependencies:
|
|
39
45
|
version: '0'
|
40
46
|
none: false
|
41
47
|
type: :runtime
|
48
|
+
- !ruby/object:Gem::Dependency
|
42
49
|
version_requirements: !ruby/object:Gem::Requirement
|
43
50
|
requirements:
|
44
51
|
- - ! '>='
|
45
52
|
- !ruby/object:Gem::Version
|
46
53
|
version: '0'
|
47
54
|
none: false
|
48
|
-
- !ruby/object:Gem::Dependency
|
49
|
-
name: rake
|
50
55
|
prerelease: false
|
56
|
+
name: rake
|
51
57
|
requirement: !ruby/object:Gem::Requirement
|
52
58
|
requirements:
|
53
59
|
- - ! '>='
|
@@ -55,15 +61,15 @@ dependencies:
|
|
55
61
|
version: '0'
|
56
62
|
none: false
|
57
63
|
type: :runtime
|
64
|
+
- !ruby/object:Gem::Dependency
|
58
65
|
version_requirements: !ruby/object:Gem::Requirement
|
59
66
|
requirements:
|
60
67
|
- - ! '>='
|
61
68
|
- !ruby/object:Gem::Version
|
62
69
|
version: '0'
|
63
70
|
none: false
|
64
|
-
- !ruby/object:Gem::Dependency
|
65
|
-
name: foreman
|
66
71
|
prerelease: false
|
72
|
+
name: foreman
|
67
73
|
requirement: !ruby/object:Gem::Requirement
|
68
74
|
requirements:
|
69
75
|
- - ! '>='
|
@@ -71,15 +77,15 @@ dependencies:
|
|
71
77
|
version: '0'
|
72
78
|
none: false
|
73
79
|
type: :development
|
80
|
+
- !ruby/object:Gem::Dependency
|
74
81
|
version_requirements: !ruby/object:Gem::Requirement
|
75
82
|
requirements:
|
76
83
|
- - ! '>='
|
77
84
|
- !ruby/object:Gem::Version
|
78
85
|
version: '0'
|
79
86
|
none: false
|
80
|
-
- !ruby/object:Gem::Dependency
|
81
|
-
name: rspec
|
82
87
|
prerelease: false
|
88
|
+
name: rspec
|
83
89
|
requirement: !ruby/object:Gem::Requirement
|
84
90
|
requirements:
|
85
91
|
- - ! '>='
|
@@ -87,12 +93,6 @@ dependencies:
|
|
87
93
|
version: '0'
|
88
94
|
none: false
|
89
95
|
type: :development
|
90
|
-
version_requirements: !ruby/object:Gem::Requirement
|
91
|
-
requirements:
|
92
|
-
- - ! '>='
|
93
|
-
- !ruby/object:Gem::Version
|
94
|
-
version: '0'
|
95
|
-
none: false
|
96
96
|
description: Think auto incrementing field from MySQL for mongoid.
|
97
97
|
email:
|
98
98
|
- robert@80beans.com
|
@@ -117,12 +117,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
117
117
|
- - ! '>='
|
118
118
|
- !ruby/object:Gem::Version
|
119
119
|
version: '0'
|
120
|
+
segments:
|
121
|
+
- 0
|
122
|
+
hash: -1490664978926103703
|
120
123
|
none: false
|
121
124
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
122
125
|
requirements:
|
123
126
|
- - ! '>='
|
124
127
|
- !ruby/object:Gem::Version
|
125
128
|
version: '0'
|
129
|
+
segments:
|
130
|
+
- 0
|
131
|
+
hash: -1490664978926103703
|
126
132
|
none: false
|
127
133
|
requirements: []
|
128
134
|
rubyforge_project:
|