auto_increment 1.5.0 → 1.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +7 -6
- data/Appraisals +5 -4
- data/README.md +2 -1
- data/auto_increment.gemspec +3 -3
- data/gemfiles/.bundle/config +2 -0
- data/gemfiles/{rails_4.2.8.gemfile → rails_4.2.11.1.gemfile} +2 -2
- data/gemfiles/{rails_4.0.13.gemfile → rails_5.0.7.2.gemfile} +2 -2
- data/gemfiles/{rails_4.1.15.gemfile → rails_5.1.6.2.gemfile} +2 -2
- data/gemfiles/{rails_5.0.2.gemfile → rails_5.2.2.1.gemfile} +2 -2
- data/gemfiles/rails_6.0.0.beta3.gemfile +8 -0
- data/lib/auto_increment/incrementor.rb +11 -2
- data/lib/auto_increment/version.rb +1 -1
- data/spec/db/sync.db +0 -0
- data/spec/lib/active_record_spec.rb +11 -5
- data/spec/models/user.rb +5 -1
- metadata +17 -21
- data/gemfiles/rails_4.2.10.gemfile +0 -8
- data/gemfiles/rails_5.0.6.gemfile +0 -8
- data/gemfiles/rails_5.1.0.gemfile +0 -8
- data/gemfiles/rails_5.1.4.gemfile +0 -8
- data/gemfiles/rails_5.2.0.beta2.gemfile +0 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c9594b9706ad92811966e6862c951db1a17cd1e59e5a79228620786e6ad56e22
|
4
|
+
data.tar.gz: bb43b244c18c12775f558eab8e84e2b685a6ab7ceec1b34bbf81f88b7114af1d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2e853a5b5164e991e3159aa46a8b4be40f409a408b001153bf09ee2751073b6168b88e1c2c9b5204a29eaafbaf0942df33d1a8a3ed5ccd0aa4517dbd26b42631
|
7
|
+
data.tar.gz: 6ae4fb78475f0e772c247d98ff7ca3a0aba2c329e8734ca1c3878c1a8fc781750a9ea9fa4b7a734f1e0fe449810cb93af95fe5e4aecd9b09f6757df81cdb5e24
|
data/.travis.yml
CHANGED
@@ -2,12 +2,13 @@ language: ruby
|
|
2
2
|
sudo: false
|
3
3
|
cache: bundler
|
4
4
|
rvm:
|
5
|
-
- 2.4
|
6
|
-
- 2.
|
5
|
+
- 2.5.4
|
6
|
+
- 2.6.2
|
7
7
|
before_install:
|
8
8
|
- gem update --system
|
9
9
|
gemfile:
|
10
|
-
- gemfiles/rails_4.2.
|
11
|
-
- gemfiles/rails_5.0.
|
12
|
-
- gemfiles/rails_5.1.
|
13
|
-
- gemfiles/rails_5.2.
|
10
|
+
- gemfiles/rails_4.2.11.1.gemfile
|
11
|
+
- gemfiles/rails_5.0.7.2.gemfile
|
12
|
+
- gemfiles/rails_5.1.6.2.gemfile
|
13
|
+
- gemfiles/rails_5.2.2.1.gemfile
|
14
|
+
- gemfiles/rails_6.0.0.beta3.gemfile
|
data/Appraisals
CHANGED
data/README.md
CHANGED
@@ -38,11 +38,12 @@ 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, before: :create
|
41
|
+
auto_increment :letter, scope: [:account_id, :job_id], model_scope: :in_account, 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
|
|
45
45
|
* scope: you can define columns that will be scoped and you can use as many as you want (default: nil)
|
46
|
+
* model_scope: you can define model scopes that will be executed and you can use as many as you want (default: nil)
|
46
47
|
* initial: initial value of column (default: 1)
|
47
48
|
* 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
49
|
* lock: you can set a lock on the max query. (default: false)
|
data/auto_increment.gemspec
CHANGED
@@ -18,8 +18,8 @@ Gem::Specification.new do |s|
|
|
18
18
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
19
|
s.require_paths = ['lib']
|
20
20
|
|
21
|
-
s.add_dependency 'activerecord', '>= 4.0', '<
|
22
|
-
s.add_dependency 'activesupport', '>= 4.0', '<
|
21
|
+
s.add_dependency 'activerecord', '>= 4.0', '< 6.1'
|
22
|
+
s.add_dependency 'activesupport', '>= 4.0', '< 6.1'
|
23
23
|
|
24
24
|
s.add_development_dependency 'bundler'
|
25
25
|
s.add_development_dependency 'rake'
|
@@ -33,5 +33,5 @@ Gem::Specification.new do |s|
|
|
33
33
|
s.add_development_dependency 'database_cleaner'
|
34
34
|
s.add_development_dependency 'appraisal'
|
35
35
|
|
36
|
-
s.add_development_dependency 'sqlite3'
|
36
|
+
s.add_development_dependency 'sqlite3', '~> 1.3.13'
|
37
37
|
end
|
@@ -9,8 +9,9 @@ module AutoIncrement
|
|
9
9
|
end
|
10
10
|
|
11
11
|
@column = column || options[:column] || :code
|
12
|
-
@options = options.reverse_merge
|
12
|
+
@options = options.reverse_merge initial: 1, force: false
|
13
13
|
@options[:scope] = [@options[:scope]] unless @options[:scope].is_a? Array
|
14
|
+
@options[:model_scope] = [@options[:model_scope]] unless @options[:model_scope].is_a? Array
|
14
15
|
end
|
15
16
|
|
16
17
|
def before_create(record)
|
@@ -41,8 +42,16 @@ module AutoIncrement
|
|
41
42
|
query
|
42
43
|
end
|
43
44
|
|
45
|
+
def build_model_scope(query)
|
46
|
+
@options[:model_scope].reject(&:nil?).each do |scope|
|
47
|
+
query = query.send(scope)
|
48
|
+
end
|
49
|
+
|
50
|
+
query
|
51
|
+
end
|
52
|
+
|
44
53
|
def maximum
|
45
|
-
query = build_scopes
|
54
|
+
query = build_scopes(build_model_scope(@record.class))
|
46
55
|
query.lock if lock?
|
47
56
|
|
48
57
|
if string?
|
data/spec/db/sync.db
CHANGED
Binary file
|
@@ -7,17 +7,19 @@ describe AutoIncrement do
|
|
7
7
|
@account1 = Account.create name: 'My Account'
|
8
8
|
@account2 = Account.create name: 'Another Account', code: 50
|
9
9
|
|
10
|
-
@
|
11
|
-
@
|
10
|
+
@user1_account1 = @account1.users.create name: 'Felipe', letter_code: 'Z'
|
11
|
+
@user1_account2 = @account2.users.create name: 'Daniel'
|
12
|
+
@user2_account2 = @account2.users.create name: 'Mark'
|
13
|
+
@user3_account2 = @account2.users.create name: 'Robert'
|
12
14
|
end
|
13
15
|
|
14
16
|
describe 'initial' do
|
15
17
|
it { expect(@account1.code).to eq 1 }
|
16
|
-
it { expect(@
|
18
|
+
it { expect(@user1_account1.letter_code).to eq 'A' }
|
17
19
|
end
|
18
20
|
|
19
21
|
describe 'do not increment outside scope' do
|
20
|
-
it { expect(@
|
22
|
+
it { expect(@user1_account2.letter_code).to eq 'A' }
|
21
23
|
end
|
22
24
|
|
23
25
|
describe 'not set column if is already set' do
|
@@ -25,7 +27,7 @@ describe AutoIncrement do
|
|
25
27
|
end
|
26
28
|
|
27
29
|
describe 'set column if option force is used' do
|
28
|
-
it { expect(@
|
30
|
+
it { expect(@user1_account1.letter_code).to eq 'A' }
|
29
31
|
end
|
30
32
|
|
31
33
|
describe 'locks query for increment' do
|
@@ -60,4 +62,8 @@ describe AutoIncrement do
|
|
60
62
|
|
61
63
|
it { expect(account3.code).not_to be_nil }
|
62
64
|
end
|
65
|
+
|
66
|
+
describe 'uses model scopes' do
|
67
|
+
it { expect(@user3_account2.letter_code).to eq('C') }
|
68
|
+
end
|
63
69
|
end
|
data/spec/models/user.rb
CHANGED
@@ -1,7 +1,11 @@
|
|
1
1
|
# + Spec +User+
|
2
2
|
class User < ActiveRecord::Base
|
3
3
|
auto_increment :letter_code, scope: :account_id, initial: 'A', force: true,
|
4
|
-
|
4
|
+
lock: true, model_scope: :with_mark
|
5
5
|
|
6
6
|
belongs_to :account
|
7
|
+
|
8
|
+
default_scope -> { where 'name <> ?', 'Mark' }
|
9
|
+
|
10
|
+
scope :with_mark, -> { unscoped }
|
7
11
|
end
|
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.5.
|
4
|
+
version: 1.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Felipe Diesel
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-03-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -19,7 +19,7 @@ dependencies:
|
|
19
19
|
version: '4.0'
|
20
20
|
- - "<"
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version: '
|
22
|
+
version: '6.1'
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -29,7 +29,7 @@ dependencies:
|
|
29
29
|
version: '4.0'
|
30
30
|
- - "<"
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version: '
|
32
|
+
version: '6.1'
|
33
33
|
- !ruby/object:Gem::Dependency
|
34
34
|
name: activesupport
|
35
35
|
requirement: !ruby/object:Gem::Requirement
|
@@ -39,7 +39,7 @@ dependencies:
|
|
39
39
|
version: '4.0'
|
40
40
|
- - "<"
|
41
41
|
- !ruby/object:Gem::Version
|
42
|
-
version: '
|
42
|
+
version: '6.1'
|
43
43
|
type: :runtime
|
44
44
|
prerelease: false
|
45
45
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -49,7 +49,7 @@ dependencies:
|
|
49
49
|
version: '4.0'
|
50
50
|
- - "<"
|
51
51
|
- !ruby/object:Gem::Version
|
52
|
-
version: '
|
52
|
+
version: '6.1'
|
53
53
|
- !ruby/object:Gem::Dependency
|
54
54
|
name: bundler
|
55
55
|
requirement: !ruby/object:Gem::Requirement
|
@@ -194,16 +194,16 @@ dependencies:
|
|
194
194
|
name: sqlite3
|
195
195
|
requirement: !ruby/object:Gem::Requirement
|
196
196
|
requirements:
|
197
|
-
- - "
|
197
|
+
- - "~>"
|
198
198
|
- !ruby/object:Gem::Version
|
199
|
-
version:
|
199
|
+
version: 1.3.13
|
200
200
|
type: :development
|
201
201
|
prerelease: false
|
202
202
|
version_requirements: !ruby/object:Gem::Requirement
|
203
203
|
requirements:
|
204
|
-
- - "
|
204
|
+
- - "~>"
|
205
205
|
- !ruby/object:Gem::Version
|
206
|
-
version:
|
206
|
+
version: 1.3.13
|
207
207
|
description: Automaticaly increments a string or integer field in ActiveRecord.
|
208
208
|
email:
|
209
209
|
- felipediesel@gmail.com
|
@@ -222,15 +222,12 @@ files:
|
|
222
222
|
- README.md
|
223
223
|
- Rakefile
|
224
224
|
- auto_increment.gemspec
|
225
|
-
- gemfiles/
|
226
|
-
- gemfiles/rails_4.1.
|
227
|
-
- gemfiles/
|
228
|
-
- gemfiles/
|
229
|
-
- gemfiles/rails_5.
|
230
|
-
- gemfiles/
|
231
|
-
- gemfiles/rails_5.1.0.gemfile
|
232
|
-
- gemfiles/rails_5.1.4.gemfile
|
233
|
-
- gemfiles/rails_5.2.0.beta2.gemfile
|
225
|
+
- gemfiles/.bundle/config
|
226
|
+
- gemfiles/rails_4.2.11.1.gemfile
|
227
|
+
- gemfiles/rails_5.0.7.2.gemfile
|
228
|
+
- gemfiles/rails_5.1.6.2.gemfile
|
229
|
+
- gemfiles/rails_5.2.2.1.gemfile
|
230
|
+
- gemfiles/rails_6.0.0.beta3.gemfile
|
234
231
|
- lib/auto_increment.rb
|
235
232
|
- lib/auto_increment/active_record.rb
|
236
233
|
- lib/auto_increment/incrementor.rb
|
@@ -262,8 +259,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
262
259
|
- !ruby/object:Gem::Version
|
263
260
|
version: '0'
|
264
261
|
requirements: []
|
265
|
-
|
266
|
-
rubygems_version: 2.7.3
|
262
|
+
rubygems_version: 3.0.1
|
267
263
|
signing_key:
|
268
264
|
specification_version: 4
|
269
265
|
summary: Auto increment a string or integer field
|