auto_increment 1.5.2 → 1.6.0

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.
@@ -0,0 +1,143 @@
1
+ PATH
2
+ remote: ..
3
+ specs:
4
+ auto_increment (1.5.2)
5
+ activerecord (>= 6.0)
6
+ activesupport (>= 6.0)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ activemodel (6.1.7.6)
12
+ activesupport (= 6.1.7.6)
13
+ activerecord (6.1.7.6)
14
+ activemodel (= 6.1.7.6)
15
+ activesupport (= 6.1.7.6)
16
+ activesupport (6.1.7.6)
17
+ concurrent-ruby (~> 1.0, >= 1.0.2)
18
+ i18n (>= 1.6, < 2)
19
+ minitest (>= 5.1)
20
+ tzinfo (~> 2.0)
21
+ zeitwerk (~> 2.3)
22
+ appraisal (2.5.0)
23
+ bundler
24
+ rake
25
+ thor (>= 0.14.0)
26
+ ast (2.4.2)
27
+ coderay (1.1.3)
28
+ concurrent-ruby (1.2.2)
29
+ database_cleaner (2.0.2)
30
+ database_cleaner-active_record (>= 2, < 3)
31
+ database_cleaner-active_record (2.1.0)
32
+ activerecord (>= 5.a)
33
+ database_cleaner-core (~> 2.0.0)
34
+ database_cleaner-core (2.0.1)
35
+ diff-lcs (1.5.0)
36
+ ffi (1.16.3)
37
+ formatador (1.1.0)
38
+ fuubar (2.5.1)
39
+ rspec-core (~> 3.0)
40
+ ruby-progressbar (~> 1.4)
41
+ guard (2.18.1)
42
+ formatador (>= 0.2.4)
43
+ listen (>= 2.7, < 4.0)
44
+ lumberjack (>= 1.0.12, < 2.0)
45
+ nenv (~> 0.1)
46
+ notiffany (~> 0.0)
47
+ pry (>= 0.13.0)
48
+ shellany (~> 0.0)
49
+ thor (>= 0.18.1)
50
+ guard-compat (1.2.1)
51
+ guard-rspec (4.7.3)
52
+ guard (~> 2.1)
53
+ guard-compat (~> 1.1)
54
+ rspec (>= 2.99.0, < 4.0)
55
+ i18n (1.14.1)
56
+ concurrent-ruby (~> 1.0)
57
+ json (2.7.1)
58
+ language_server-protocol (3.17.0.3)
59
+ listen (3.8.0)
60
+ rb-fsevent (~> 0.10, >= 0.10.3)
61
+ rb-inotify (~> 0.9, >= 0.9.10)
62
+ lumberjack (1.2.10)
63
+ method_source (1.0.0)
64
+ minitest (5.20.0)
65
+ nenv (0.3.0)
66
+ notiffany (0.1.3)
67
+ nenv (~> 0.1)
68
+ shellany (~> 0.0)
69
+ parallel (1.24.0)
70
+ parser (3.2.2.4)
71
+ ast (~> 2.4.1)
72
+ racc
73
+ pry (0.14.2)
74
+ coderay (~> 1.1)
75
+ method_source (~> 1.0)
76
+ racc (1.7.3)
77
+ rainbow (3.1.1)
78
+ rake (13.1.0)
79
+ rb-fsevent (0.11.2)
80
+ rb-inotify (0.10.1)
81
+ ffi (~> 1.0)
82
+ regexp_parser (2.8.3)
83
+ rexml (3.2.6)
84
+ rspec (3.12.0)
85
+ rspec-core (~> 3.12.0)
86
+ rspec-expectations (~> 3.12.0)
87
+ rspec-mocks (~> 3.12.0)
88
+ rspec-core (3.12.2)
89
+ rspec-support (~> 3.12.0)
90
+ rspec-expectations (3.12.3)
91
+ diff-lcs (>= 1.2.0, < 2.0)
92
+ rspec-support (~> 3.12.0)
93
+ rspec-mocks (3.12.6)
94
+ diff-lcs (>= 1.2.0, < 2.0)
95
+ rspec-support (~> 3.12.0)
96
+ rspec-nc (0.3.0)
97
+ rspec (>= 3)
98
+ terminal-notifier (>= 1.4)
99
+ rspec-support (3.12.1)
100
+ rubocop (1.59.0)
101
+ json (~> 2.3)
102
+ language_server-protocol (>= 3.17.0)
103
+ parallel (~> 1.10)
104
+ parser (>= 3.2.2.4)
105
+ rainbow (>= 2.2.2, < 4.0)
106
+ regexp_parser (>= 1.8, < 3.0)
107
+ rexml (>= 3.2.5, < 4.0)
108
+ rubocop-ast (>= 1.30.0, < 2.0)
109
+ ruby-progressbar (~> 1.7)
110
+ unicode-display_width (>= 2.4.0, < 3.0)
111
+ rubocop-ast (1.30.0)
112
+ parser (>= 3.2.1.0)
113
+ ruby-progressbar (1.13.0)
114
+ shellany (0.0.1)
115
+ sqlite3 (1.4.2)
116
+ terminal-notifier (2.0.0)
117
+ thor (1.3.0)
118
+ tzinfo (2.0.6)
119
+ concurrent-ruby (~> 1.0)
120
+ unicode-display_width (2.5.0)
121
+ zeitwerk (2.6.12)
122
+
123
+ PLATFORMS
124
+ arm64-darwin-23
125
+
126
+ DEPENDENCIES
127
+ activerecord (= 6.1.7.6)
128
+ activesupport (= 6.1.7.6)
129
+ appraisal
130
+ auto_increment!
131
+ bundler
132
+ database_cleaner
133
+ fuubar
134
+ guard
135
+ guard-rspec
136
+ rake
137
+ rspec
138
+ rspec-nc
139
+ rubocop
140
+ sqlite3 (>= 1.3.13)
141
+
142
+ BUNDLED WITH
143
+ 2.4.22
@@ -2,7 +2,7 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- gem "activerecord", "6.1.0"
6
- gem "activesupport", "6.1.0"
5
+ gem "activerecord", "7.0.8"
6
+ gem "activesupport", "7.0.8"
7
7
 
8
8
  gemspec path: "../"
@@ -0,0 +1,141 @@
1
+ PATH
2
+ remote: ..
3
+ specs:
4
+ auto_increment (1.5.2)
5
+ activerecord (>= 6.0)
6
+ activesupport (>= 6.0)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ activemodel (7.0.8)
12
+ activesupport (= 7.0.8)
13
+ activerecord (7.0.8)
14
+ activemodel (= 7.0.8)
15
+ activesupport (= 7.0.8)
16
+ activesupport (7.0.8)
17
+ concurrent-ruby (~> 1.0, >= 1.0.2)
18
+ i18n (>= 1.6, < 2)
19
+ minitest (>= 5.1)
20
+ tzinfo (~> 2.0)
21
+ appraisal (2.5.0)
22
+ bundler
23
+ rake
24
+ thor (>= 0.14.0)
25
+ ast (2.4.2)
26
+ coderay (1.1.3)
27
+ concurrent-ruby (1.2.2)
28
+ database_cleaner (2.0.2)
29
+ database_cleaner-active_record (>= 2, < 3)
30
+ database_cleaner-active_record (2.1.0)
31
+ activerecord (>= 5.a)
32
+ database_cleaner-core (~> 2.0.0)
33
+ database_cleaner-core (2.0.1)
34
+ diff-lcs (1.5.0)
35
+ ffi (1.16.3)
36
+ formatador (1.1.0)
37
+ fuubar (2.5.1)
38
+ rspec-core (~> 3.0)
39
+ ruby-progressbar (~> 1.4)
40
+ guard (2.18.1)
41
+ formatador (>= 0.2.4)
42
+ listen (>= 2.7, < 4.0)
43
+ lumberjack (>= 1.0.12, < 2.0)
44
+ nenv (~> 0.1)
45
+ notiffany (~> 0.0)
46
+ pry (>= 0.13.0)
47
+ shellany (~> 0.0)
48
+ thor (>= 0.18.1)
49
+ guard-compat (1.2.1)
50
+ guard-rspec (4.7.3)
51
+ guard (~> 2.1)
52
+ guard-compat (~> 1.1)
53
+ rspec (>= 2.99.0, < 4.0)
54
+ i18n (1.14.1)
55
+ concurrent-ruby (~> 1.0)
56
+ json (2.7.1)
57
+ language_server-protocol (3.17.0.3)
58
+ listen (3.8.0)
59
+ rb-fsevent (~> 0.10, >= 0.10.3)
60
+ rb-inotify (~> 0.9, >= 0.9.10)
61
+ lumberjack (1.2.10)
62
+ method_source (1.0.0)
63
+ minitest (5.20.0)
64
+ nenv (0.3.0)
65
+ notiffany (0.1.3)
66
+ nenv (~> 0.1)
67
+ shellany (~> 0.0)
68
+ parallel (1.24.0)
69
+ parser (3.2.2.4)
70
+ ast (~> 2.4.1)
71
+ racc
72
+ pry (0.14.2)
73
+ coderay (~> 1.1)
74
+ method_source (~> 1.0)
75
+ racc (1.7.3)
76
+ rainbow (3.1.1)
77
+ rake (13.1.0)
78
+ rb-fsevent (0.11.2)
79
+ rb-inotify (0.10.1)
80
+ ffi (~> 1.0)
81
+ regexp_parser (2.8.3)
82
+ rexml (3.2.6)
83
+ rspec (3.12.0)
84
+ rspec-core (~> 3.12.0)
85
+ rspec-expectations (~> 3.12.0)
86
+ rspec-mocks (~> 3.12.0)
87
+ rspec-core (3.12.2)
88
+ rspec-support (~> 3.12.0)
89
+ rspec-expectations (3.12.3)
90
+ diff-lcs (>= 1.2.0, < 2.0)
91
+ rspec-support (~> 3.12.0)
92
+ rspec-mocks (3.12.6)
93
+ diff-lcs (>= 1.2.0, < 2.0)
94
+ rspec-support (~> 3.12.0)
95
+ rspec-nc (0.3.0)
96
+ rspec (>= 3)
97
+ terminal-notifier (>= 1.4)
98
+ rspec-support (3.12.1)
99
+ rubocop (1.59.0)
100
+ json (~> 2.3)
101
+ language_server-protocol (>= 3.17.0)
102
+ parallel (~> 1.10)
103
+ parser (>= 3.2.2.4)
104
+ rainbow (>= 2.2.2, < 4.0)
105
+ regexp_parser (>= 1.8, < 3.0)
106
+ rexml (>= 3.2.5, < 4.0)
107
+ rubocop-ast (>= 1.30.0, < 2.0)
108
+ ruby-progressbar (~> 1.7)
109
+ unicode-display_width (>= 2.4.0, < 3.0)
110
+ rubocop-ast (1.30.0)
111
+ parser (>= 3.2.1.0)
112
+ ruby-progressbar (1.13.0)
113
+ shellany (0.0.1)
114
+ sqlite3 (1.4.2)
115
+ terminal-notifier (2.0.0)
116
+ thor (1.3.0)
117
+ tzinfo (2.0.6)
118
+ concurrent-ruby (~> 1.0)
119
+ unicode-display_width (2.5.0)
120
+
121
+ PLATFORMS
122
+ arm64-darwin-23
123
+
124
+ DEPENDENCIES
125
+ activerecord (= 7.0.8)
126
+ activesupport (= 7.0.8)
127
+ appraisal
128
+ auto_increment!
129
+ bundler
130
+ database_cleaner
131
+ fuubar
132
+ guard
133
+ guard-rspec
134
+ rake
135
+ rspec
136
+ rspec-nc
137
+ rubocop
138
+ sqlite3 (>= 1.3.13)
139
+
140
+ BUNDLED WITH
141
+ 2.4.22
@@ -2,8 +2,7 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- gem "activerecord", "5.1.6.2"
6
- gem "activesupport", "5.1.6.2"
7
- gem "sqlite3", "1.3.13"
5
+ gem "activerecord", "7.1.2"
6
+ gem "activesupport", "7.1.2"
8
7
 
9
8
  gemspec path: "../"
@@ -0,0 +1,155 @@
1
+ PATH
2
+ remote: ..
3
+ specs:
4
+ auto_increment (1.5.2)
5
+ activerecord (>= 6.0)
6
+ activesupport (>= 6.0)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ activemodel (7.1.2)
12
+ activesupport (= 7.1.2)
13
+ activerecord (7.1.2)
14
+ activemodel (= 7.1.2)
15
+ activesupport (= 7.1.2)
16
+ timeout (>= 0.4.0)
17
+ activesupport (7.1.2)
18
+ base64
19
+ bigdecimal
20
+ concurrent-ruby (~> 1.0, >= 1.0.2)
21
+ connection_pool (>= 2.2.5)
22
+ drb
23
+ i18n (>= 1.6, < 2)
24
+ minitest (>= 5.1)
25
+ mutex_m
26
+ tzinfo (~> 2.0)
27
+ appraisal (2.5.0)
28
+ bundler
29
+ rake
30
+ thor (>= 0.14.0)
31
+ ast (2.4.2)
32
+ base64 (0.2.0)
33
+ bigdecimal (3.1.5)
34
+ coderay (1.1.3)
35
+ concurrent-ruby (1.2.2)
36
+ connection_pool (2.4.1)
37
+ database_cleaner (2.0.2)
38
+ database_cleaner-active_record (>= 2, < 3)
39
+ database_cleaner-active_record (2.1.0)
40
+ activerecord (>= 5.a)
41
+ database_cleaner-core (~> 2.0.0)
42
+ database_cleaner-core (2.0.1)
43
+ diff-lcs (1.5.0)
44
+ drb (2.2.0)
45
+ ruby2_keywords
46
+ ffi (1.16.3)
47
+ formatador (1.1.0)
48
+ fuubar (2.5.1)
49
+ rspec-core (~> 3.0)
50
+ ruby-progressbar (~> 1.4)
51
+ guard (2.18.1)
52
+ formatador (>= 0.2.4)
53
+ listen (>= 2.7, < 4.0)
54
+ lumberjack (>= 1.0.12, < 2.0)
55
+ nenv (~> 0.1)
56
+ notiffany (~> 0.0)
57
+ pry (>= 0.13.0)
58
+ shellany (~> 0.0)
59
+ thor (>= 0.18.1)
60
+ guard-compat (1.2.1)
61
+ guard-rspec (4.7.3)
62
+ guard (~> 2.1)
63
+ guard-compat (~> 1.1)
64
+ rspec (>= 2.99.0, < 4.0)
65
+ i18n (1.14.1)
66
+ concurrent-ruby (~> 1.0)
67
+ json (2.7.1)
68
+ language_server-protocol (3.17.0.3)
69
+ listen (3.8.0)
70
+ rb-fsevent (~> 0.10, >= 0.10.3)
71
+ rb-inotify (~> 0.9, >= 0.9.10)
72
+ lumberjack (1.2.10)
73
+ method_source (1.0.0)
74
+ minitest (5.20.0)
75
+ mutex_m (0.2.0)
76
+ nenv (0.3.0)
77
+ notiffany (0.1.3)
78
+ nenv (~> 0.1)
79
+ shellany (~> 0.0)
80
+ parallel (1.24.0)
81
+ parser (3.2.2.4)
82
+ ast (~> 2.4.1)
83
+ racc
84
+ pry (0.14.2)
85
+ coderay (~> 1.1)
86
+ method_source (~> 1.0)
87
+ racc (1.7.3)
88
+ rainbow (3.1.1)
89
+ rake (13.1.0)
90
+ rb-fsevent (0.11.2)
91
+ rb-inotify (0.10.1)
92
+ ffi (~> 1.0)
93
+ regexp_parser (2.8.3)
94
+ rexml (3.2.6)
95
+ rspec (3.12.0)
96
+ rspec-core (~> 3.12.0)
97
+ rspec-expectations (~> 3.12.0)
98
+ rspec-mocks (~> 3.12.0)
99
+ rspec-core (3.12.2)
100
+ rspec-support (~> 3.12.0)
101
+ rspec-expectations (3.12.3)
102
+ diff-lcs (>= 1.2.0, < 2.0)
103
+ rspec-support (~> 3.12.0)
104
+ rspec-mocks (3.12.6)
105
+ diff-lcs (>= 1.2.0, < 2.0)
106
+ rspec-support (~> 3.12.0)
107
+ rspec-nc (0.3.0)
108
+ rspec (>= 3)
109
+ terminal-notifier (>= 1.4)
110
+ rspec-support (3.12.1)
111
+ rubocop (1.59.0)
112
+ json (~> 2.3)
113
+ language_server-protocol (>= 3.17.0)
114
+ parallel (~> 1.10)
115
+ parser (>= 3.2.2.4)
116
+ rainbow (>= 2.2.2, < 4.0)
117
+ regexp_parser (>= 1.8, < 3.0)
118
+ rexml (>= 3.2.5, < 4.0)
119
+ rubocop-ast (>= 1.30.0, < 2.0)
120
+ ruby-progressbar (~> 1.7)
121
+ unicode-display_width (>= 2.4.0, < 3.0)
122
+ rubocop-ast (1.30.0)
123
+ parser (>= 3.2.1.0)
124
+ ruby-progressbar (1.13.0)
125
+ ruby2_keywords (0.0.5)
126
+ shellany (0.0.1)
127
+ sqlite3 (1.4.2)
128
+ terminal-notifier (2.0.0)
129
+ thor (1.3.0)
130
+ timeout (0.4.1)
131
+ tzinfo (2.0.6)
132
+ concurrent-ruby (~> 1.0)
133
+ unicode-display_width (2.5.0)
134
+
135
+ PLATFORMS
136
+ arm64-darwin-23
137
+
138
+ DEPENDENCIES
139
+ activerecord (= 7.1.2)
140
+ activesupport (= 7.1.2)
141
+ appraisal
142
+ auto_increment!
143
+ bundler
144
+ database_cleaner
145
+ fuubar
146
+ guard
147
+ guard-rspec
148
+ rake
149
+ rspec
150
+ rspec-nc
151
+ rubocop
152
+ sqlite3 (>= 1.3.13)
153
+
154
+ BUNDLED WITH
155
+ 2.4.22
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # +AutoIncrement+
2
4
  module AutoIncrement
3
5
  # +AutoIncrement::ActiveRecord+
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # +AutoIncrement+
2
4
  module AutoIncrement
3
5
  # +AutoIncrement::Incrementor+
@@ -10,8 +12,10 @@ module AutoIncrement
10
12
 
11
13
  @column = column || options[:column] || :code
12
14
  @options = options.reverse_merge initial: 1, force: false
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
15
+ @options[:scope] = [@options[:scope]].compact unless @options[:scope].is_a?(Array)
16
+ @options[:model_scope] = [@options[:model_scope]].compact unless @options[:model_scope].is_a?(Array)
17
+
18
+ deprecated_warning
15
19
  end
16
20
 
17
21
  def before_create(record)
@@ -34,9 +38,7 @@ module AutoIncrement
34
38
 
35
39
  def build_scopes(query)
36
40
  @options[:scope].each do |scope|
37
- if scope.present? && @record.respond_to?(scope)
38
- query = query.where(scope => @record.send(scope))
39
- end
41
+ query = query.where(scope => @record.send(scope)) if scope.present? && @record.respond_to?(scope)
40
42
  end
41
43
 
42
44
  query
@@ -74,7 +76,15 @@ module AutoIncrement
74
76
  end
75
77
 
76
78
  def string?
77
- @options[:initial].class == String
79
+ @options[:initial].instance_of?(String)
80
+ end
81
+
82
+ def deprecated_warning
83
+ return if @options[:scope].empty?
84
+
85
+ ActiveSupport::Deprecation.warn <<~WARNING.squish
86
+ Passing a scope to auto_increment is deprecated and will be removed in the next version. Please use model_scope instead.
87
+ WARNING
78
88
  end
79
89
  end
80
90
  end
@@ -1,4 +1,6 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # +AutoIncrement::VERSION+
2
4
  module AutoIncrement
3
- VERSION = '1.5.2'.freeze
5
+ VERSION = '1.6.0'
4
6
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'date'
2
4
  require 'i18n'
3
5
  require 'active_record'
@@ -11,4 +13,4 @@ module AutoIncrement
11
13
  autoload :ActiveRecord, 'auto_increment/active_record'
12
14
  end
13
15
 
14
- ActiveRecord::Base.send :include, AutoIncrement::ActiveRecord
16
+ ActiveRecord::Base.include AutoIncrement::ActiveRecord
data/spec/db/sync.db CHANGED
Binary file
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
  require 'models/account'
3
5
  require 'models/user'
@@ -49,7 +51,7 @@ describe AutoIncrement do
49
51
  end
50
52
 
51
53
  let(:account_last_letter_code) do
52
- @accounts.sort_by(&:letter_code).last.letter_code
54
+ @accounts.max_by(&:letter_code).letter_code
53
55
  end
54
56
 
55
57
  it { expect(@accounts.size).to eq 25 }
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe AutoIncrement::Incrementor do
@@ -28,4 +30,23 @@ describe AutoIncrement::Incrementor do
28
30
  expect(subject.send(:increment)).to eq 'A'
29
31
  end
30
32
  end
33
+
34
+ describe 'deprecates scope' do
35
+ subject { AutoIncrement::Incrementor.new :code, **options }
36
+ let(:options) { { scope: :account_id } }
37
+
38
+ it 'issues a deprecation warning' do
39
+ expect(ActiveSupport::Deprecation).to receive(:warn).with(/Passing a scope to auto_increment is deprecated/)
40
+ subject
41
+ end
42
+
43
+ context 'when @options[:scope] is not present' do
44
+ let(:options) { {} }
45
+
46
+ it 'does not issue a deprecation warning' do
47
+ expect(ActiveSupport::Deprecation).not_to receive(:warn)
48
+ subject
49
+ end
50
+ end
51
+ end
31
52
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Spec +Account+
2
4
  class Account < ActiveRecord::Base
3
5
  auto_increment :code, before: :validation
data/spec/models/user.rb CHANGED
@@ -1,7 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # + Spec +User+
2
4
  class User < ActiveRecord::Base
3
5
  auto_increment :letter_code, scope: :account_id, initial: 'A', force: true,
4
- lock: true, model_scope: :with_mark
6
+ lock: true, model_scope: :with_mark
5
7
 
6
8
  belongs_to :account
7
9
 
data/spec/spec_helper.rb CHANGED
@@ -1,5 +1,4 @@
1
- require 'coveralls'
2
- Coveralls.wear!
1
+ # frozen_string_literal: true
3
2
 
4
3
  require 'pry'
5
4
  require 'auto_increment'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # +ActiveRecord+ migration for Accounts
2
4
  ActiveRecord::Migration.create_table :accounts do |t|
3
5
  t.string :name
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  RSpec.configure do |config|
2
4
  config.before(:suite) do
3
5
  DatabaseCleaner.strategy = :transaction