auto_increment 1.5.0 → 1.5.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f12e8fb8b608aa185f3c19fdca1f32225a2bcc114e56fe8b00833aa75690170a
4
- data.tar.gz: f14390de2bb38ac2df6cb3d0aca1db054aa43ebd3e19960a1a30a333c6c5201f
3
+ metadata.gz: c9594b9706ad92811966e6862c951db1a17cd1e59e5a79228620786e6ad56e22
4
+ data.tar.gz: bb43b244c18c12775f558eab8e84e2b685a6ab7ceec1b34bbf81f88b7114af1d
5
5
  SHA512:
6
- metadata.gz: 0631b7abae5d4a9f4b190a6d2943f7a95d6d7dd450e289990bde8a1d50a52921240921e59d98cb335b84d440db3de90d5a1bbfcce4d45eca37222d357b26f342
7
- data.tar.gz: 1da7acf3f3d9acfb443412b862d387cfbe8fc3c51c5886702bf80cb4376d8b2965fc9c83be98312956b7aba560615fdd01507e937b508c2aa125c256a9127e76
6
+ metadata.gz: 2e853a5b5164e991e3159aa46a8b4be40f409a408b001153bf09ee2751073b6168b88e1c2c9b5204a29eaafbaf0942df33d1a8a3ed5ccd0aa4517dbd26b42631
7
+ data.tar.gz: 6ae4fb78475f0e772c247d98ff7ca3a0aba2c329e8734ca1c3878c1a8fc781750a9ea9fa4b7a734f1e0fe449810cb93af95fe5e4aecd9b09f6757df81cdb5e24
@@ -2,12 +2,13 @@ language: ruby
2
2
  sudo: false
3
3
  cache: bundler
4
4
  rvm:
5
- - 2.4.3
6
- - 2.5.0
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.10.gemfile
11
- - gemfiles/rails_5.0.6.gemfile
12
- - gemfiles/rails_5.1.4.gemfile
13
- - gemfiles/rails_5.2.0.beta2.gemfile
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
@@ -1,8 +1,9 @@
1
1
  RAILS_VERSIONS = %w(
2
- 4.2.10
3
- 5.0.6
4
- 5.1.4
5
- 5.2.0.beta2
2
+ 4.2.11.1
3
+ 5.0.7.2
4
+ 5.1.6.2
5
+ 5.2.2.1
6
+ 6.0.0.beta3
6
7
  )
7
8
 
8
9
  RAILS_VERSIONS.each do |version|
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)
@@ -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', '< 5.3'
22
- s.add_dependency 'activesupport', '>= 4.0', '< 5.3'
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
@@ -0,0 +1,2 @@
1
+ ---
2
+ BUNDLE_RETRY: "1"
@@ -2,7 +2,7 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- gem "activerecord", "4.2.8"
6
- gem "activesupport", "4.2.8"
5
+ gem "activerecord", "4.2.11.1"
6
+ gem "activesupport", "4.2.11.1"
7
7
 
8
8
  gemspec path: "../"
@@ -2,7 +2,7 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- gem "activerecord", "4.0.13"
6
- gem "activesupport", "4.0.13"
5
+ gem "activerecord", "5.0.7.2"
6
+ gem "activesupport", "5.0.7.2"
7
7
 
8
8
  gemspec path: "../"
@@ -2,7 +2,7 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- gem "activerecord", "4.1.15"
6
- gem "activesupport", "4.1.15"
5
+ gem "activerecord", "5.1.6.2"
6
+ gem "activesupport", "5.1.6.2"
7
7
 
8
8
  gemspec path: "../"
@@ -2,7 +2,7 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- gem "activerecord", "5.0.2"
6
- gem "activesupport", "5.0.2"
5
+ gem "activerecord", "5.2.2.1"
6
+ gem "activesupport", "5.2.2.1"
7
7
 
8
8
  gemspec path: "../"
@@ -0,0 +1,8 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "activerecord", "6.0.0.beta3"
6
+ gem "activesupport", "6.0.0.beta3"
7
+
8
+ gemspec path: "../"
@@ -9,8 +9,9 @@ module AutoIncrement
9
9
  end
10
10
 
11
11
  @column = column || options[:column] || :code
12
- @options = options.reverse_merge scope: nil, initial: 1, force: false
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 @record.class
54
+ query = build_scopes(build_model_scope(@record.class))
46
55
  query.lock if lock?
47
56
 
48
57
  if string?
@@ -1,4 +1,4 @@
1
1
  # +AutoIncrement::VERSION+
2
2
  module AutoIncrement
3
- VERSION = '1.5.0'.freeze
3
+ VERSION = '1.5.1'.freeze
4
4
  end
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
- @user_account1 = @account1.users.create name: 'Felipe', letter_code: 'Z'
11
- @user_account2 = @account2.users.create name: 'Daniel'
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(@user_account1.letter_code).to eq 'A' }
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(@user_account2.letter_code).to eq 'A' }
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(@user_account1.letter_code).to eq 'A' }
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
@@ -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
- lock: true
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.0
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: 2018-01-21 00:00:00.000000000 Z
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: '5.3'
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: '5.3'
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: '5.3'
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: '5.3'
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: '0'
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: '0'
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/rails_4.0.13.gemfile
226
- - gemfiles/rails_4.1.15.gemfile
227
- - gemfiles/rails_4.2.10.gemfile
228
- - gemfiles/rails_4.2.8.gemfile
229
- - gemfiles/rails_5.0.2.gemfile
230
- - gemfiles/rails_5.0.6.gemfile
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
- rubyforge_project:
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
@@ -1,8 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "activerecord", "4.2.10"
6
- gem "activesupport", "4.2.10"
7
-
8
- gemspec :path => "../"
@@ -1,8 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "activerecord", "5.0.6"
6
- gem "activesupport", "5.0.6"
7
-
8
- gemspec :path => "../"
@@ -1,8 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "activerecord", "5.1.0"
6
- gem "activesupport", "5.1.0"
7
-
8
- gemspec path: "../"
@@ -1,8 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "activerecord", "5.1.4"
6
- gem "activesupport", "5.1.4"
7
-
8
- gemspec :path => "../"
@@ -1,8 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "activerecord", "5.2.0.beta2"
6
- gem "activesupport", "5.2.0.beta2"
7
-
8
- gemspec :path => "../"