auto_increment 1.3.0 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -1
- data/lib/auto_increment/active_record.rb +5 -1
- data/lib/auto_increment/incrementor.rb +3 -0
- data/lib/auto_increment/version.rb +1 -1
- data/spec/db/sync.db +0 -0
- data/spec/lib/active_record_spec.rb +9 -0
- data/spec/models/account.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 564b658b6b2444141f7eb814e2125c480c06301c
|
4
|
+
data.tar.gz: ef6c4950e669707eac1d8f97a63e627708db2e2f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7792a1be4db338672e977040591fcd57a3229da7b35f54fed2e2c04dcafadd2b1f659a4512eefbb0e14888eed60db9fcbabe3553c18c24a6f49600f0d24ec053
|
7
|
+
data.tar.gz: a401806c20c58968755790e1231b5ce5f9a1490507b8e37cdb60e20670d0c9b9fe493c1d8125a637a10b91a76bd375e7278c5884629577a997e4433ccdcaa401
|
data/README.md
CHANGED
@@ -38,7 +38,7 @@ And your code field will be incremented
|
|
38
38
|
|
39
39
|
So you have a different column or need a scope. auto_increment provides options. You can use it like this:
|
40
40
|
|
41
|
-
auto_increment :letter, scope: [:account_id, :job_id], initial: 'C', force: true, lock: false
|
41
|
+
auto_increment :letter, scope: [:account_id, :job_id], initial: 'C', force: true, lock: false, before: :create
|
42
42
|
|
43
43
|
First argument is the column that will be incremented. Can be integer or string.
|
44
44
|
|
@@ -46,6 +46,7 @@ First argument is the column that will be incremented. Can be integer or string.
|
|
46
46
|
* initial: initial value of column (default: 1)
|
47
47
|
* force: you can set a value before create and auto_increment will not change that, but if you do want this, set force to true (default: false)
|
48
48
|
* lock: you can set a lock on the max query. (default: false)
|
49
|
+
* before: you can choose a different callback to be used (:create, :save, :validation) (default: create)
|
49
50
|
|
50
51
|
|
51
52
|
## Compatibility
|
@@ -6,7 +6,11 @@ module AutoIncrement
|
|
6
6
|
# +AutoIncrement::ActiveRecord::ClassMethods+
|
7
7
|
module ClassMethods
|
8
8
|
def auto_increment(column = nil, options = {})
|
9
|
-
|
9
|
+
options.reverse_merge! before: :create
|
10
|
+
|
11
|
+
callback = "before_#{ options[:before]}"
|
12
|
+
|
13
|
+
self.send callback, Incrementor.new(column, options)
|
10
14
|
end
|
11
15
|
end
|
12
16
|
end
|
data/spec/db/sync.db
CHANGED
Binary file
|
@@ -53,4 +53,13 @@ describe AutoIncrement do
|
|
53
53
|
it { expect(@accounts.size).to eq 25 }
|
54
54
|
it { expect(account_last_letter_code).to eq 'Y' }
|
55
55
|
end
|
56
|
+
|
57
|
+
|
58
|
+
describe 'set before validation' do
|
59
|
+
account3 = Account.new
|
60
|
+
account3.valid?
|
61
|
+
|
62
|
+
it { expect(account3.code).not_to be_nil }
|
63
|
+
end
|
64
|
+
|
56
65
|
end
|
data/spec/models/account.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: auto_increment
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Felipe Diesel
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-11-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|