sequenced 2.0.0 → 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (95) hide show
  1. checksums.yaml +5 -5
  2. data/.github/workflows/ci.yml +100 -0
  3. data/Appraisals +19 -0
  4. data/CHANGELOG.md +32 -0
  5. data/Gemfile +12 -3
  6. data/MIT-LICENSE +1 -1
  7. data/README.md +90 -50
  8. data/Rakefile +39 -15
  9. data/gemfiles/rails_5_2.gemfile +17 -0
  10. data/gemfiles/rails_5_2.gemfile.lock +193 -0
  11. data/gemfiles/rails_6.gemfile +17 -0
  12. data/gemfiles/rails_6.gemfile.lock +204 -0
  13. data/gemfiles/rails_6_1.gemfile +17 -0
  14. data/gemfiles/rails_6_1.gemfile.lock +207 -0
  15. data/gemfiles/rails_7.gemfile +17 -0
  16. data/gemfiles/rails_7.gemfile.lock +206 -0
  17. data/gemfiles/rails_master.gemfile +17 -0
  18. data/gemfiles/rails_master.gemfile.lock +215 -0
  19. data/lib/sequenced/acts_as_sequenced.rb +34 -8
  20. data/lib/sequenced/generator.rb +28 -13
  21. data/lib/sequenced/version.rb +1 -1
  22. data/lib/sequenced.rb +5 -3
  23. data/sequenced.gemspec +8 -10
  24. metadata +29 -168
  25. data/.travis.yml +0 -4
  26. data/TODO.md +0 -7
  27. data/test/acts_as_sequenced_test.rb +0 -132
  28. data/test/dummy/README.rdoc +0 -261
  29. data/test/dummy/Rakefile +0 -7
  30. data/test/dummy/app/assets/javascripts/application.js +0 -15
  31. data/test/dummy/app/assets/stylesheets/application.css +0 -13
  32. data/test/dummy/app/controllers/application_controller.rb +0 -3
  33. data/test/dummy/app/helpers/application_helper.rb +0 -2
  34. data/test/dummy/app/mailers/.gitkeep +0 -0
  35. data/test/dummy/app/models/.gitkeep +0 -0
  36. data/test/dummy/app/models/account.rb +0 -6
  37. data/test/dummy/app/models/address.rb +0 -4
  38. data/test/dummy/app/models/answer.rb +0 -4
  39. data/test/dummy/app/models/comment.rb +0 -8
  40. data/test/dummy/app/models/email.rb +0 -4
  41. data/test/dummy/app/models/invoice.rb +0 -4
  42. data/test/dummy/app/models/monster.rb +0 -3
  43. data/test/dummy/app/models/order.rb +0 -4
  44. data/test/dummy/app/models/policeman.rb +0 -5
  45. data/test/dummy/app/models/product.rb +0 -8
  46. data/test/dummy/app/models/question.rb +0 -4
  47. data/test/dummy/app/models/rating.rb +0 -3
  48. data/test/dummy/app/models/subscription.rb +0 -3
  49. data/test/dummy/app/models/user.rb +0 -4
  50. data/test/dummy/app/models/werewolf.rb +0 -2
  51. data/test/dummy/app/models/zombie.rb +0 -2
  52. data/test/dummy/app/views/layouts/application.html.erb +0 -14
  53. data/test/dummy/config/application.rb +0 -56
  54. data/test/dummy/config/boot.rb +0 -10
  55. data/test/dummy/config/database.yml +0 -25
  56. data/test/dummy/config/environment.rb +0 -5
  57. data/test/dummy/config/environments/development.rb +0 -37
  58. data/test/dummy/config/environments/production.rb +0 -67
  59. data/test/dummy/config/environments/test.rb +0 -38
  60. data/test/dummy/config/initializers/backtrace_silencers.rb +0 -7
  61. data/test/dummy/config/initializers/inflections.rb +0 -15
  62. data/test/dummy/config/initializers/mime_types.rb +0 -5
  63. data/test/dummy/config/initializers/secret_token.rb +0 -7
  64. data/test/dummy/config/initializers/session_store.rb +0 -8
  65. data/test/dummy/config/initializers/wrap_parameters.rb +0 -14
  66. data/test/dummy/config/locales/en.yml +0 -5
  67. data/test/dummy/config/routes.rb +0 -58
  68. data/test/dummy/config.ru +0 -4
  69. data/test/dummy/db/development.sqlite3 +0 -0
  70. data/test/dummy/db/migrate/20120219165346_create_questions.rb +0 -10
  71. data/test/dummy/db/migrate/20120219165548_create_answers.rb +0 -13
  72. data/test/dummy/db/migrate/20120219171957_create_accounts.rb +0 -9
  73. data/test/dummy/db/migrate/20120219172039_create_invoices.rb +0 -12
  74. data/test/dummy/db/migrate/20120219172922_create_orders.rb +0 -10
  75. data/test/dummy/db/migrate/20120219174931_create_subscriptions.rb +0 -10
  76. data/test/dummy/db/migrate/20120219175744_create_users.rb +0 -12
  77. data/test/dummy/db/migrate/20120219232323_create_addresses.rb +0 -9
  78. data/test/dummy/db/migrate/20120220000804_create_comments.rb +0 -12
  79. data/test/dummy/db/migrate/20130411225444_create_emails.rb +0 -12
  80. data/test/dummy/db/migrate/20130715002029_create_ratings.rb +0 -10
  81. data/test/dummy/db/migrate/20130730004055_create_products.rb +0 -9
  82. data/test/dummy/db/migrate/20131226000000_create_monsters.rb +0 -9
  83. data/test/dummy/db/migrate/20140404195334_create_policemen.rb +0 -9
  84. data/test/dummy/db/schema.rb +0 -108
  85. data/test/dummy/db/test.sqlite3 +0 -0
  86. data/test/dummy/lib/assets/.gitkeep +0 -0
  87. data/test/dummy/log/.gitkeep +0 -0
  88. data/test/dummy/log/development.log +0 -62
  89. data/test/dummy/log/test.log +0 -30088
  90. data/test/dummy/public/404.html +0 -26
  91. data/test/dummy/public/422.html +0 -26
  92. data/test/dummy/public/500.html +0 -25
  93. data/test/dummy/public/favicon.ico +0 -0
  94. data/test/dummy/script/rails +0 -6
  95. data/test/test_helper.rb +0 -13
@@ -0,0 +1,206 @@
1
+ PATH
2
+ remote: ..
3
+ specs:
4
+ sequenced (4.0.0)
5
+ activerecord (>= 3.0)
6
+ activesupport (>= 3.0)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ actioncable (7.0.3.1)
12
+ actionpack (= 7.0.3.1)
13
+ activesupport (= 7.0.3.1)
14
+ nio4r (~> 2.0)
15
+ websocket-driver (>= 0.6.1)
16
+ actionmailbox (7.0.3.1)
17
+ actionpack (= 7.0.3.1)
18
+ activejob (= 7.0.3.1)
19
+ activerecord (= 7.0.3.1)
20
+ activestorage (= 7.0.3.1)
21
+ activesupport (= 7.0.3.1)
22
+ mail (>= 2.7.1)
23
+ net-imap
24
+ net-pop
25
+ net-smtp
26
+ actionmailer (7.0.3.1)
27
+ actionpack (= 7.0.3.1)
28
+ actionview (= 7.0.3.1)
29
+ activejob (= 7.0.3.1)
30
+ activesupport (= 7.0.3.1)
31
+ mail (~> 2.5, >= 2.5.4)
32
+ net-imap
33
+ net-pop
34
+ net-smtp
35
+ rails-dom-testing (~> 2.0)
36
+ actionpack (7.0.3.1)
37
+ actionview (= 7.0.3.1)
38
+ activesupport (= 7.0.3.1)
39
+ rack (~> 2.0, >= 2.2.0)
40
+ rack-test (>= 0.6.3)
41
+ rails-dom-testing (~> 2.0)
42
+ rails-html-sanitizer (~> 1.0, >= 1.2.0)
43
+ actiontext (7.0.3.1)
44
+ actionpack (= 7.0.3.1)
45
+ activerecord (= 7.0.3.1)
46
+ activestorage (= 7.0.3.1)
47
+ activesupport (= 7.0.3.1)
48
+ globalid (>= 0.6.0)
49
+ nokogiri (>= 1.8.5)
50
+ actionview (7.0.3.1)
51
+ activesupport (= 7.0.3.1)
52
+ builder (~> 3.1)
53
+ erubi (~> 1.4)
54
+ rails-dom-testing (~> 2.0)
55
+ rails-html-sanitizer (~> 1.1, >= 1.2.0)
56
+ activejob (7.0.3.1)
57
+ activesupport (= 7.0.3.1)
58
+ globalid (>= 0.3.6)
59
+ activemodel (7.0.3.1)
60
+ activesupport (= 7.0.3.1)
61
+ activerecord (7.0.3.1)
62
+ activemodel (= 7.0.3.1)
63
+ activesupport (= 7.0.3.1)
64
+ activestorage (7.0.3.1)
65
+ actionpack (= 7.0.3.1)
66
+ activejob (= 7.0.3.1)
67
+ activerecord (= 7.0.3.1)
68
+ activesupport (= 7.0.3.1)
69
+ marcel (~> 1.0)
70
+ mini_mime (>= 1.1.0)
71
+ activesupport (7.0.3.1)
72
+ concurrent-ruby (~> 1.0, >= 1.0.2)
73
+ i18n (>= 1.6, < 2)
74
+ minitest (>= 5.1)
75
+ tzinfo (~> 2.0)
76
+ appraisal (2.4.1)
77
+ bundler
78
+ rake
79
+ thor (>= 0.14.0)
80
+ ast (2.4.2)
81
+ builder (3.2.4)
82
+ concurrent-ruby (1.1.10)
83
+ crass (1.0.6)
84
+ digest (3.1.0)
85
+ erubi (1.11.0)
86
+ globalid (1.0.0)
87
+ activesupport (>= 5.0)
88
+ i18n (1.12.0)
89
+ concurrent-ruby (~> 1.0)
90
+ json (2.6.2)
91
+ loofah (2.18.0)
92
+ crass (~> 1.0.2)
93
+ nokogiri (>= 1.5.9)
94
+ mail (2.7.1)
95
+ mini_mime (>= 0.1.1)
96
+ marcel (1.0.2)
97
+ method_source (1.0.0)
98
+ mini_mime (1.1.2)
99
+ minitest (5.16.2)
100
+ net-imap (0.2.3)
101
+ digest
102
+ net-protocol
103
+ strscan
104
+ net-pop (0.1.1)
105
+ digest
106
+ net-protocol
107
+ timeout
108
+ net-protocol (0.1.3)
109
+ timeout
110
+ net-smtp (0.3.1)
111
+ digest
112
+ net-protocol
113
+ timeout
114
+ nio4r (2.5.8)
115
+ nokogiri (1.13.8-arm64-darwin)
116
+ racc (~> 1.4)
117
+ nokogiri (1.13.8-x86_64-linux)
118
+ racc (~> 1.4)
119
+ parallel (1.22.1)
120
+ parser (3.1.2.1)
121
+ ast (~> 2.4.1)
122
+ pg (1.4.3)
123
+ racc (1.6.0)
124
+ rack (2.2.4)
125
+ rack-test (2.0.2)
126
+ rack (>= 1.3)
127
+ rails (7.0.3.1)
128
+ actioncable (= 7.0.3.1)
129
+ actionmailbox (= 7.0.3.1)
130
+ actionmailer (= 7.0.3.1)
131
+ actionpack (= 7.0.3.1)
132
+ actiontext (= 7.0.3.1)
133
+ actionview (= 7.0.3.1)
134
+ activejob (= 7.0.3.1)
135
+ activemodel (= 7.0.3.1)
136
+ activerecord (= 7.0.3.1)
137
+ activestorage (= 7.0.3.1)
138
+ activesupport (= 7.0.3.1)
139
+ bundler (>= 1.15.0)
140
+ railties (= 7.0.3.1)
141
+ rails-dom-testing (2.0.3)
142
+ activesupport (>= 4.2.0)
143
+ nokogiri (>= 1.6)
144
+ rails-html-sanitizer (1.4.3)
145
+ loofah (~> 2.3)
146
+ railties (7.0.3.1)
147
+ actionpack (= 7.0.3.1)
148
+ activesupport (= 7.0.3.1)
149
+ method_source
150
+ rake (>= 12.2)
151
+ thor (~> 1.0)
152
+ zeitwerk (~> 2.5)
153
+ rainbow (3.1.1)
154
+ rake (13.0.6)
155
+ regexp_parser (2.5.0)
156
+ rexml (3.2.5)
157
+ rubocop (1.35.0)
158
+ json (~> 2.3)
159
+ parallel (~> 1.10)
160
+ parser (>= 3.1.2.1)
161
+ rainbow (>= 2.2.2, < 4.0)
162
+ regexp_parser (>= 1.8, < 3.0)
163
+ rexml (>= 3.2.5, < 4.0)
164
+ rubocop-ast (>= 1.20.1, < 2.0)
165
+ ruby-progressbar (~> 1.7)
166
+ unicode-display_width (>= 1.4.0, < 3.0)
167
+ rubocop-ast (1.21.0)
168
+ parser (>= 3.1.1.0)
169
+ rubocop-performance (1.14.3)
170
+ rubocop (>= 1.7.0, < 2.0)
171
+ rubocop-ast (>= 0.4.0)
172
+ ruby-progressbar (1.11.0)
173
+ sqlite3 (1.4.4)
174
+ standard (1.16.0)
175
+ rubocop (= 1.35.0)
176
+ rubocop-performance (= 1.14.3)
177
+ standardrb (1.0.1)
178
+ standard
179
+ strscan (3.0.4)
180
+ thor (1.2.1)
181
+ timeout (0.3.0)
182
+ tzinfo (2.0.5)
183
+ concurrent-ruby (~> 1.0)
184
+ unicode-display_width (2.2.0)
185
+ websocket-driver (0.7.5)
186
+ websocket-extensions (>= 0.1.0)
187
+ websocket-extensions (0.1.5)
188
+ zeitwerk (2.6.0)
189
+
190
+ PLATFORMS
191
+ arm64-darwin-21
192
+ x86_64-linux
193
+
194
+ DEPENDENCIES
195
+ appraisal
196
+ net-imap
197
+ net-pop
198
+ net-smtp
199
+ pg
200
+ rails (~> 7.0.0)
201
+ sequenced!
202
+ sqlite3 (~> 1.4.4)
203
+ standardrb
204
+
205
+ BUNDLED WITH
206
+ 2.3.16
@@ -0,0 +1,17 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "appraisal"
6
+ gem "standardrb"
7
+ gem "rails", github: "rails/rails", branch: "main"
8
+
9
+ group :development, :test do
10
+ gem "sqlite3", "~> 1.4.4"
11
+ gem "pg"
12
+ gem "net-imap"
13
+ gem "net-pop"
14
+ gem "net-smtp"
15
+ end
16
+
17
+ gemspec path: "../"
@@ -0,0 +1,215 @@
1
+ GIT
2
+ remote: https://github.com/rails/rails.git
3
+ revision: cb5765a12751ca03866a89cf19fefcbc2d93a8ea
4
+ branch: main
5
+ specs:
6
+ actioncable (7.1.0.alpha)
7
+ actionpack (= 7.1.0.alpha)
8
+ activesupport (= 7.1.0.alpha)
9
+ nio4r (~> 2.0)
10
+ websocket-driver (>= 0.6.1)
11
+ zeitwerk (~> 2.6)
12
+ actionmailbox (7.1.0.alpha)
13
+ actionpack (= 7.1.0.alpha)
14
+ activejob (= 7.1.0.alpha)
15
+ activerecord (= 7.1.0.alpha)
16
+ activestorage (= 7.1.0.alpha)
17
+ activesupport (= 7.1.0.alpha)
18
+ mail (>= 2.7.1)
19
+ net-imap
20
+ net-pop
21
+ net-smtp
22
+ actionmailer (7.1.0.alpha)
23
+ actionpack (= 7.1.0.alpha)
24
+ actionview (= 7.1.0.alpha)
25
+ activejob (= 7.1.0.alpha)
26
+ activesupport (= 7.1.0.alpha)
27
+ mail (~> 2.5, >= 2.5.4)
28
+ net-imap
29
+ net-pop
30
+ net-smtp
31
+ rails-dom-testing (~> 2.0)
32
+ actionpack (7.1.0.alpha)
33
+ actionview (= 7.1.0.alpha)
34
+ activesupport (= 7.1.0.alpha)
35
+ rack (~> 2.0, >= 2.2.0)
36
+ rack-test (>= 0.6.3)
37
+ rails-dom-testing (~> 2.0)
38
+ rails-html-sanitizer (~> 1.0, >= 1.2.0)
39
+ actiontext (7.1.0.alpha)
40
+ actionpack (= 7.1.0.alpha)
41
+ activerecord (= 7.1.0.alpha)
42
+ activestorage (= 7.1.0.alpha)
43
+ activesupport (= 7.1.0.alpha)
44
+ globalid (>= 0.6.0)
45
+ nokogiri (>= 1.8.5)
46
+ actionview (7.1.0.alpha)
47
+ activesupport (= 7.1.0.alpha)
48
+ builder (~> 3.1)
49
+ erubi (~> 1.11)
50
+ rails-dom-testing (~> 2.0)
51
+ rails-html-sanitizer (~> 1.1, >= 1.2.0)
52
+ activejob (7.1.0.alpha)
53
+ activesupport (= 7.1.0.alpha)
54
+ globalid (>= 0.3.6)
55
+ activemodel (7.1.0.alpha)
56
+ activesupport (= 7.1.0.alpha)
57
+ activerecord (7.1.0.alpha)
58
+ activemodel (= 7.1.0.alpha)
59
+ activesupport (= 7.1.0.alpha)
60
+ activestorage (7.1.0.alpha)
61
+ actionpack (= 7.1.0.alpha)
62
+ activejob (= 7.1.0.alpha)
63
+ activerecord (= 7.1.0.alpha)
64
+ activesupport (= 7.1.0.alpha)
65
+ marcel (~> 1.0)
66
+ mini_mime (>= 1.1.0)
67
+ activesupport (7.1.0.alpha)
68
+ concurrent-ruby (~> 1.0, >= 1.0.2)
69
+ connection_pool (>= 2.2.5)
70
+ i18n (>= 1.6, < 2)
71
+ minitest (>= 5.1)
72
+ tzinfo (~> 2.0)
73
+ rails (7.1.0.alpha)
74
+ actioncable (= 7.1.0.alpha)
75
+ actionmailbox (= 7.1.0.alpha)
76
+ actionmailer (= 7.1.0.alpha)
77
+ actionpack (= 7.1.0.alpha)
78
+ actiontext (= 7.1.0.alpha)
79
+ actionview (= 7.1.0.alpha)
80
+ activejob (= 7.1.0.alpha)
81
+ activemodel (= 7.1.0.alpha)
82
+ activerecord (= 7.1.0.alpha)
83
+ activestorage (= 7.1.0.alpha)
84
+ activesupport (= 7.1.0.alpha)
85
+ bundler (>= 1.15.0)
86
+ railties (= 7.1.0.alpha)
87
+ railties (7.1.0.alpha)
88
+ actionpack (= 7.1.0.alpha)
89
+ activesupport (= 7.1.0.alpha)
90
+ method_source
91
+ rake (>= 12.2)
92
+ thor (~> 1.0)
93
+ zeitwerk (~> 2.6)
94
+
95
+ PATH
96
+ remote: ..
97
+ specs:
98
+ sequenced (4.0.0)
99
+ activerecord (>= 3.0)
100
+ activesupport (>= 3.0)
101
+
102
+ GEM
103
+ remote: https://rubygems.org/
104
+ specs:
105
+ appraisal (2.4.1)
106
+ bundler
107
+ rake
108
+ thor (>= 0.14.0)
109
+ ast (2.4.2)
110
+ builder (3.2.4)
111
+ concurrent-ruby (1.1.10)
112
+ connection_pool (2.2.5)
113
+ crass (1.0.6)
114
+ digest (3.1.0)
115
+ erubi (1.11.0)
116
+ globalid (1.0.0)
117
+ activesupport (>= 5.0)
118
+ i18n (1.12.0)
119
+ concurrent-ruby (~> 1.0)
120
+ json (2.6.2)
121
+ loofah (2.18.0)
122
+ crass (~> 1.0.2)
123
+ nokogiri (>= 1.5.9)
124
+ mail (2.7.1)
125
+ mini_mime (>= 0.1.1)
126
+ marcel (1.0.2)
127
+ method_source (1.0.0)
128
+ mini_mime (1.1.2)
129
+ minitest (5.16.2)
130
+ net-imap (0.2.3)
131
+ digest
132
+ net-protocol
133
+ strscan
134
+ net-pop (0.1.1)
135
+ digest
136
+ net-protocol
137
+ timeout
138
+ net-protocol (0.1.3)
139
+ timeout
140
+ net-smtp (0.3.1)
141
+ digest
142
+ net-protocol
143
+ timeout
144
+ nio4r (2.5.8)
145
+ nokogiri (1.13.8-arm64-darwin)
146
+ racc (~> 1.4)
147
+ nokogiri (1.13.8-x86_64-linux)
148
+ racc (~> 1.4)
149
+ parallel (1.22.1)
150
+ parser (3.1.2.1)
151
+ ast (~> 2.4.1)
152
+ pg (1.4.3)
153
+ racc (1.6.0)
154
+ rack (2.2.4)
155
+ rack-test (2.0.2)
156
+ rack (>= 1.3)
157
+ rails-dom-testing (2.0.3)
158
+ activesupport (>= 4.2.0)
159
+ nokogiri (>= 1.6)
160
+ rails-html-sanitizer (1.4.3)
161
+ loofah (~> 2.3)
162
+ rainbow (3.1.1)
163
+ rake (13.0.6)
164
+ regexp_parser (2.5.0)
165
+ rexml (3.2.5)
166
+ rubocop (1.35.0)
167
+ json (~> 2.3)
168
+ parallel (~> 1.10)
169
+ parser (>= 3.1.2.1)
170
+ rainbow (>= 2.2.2, < 4.0)
171
+ regexp_parser (>= 1.8, < 3.0)
172
+ rexml (>= 3.2.5, < 4.0)
173
+ rubocop-ast (>= 1.20.1, < 2.0)
174
+ ruby-progressbar (~> 1.7)
175
+ unicode-display_width (>= 1.4.0, < 3.0)
176
+ rubocop-ast (1.21.0)
177
+ parser (>= 3.1.1.0)
178
+ rubocop-performance (1.14.3)
179
+ rubocop (>= 1.7.0, < 2.0)
180
+ rubocop-ast (>= 0.4.0)
181
+ ruby-progressbar (1.11.0)
182
+ sqlite3 (1.4.4)
183
+ standard (1.16.0)
184
+ rubocop (= 1.35.0)
185
+ rubocop-performance (= 1.14.3)
186
+ standardrb (1.0.1)
187
+ standard
188
+ strscan (3.0.4)
189
+ thor (1.2.1)
190
+ timeout (0.3.0)
191
+ tzinfo (2.0.5)
192
+ concurrent-ruby (~> 1.0)
193
+ unicode-display_width (2.2.0)
194
+ websocket-driver (0.7.5)
195
+ websocket-extensions (>= 0.1.0)
196
+ websocket-extensions (0.1.5)
197
+ zeitwerk (2.6.0)
198
+
199
+ PLATFORMS
200
+ arm64-darwin-21
201
+ x86_64-linux
202
+
203
+ DEPENDENCIES
204
+ appraisal
205
+ net-imap
206
+ net-pop
207
+ net-smtp
208
+ pg
209
+ rails!
210
+ sequenced!
211
+ sqlite3 (~> 1.4.4)
212
+ standardrb
213
+
214
+ BUNDLED WITH
215
+ 2.3.16
@@ -1,8 +1,14 @@
1
- require 'active_support/core_ext/hash/slice'
2
- require 'active_support/core_ext/class/attribute_accessors'
1
+ require "active_support/core_ext/hash/slice"
2
+ require "active_support/core_ext/class/attribute_accessors"
3
3
 
4
4
  module Sequenced
5
5
  module ActsAsSequenced
6
+ DEFAULT_OPTIONS = {
7
+ column: :sequential_id,
8
+ start_at: 1
9
+ }.freeze
10
+ SequencedColumnExists = Class.new(StandardError)
11
+
6
12
  def self.included(base)
7
13
  base.extend ClassMethods
8
14
  end
@@ -11,6 +17,8 @@ module Sequenced
11
17
  # Public: Defines ActiveRecord callbacks to set a sequential ID scoped
12
18
  # on a specific class.
13
19
  #
20
+ # Can be called multiple times to add hooks for different column names.
21
+ #
14
22
  # options - The Hash of options for configuration:
15
23
  # :scope - The Symbol representing the columm on which the
16
24
  # sequential ID should be scoped (default: nil)
@@ -31,17 +39,35 @@ module Sequenced
31
39
  #
32
40
  # Returns nothing.
33
41
  def acts_as_sequenced(options = {})
34
- cattr_accessor :sequenced_options
35
- self.sequenced_options = options
42
+ unless defined?(sequenced_options)
43
+ include Sequenced::ActsAsSequenced::InstanceMethods
44
+
45
+ mattr_accessor :sequenced_options, instance_accessor: false
46
+ self.sequenced_options = []
47
+
48
+ before_save :set_sequential_ids
49
+ end
50
+
51
+ options = DEFAULT_OPTIONS.merge(options)
52
+ column_name = options[:column]
36
53
 
37
- before_save :set_sequential_id
38
- include Sequenced::ActsAsSequenced::InstanceMethods
54
+ if sequenced_options.any? { |options| options[:column] == column_name }
55
+ raise(SequencedColumnExists, <<-MSG.squish)
56
+ Tried to set #{column_name} as sequenced but there was already a
57
+ definition here. Did you accidentally call acts_as_sequenced
58
+ multiple times on the same column?
59
+ MSG
60
+ else
61
+ sequenced_options << options
62
+ end
39
63
  end
40
64
  end
41
65
 
42
66
  module InstanceMethods
43
- def set_sequential_id
44
- Sequenced::Generator.new(self, self.class.base_class.sequenced_options).set
67
+ def set_sequential_ids
68
+ self.class.base_class.sequenced_options.each do |options|
69
+ Sequenced::Generator.new(self, options).set
70
+ end
45
71
  end
46
72
  end
47
73
  end
@@ -5,13 +5,15 @@ module Sequenced
5
5
  def initialize(record, options = {})
6
6
  @record = record
7
7
  @scope = options[:scope]
8
- @column = (options[:column] || :sequential_id).to_sym
9
- @start_at = options[:start_at] || 1
8
+ @column = options[:column].to_sym
9
+ @start_at = options[:start_at]
10
10
  @skip = options[:skip]
11
11
  end
12
12
 
13
13
  def set
14
- record.send(:"#{column}=", next_id) unless id_set? || skip?
14
+ return if skip? || id_set?
15
+ lock_table
16
+ record.send(:"#{column}=", next_id)
15
17
  end
16
18
 
17
19
  def id_set?
@@ -19,7 +21,7 @@ module Sequenced
19
21
  end
20
22
 
21
23
  def skip?
22
- skip && skip.call(record)
24
+ skip&.call(record)
23
25
  end
24
26
 
25
27
  def next_id
@@ -30,19 +32,33 @@ module Sequenced
30
32
 
31
33
  def next_id_in_sequence
32
34
  start_at = self.start_at.respond_to?(:call) ? self.start_at.call(record) : self.start_at
33
- return start_at unless last_record = find_last_record
34
- max(last_record.send(column) + 1, start_at)
35
+ if (last_record = find_last_record)
36
+ max(last_record.send(column) + 1, start_at)
37
+ else
38
+ start_at
39
+ end
35
40
  end
36
41
 
37
42
  def unique?(id)
38
43
  build_scope(*scope) do
39
44
  rel = base_relation
40
- rel = rel.where("NOT id = ?", record.id) if record.persisted?
45
+ rel = rel.where.not(record.class.primary_key => record.id) if record.persisted?
41
46
  rel.where(column => id)
42
47
  end.count == 0
43
48
  end
44
49
 
45
- private
50
+ private
51
+
52
+ def lock_table
53
+ if postgresql?
54
+ record.class.connection.execute("LOCK TABLE #{record.class.table_name} IN EXCLUSIVE MODE")
55
+ end
56
+ end
57
+
58
+ def postgresql?
59
+ defined?(ActiveRecord::ConnectionAdapters::PostgreSQLAdapter) &&
60
+ record.class.connection.is_a?(ActiveRecord::ConnectionAdapters::PostgreSQLAdapter)
61
+ end
46
62
 
47
63
  def base_relation
48
64
  record.class.base_class.unscoped
@@ -50,9 +66,9 @@ module Sequenced
50
66
 
51
67
  def find_last_record
52
68
  build_scope(*scope) do
53
- base_relation.
54
- where("#{column.to_s} IS NOT NULL").
55
- order("#{column.to_s} DESC")
69
+ base_relation
70
+ .where("#{column} IS NOT NULL")
71
+ .order("#{column} DESC")
56
72
  end.first
57
73
  end
58
74
 
@@ -65,6 +81,5 @@ module Sequenced
65
81
  def max(*values)
66
82
  values.to_a.max
67
83
  end
68
-
69
84
  end
70
- end
85
+ end
@@ -1,3 +1,3 @@
1
1
  module Sequenced
2
- VERSION = "2.0.0"
2
+ VERSION = "4.0.0"
3
3
  end
data/lib/sequenced.rb CHANGED
@@ -1,4 +1,6 @@
1
- require 'sequenced/generator'
2
- require 'sequenced/acts_as_sequenced'
1
+ require "sequenced/generator"
2
+ require "sequenced/acts_as_sequenced"
3
3
 
4
- ActiveRecord::Base.send(:include, Sequenced::ActsAsSequenced)
4
+ ActiveSupport.on_load(:active_record) do
5
+ include Sequenced::ActsAsSequenced
6
+ end
data/sequenced.gemspec CHANGED
@@ -2,20 +2,18 @@ $:.push File.expand_path("../lib", __FILE__)
2
2
  require "sequenced/version"
3
3
 
4
4
  Gem::Specification.new do |s|
5
- s.name = "sequenced"
6
- s.version = Sequenced::VERSION
7
- s.authors = ["Derrick Reimer"]
8
- s.licenses = ['MIT']
9
- s.email = ["derrickreimer@gmail.com"]
10
- s.homepage = "https://github.com/djreimer/sequenced"
11
- s.summary = "Generate scoped sequential IDs for ActiveRecord models"
5
+ s.name = "sequenced"
6
+ s.version = Sequenced::VERSION
7
+ s.authors = ["Derrick Reimer"]
8
+ s.licenses = ["MIT"]
9
+ s.email = ["derrickreimer@gmail.com"]
10
+ s.homepage = "https://github.com/derrickreimer/sequenced"
11
+ s.summary = "Generate scoped sequential IDs for ActiveRecord models"
12
12
  s.description = "Sequenced is a gem that generates scoped sequential IDs for ActiveRecord models."
13
13
 
14
- s.files = `git ls-files`.split("\n")
15
- s.test_files = Dir["test/**/*"]
14
+ s.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
16
15
 
17
16
  s.add_dependency "activesupport", ">= 3.0"
18
17
  s.add_dependency "activerecord", ">= 3.0"
19
18
  s.add_development_dependency "rails", ">= 3.1"
20
- s.add_development_dependency "sqlite3"
21
19
  end