sequenced 3.0.0 → 3.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -1
- data/MIT-LICENSE +1 -1
- data/README.md +12 -0
- data/lib/sequenced/acts_as_sequenced.rb +33 -6
- data/lib/sequenced/generator.rb +2 -2
- data/lib/sequenced/version.rb +1 -1
- data/test/dummy/app/models/doppelganger.rb +4 -0
- data/test/dummy/config/environments/production.rb +1 -1
- data/test/dummy/config/environments/test.rb +3 -1
- data/test/dummy/db/migrate/20160118182655_create_doppelgangers.rb +10 -0
- data/test/dummy/db/schema.rb +46 -12
- data/test/multiple_sequences_test.rb +20 -0
- metadata +8 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0706f251eb15142b2e59f24168bdfc83bbb86d51
|
4
|
+
data.tar.gz: e222ef16202f2703c315b107136687c5e484fe41
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6b2e5b704a339e4449d1ba8175bb72dc5e857450d693aed070304c61865d546bc3459e8412d7990ac112f8da0f3f4ff1d560f94be09c000c66a2bf4d5d6c6a9b
|
7
|
+
data.tar.gz: 601a93fee12817506cce21f0027eb89b35418cffe1cfa26183810fd59ae31adf435f609d53ffb92e1e3c9ae3cfff6e5d281b9636c4045ff762d79fde4ae46d2d
|
data/CHANGELOG.md
CHANGED
@@ -1,8 +1,14 @@
|
|
1
|
+
3.1.0 (January 23, 2016)
|
2
|
+
-------------------------
|
3
|
+
|
4
|
+
* Allow multiple sequences on one record
|
5
|
+
(samphilipd, [#19](https://github.com/djreimer/sequenced/pull/19))
|
6
|
+
|
1
7
|
3.0.0 (November 28, 2015)
|
2
8
|
-------------------------
|
3
9
|
|
4
10
|
* Make this gem thread-safe for PostgreSQL
|
5
|
-
(samphilipd, [#16](https://github.com/djreimer/sequenced/pull/16))
|
11
|
+
(samphilipd, [#16](https://github.com/djreimer/sequenced/pull/16))
|
6
12
|
|
7
13
|
2.0.0 (October 24, 2014)
|
8
14
|
------------------------
|
data/MIT-LICENSE
CHANGED
data/README.md
CHANGED
@@ -70,6 +70,18 @@ class Answer < ActiveRecord::Base
|
|
70
70
|
end
|
71
71
|
```
|
72
72
|
|
73
|
+
Multiple sequences can be defined by using the macro multiple times:
|
74
|
+
|
75
|
+
```ruby
|
76
|
+
class Answer < ActiveRecord::Base
|
77
|
+
belongs_to :account
|
78
|
+
belongs_to :question
|
79
|
+
|
80
|
+
acts_as_sequenced column: :question_answer_number, scope: :question_id
|
81
|
+
acts_as_sequenced column: :account_answer_number, scope: :account_id
|
82
|
+
end
|
83
|
+
```
|
84
|
+
|
73
85
|
## Schema and data integrity
|
74
86
|
|
75
87
|
**This gem is only concurrent-safe for PostgreSQL databases**. For other database systems, unexpected behavior may occur if you attempt to create records concurrently.
|
@@ -3,6 +3,12 @@ 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,36 @@ module Sequenced
|
|
31
39
|
#
|
32
40
|
# Returns nothing.
|
33
41
|
def acts_as_sequenced(options = {})
|
34
|
-
|
35
|
-
|
42
|
+
unless defined?(sequenced_options)
|
43
|
+
include Sequenced::ActsAsSequenced::InstanceMethods
|
44
|
+
|
45
|
+
mattr_accessor :sequenced_options, instance_accessor: false do
|
46
|
+
[]
|
47
|
+
end
|
48
|
+
|
49
|
+
before_save :set_sequential_ids
|
50
|
+
end
|
51
|
+
|
52
|
+
options = DEFAULT_OPTIONS.merge(options)
|
53
|
+
column_name = options[:column]
|
36
54
|
|
37
|
-
|
38
|
-
|
55
|
+
if sequenced_options.any? {|options| options[:column] == column_name}
|
56
|
+
raise(SequencedColumnExists, <<-MSG.squish)
|
57
|
+
Tried to set #{column_name} as sequenced but there was already a
|
58
|
+
definition here. Did you accidentally call acts_as_sequenced
|
59
|
+
multiple times on the same column?
|
60
|
+
MSG
|
61
|
+
else
|
62
|
+
sequenced_options << options
|
63
|
+
end
|
39
64
|
end
|
40
65
|
end
|
41
66
|
|
42
67
|
module InstanceMethods
|
43
|
-
def
|
44
|
-
|
68
|
+
def set_sequential_ids
|
69
|
+
self.class.base_class.sequenced_options.each do |options|
|
70
|
+
Sequenced::Generator.new(self, options).set
|
71
|
+
end
|
45
72
|
end
|
46
73
|
end
|
47
74
|
end
|
data/lib/sequenced/generator.rb
CHANGED
@@ -5,8 +5,8 @@ module Sequenced
|
|
5
5
|
def initialize(record, options = {})
|
6
6
|
@record = record
|
7
7
|
@scope = options[:scope]
|
8
|
-
@column =
|
9
|
-
@start_at = options[:start_at]
|
8
|
+
@column = options[:column].to_sym
|
9
|
+
@start_at = options[:start_at]
|
10
10
|
@skip = options[:skip]
|
11
11
|
end
|
12
12
|
|
data/lib/sequenced/version.rb
CHANGED
@@ -9,7 +9,7 @@ Dummy::Application.configure do
|
|
9
9
|
config.action_controller.perform_caching = true
|
10
10
|
|
11
11
|
# Disable Rails's static asset server (Apache or nginx will already do this)
|
12
|
-
config.
|
12
|
+
config.serve_static_files = false
|
13
13
|
|
14
14
|
# Compress JavaScripts and CSS
|
15
15
|
config.assets.compress = true
|
@@ -9,7 +9,7 @@ Dummy::Application.configure do
|
|
9
9
|
config.cache_classes = true
|
10
10
|
|
11
11
|
# Configure static asset server for tests with Cache-Control for performance
|
12
|
-
config.
|
12
|
+
config.serve_static_files = true
|
13
13
|
config.static_cache_control = "public, max-age=3600"
|
14
14
|
|
15
15
|
# Log error messages when you accidentally call methods on nil
|
@@ -38,4 +38,6 @@ Dummy::Application.configure do
|
|
38
38
|
|
39
39
|
# Required for Rails >= 4.2
|
40
40
|
config.eager_load = true
|
41
|
+
|
42
|
+
config.active_support.test_order = :random
|
41
43
|
end
|
data/test/dummy/db/schema.rb
CHANGED
@@ -11,22 +11,22 @@
|
|
11
11
|
#
|
12
12
|
# It's strongly recommended that you check this file into your version control system.
|
13
13
|
|
14
|
-
ActiveRecord::Schema.define(version:
|
14
|
+
ActiveRecord::Schema.define(version: 20160118182655) do
|
15
15
|
|
16
|
-
create_table "accounts", force:
|
16
|
+
create_table "accounts", force: :cascade do |t|
|
17
17
|
t.string "name"
|
18
18
|
t.datetime "created_at"
|
19
19
|
t.datetime "updated_at"
|
20
20
|
end
|
21
21
|
|
22
|
-
create_table "addresses", force:
|
22
|
+
create_table "addresses", force: :cascade do |t|
|
23
23
|
t.integer "account_id"
|
24
24
|
t.string "city"
|
25
25
|
t.datetime "created_at"
|
26
26
|
t.datetime "updated_at"
|
27
27
|
end
|
28
28
|
|
29
|
-
create_table "answers", force:
|
29
|
+
create_table "answers", force: :cascade do |t|
|
30
30
|
t.integer "question_id"
|
31
31
|
t.text "body"
|
32
32
|
t.integer "sequential_id"
|
@@ -37,7 +37,7 @@ ActiveRecord::Schema.define(version: 20130715002029) do
|
|
37
37
|
add_index "answers", ["question_id"], name: "index_answers_on_question_id"
|
38
38
|
add_index "answers", ["sequential_id"], name: "index_answers_on_sequential_id"
|
39
39
|
|
40
|
-
create_table "comments", force:
|
40
|
+
create_table "comments", force: :cascade do |t|
|
41
41
|
t.integer "question_id"
|
42
42
|
t.text "body"
|
43
43
|
t.integer "sequential_id"
|
@@ -47,7 +47,21 @@ ActiveRecord::Schema.define(version: 20130715002029) do
|
|
47
47
|
|
48
48
|
add_index "comments", ["question_id"], name: "index_comments_on_question_id"
|
49
49
|
|
50
|
-
create_table "
|
50
|
+
create_table "concurrent_badgers", force: :cascade do |t|
|
51
|
+
t.integer "sequential_id", null: false
|
52
|
+
t.integer "burrow_id"
|
53
|
+
end
|
54
|
+
|
55
|
+
add_index "concurrent_badgers", ["sequential_id", "burrow_id"], name: "unique_concurrent", unique: true
|
56
|
+
|
57
|
+
create_table "doppelgangers", force: :cascade do |t|
|
58
|
+
t.integer "sequential_id_one"
|
59
|
+
t.integer "sequential_id_two"
|
60
|
+
t.datetime "created_at", null: false
|
61
|
+
t.datetime "updated_at", null: false
|
62
|
+
end
|
63
|
+
|
64
|
+
create_table "emails", force: :cascade do |t|
|
51
65
|
t.string "emailable_type"
|
52
66
|
t.integer "emailable_id"
|
53
67
|
t.integer "sequential_id"
|
@@ -56,7 +70,7 @@ ActiveRecord::Schema.define(version: 20130715002029) do
|
|
56
70
|
t.datetime "updated_at"
|
57
71
|
end
|
58
72
|
|
59
|
-
create_table "invoices", force:
|
73
|
+
create_table "invoices", force: :cascade do |t|
|
60
74
|
t.integer "amount"
|
61
75
|
t.integer "sequential_id"
|
62
76
|
t.integer "account_id"
|
@@ -66,21 +80,41 @@ ActiveRecord::Schema.define(version: 20130715002029) do
|
|
66
80
|
|
67
81
|
add_index "invoices", ["account_id"], name: "index_invoices_on_account_id"
|
68
82
|
|
69
|
-
create_table "
|
83
|
+
create_table "monsters", force: :cascade do |t|
|
84
|
+
t.integer "sequential_id"
|
85
|
+
t.string "type"
|
86
|
+
t.datetime "created_at"
|
87
|
+
t.datetime "updated_at"
|
88
|
+
end
|
89
|
+
|
90
|
+
create_table "orders", force: :cascade do |t|
|
70
91
|
t.string "product"
|
71
92
|
t.integer "account_id"
|
72
93
|
t.datetime "created_at"
|
73
94
|
t.datetime "updated_at"
|
74
95
|
end
|
75
96
|
|
76
|
-
create_table "
|
97
|
+
create_table "policemen", force: :cascade do |t|
|
98
|
+
t.integer "sequential_id"
|
99
|
+
t.datetime "created_at"
|
100
|
+
t.datetime "updated_at"
|
101
|
+
end
|
102
|
+
|
103
|
+
create_table "products", force: :cascade do |t|
|
104
|
+
t.integer "account_id"
|
105
|
+
t.integer "sequential_id"
|
106
|
+
t.datetime "created_at"
|
107
|
+
t.datetime "updated_at"
|
108
|
+
end
|
109
|
+
|
110
|
+
create_table "questions", force: :cascade do |t|
|
77
111
|
t.string "summary"
|
78
112
|
t.text "body"
|
79
113
|
t.datetime "created_at"
|
80
114
|
t.datetime "updated_at"
|
81
115
|
end
|
82
116
|
|
83
|
-
create_table "ratings", force:
|
117
|
+
create_table "ratings", force: :cascade do |t|
|
84
118
|
t.integer "comment_id"
|
85
119
|
t.integer "score"
|
86
120
|
t.integer "sequential_id"
|
@@ -88,14 +122,14 @@ ActiveRecord::Schema.define(version: 20130715002029) do
|
|
88
122
|
t.datetime "updated_at"
|
89
123
|
end
|
90
124
|
|
91
|
-
create_table "subscriptions", force:
|
125
|
+
create_table "subscriptions", force: :cascade do |t|
|
92
126
|
t.string "plan"
|
93
127
|
t.integer "sequential_id"
|
94
128
|
t.datetime "created_at"
|
95
129
|
t.datetime "updated_at"
|
96
130
|
end
|
97
131
|
|
98
|
-
create_table "users", force:
|
132
|
+
create_table "users", force: :cascade do |t|
|
99
133
|
t.integer "account_id"
|
100
134
|
t.string "name"
|
101
135
|
t.integer "custom_sequential_id"
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class MultipleSequencesTest < ActiveSupport::TestCase
|
4
|
+
test "works with simple multiple sequences" do
|
5
|
+
doppelganger = Doppelganger.create!
|
6
|
+
assert_equal 1, doppelganger.sequential_id_one
|
7
|
+
assert_equal 1000, doppelganger.sequential_id_two
|
8
|
+
end
|
9
|
+
|
10
|
+
test "raises error on multiple definitions for the same column" do
|
11
|
+
assert_raise Sequenced::ActsAsSequenced::SequencedColumnExists do
|
12
|
+
Doppelganger.class_eval do
|
13
|
+
acts_as_sequenced column: :sequential_id_one, start_at: 99
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
doppelganger = Doppelganger.create!
|
18
|
+
assert_equal 1, doppelganger.sequential_id_one
|
19
|
+
end
|
20
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sequenced
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Derrick Reimer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-01-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -87,6 +87,7 @@ files:
|
|
87
87
|
- test/dummy/app/models/answer.rb
|
88
88
|
- test/dummy/app/models/comment.rb
|
89
89
|
- test/dummy/app/models/concurrent_badger.rb
|
90
|
+
- test/dummy/app/models/doppelganger.rb
|
90
91
|
- test/dummy/app/models/email.rb
|
91
92
|
- test/dummy/app/models/invoice.rb
|
92
93
|
- test/dummy/app/models/monster.rb
|
@@ -132,6 +133,7 @@ files:
|
|
132
133
|
- test/dummy/db/migrate/20131226000000_create_monsters.rb
|
133
134
|
- test/dummy/db/migrate/20140404195334_create_policemen.rb
|
134
135
|
- test/dummy/db/migrate/20151120190645_create_concurrent_badgers.rb
|
136
|
+
- test/dummy/db/migrate/20160118182655_create_doppelgangers.rb
|
135
137
|
- test/dummy/db/schema.rb
|
136
138
|
- test/dummy/db/test.sqlite3
|
137
139
|
- test/dummy/lib/assets/.gitkeep
|
@@ -143,6 +145,7 @@ files:
|
|
143
145
|
- test/dummy/public/500.html
|
144
146
|
- test/dummy/public/favicon.ico
|
145
147
|
- test/dummy/script/rails
|
148
|
+
- test/multiple_sequences_test.rb
|
146
149
|
- test/test_helper.rb
|
147
150
|
homepage: https://github.com/djreimer/sequenced
|
148
151
|
licenses:
|
@@ -180,6 +183,7 @@ test_files:
|
|
180
183
|
- test/dummy/app/models/answer.rb
|
181
184
|
- test/dummy/app/models/comment.rb
|
182
185
|
- test/dummy/app/models/concurrent_badger.rb
|
186
|
+
- test/dummy/app/models/doppelganger.rb
|
183
187
|
- test/dummy/app/models/email.rb
|
184
188
|
- test/dummy/app/models/invoice.rb
|
185
189
|
- test/dummy/app/models/monster.rb
|
@@ -225,6 +229,7 @@ test_files:
|
|
225
229
|
- test/dummy/db/migrate/20131226000000_create_monsters.rb
|
226
230
|
- test/dummy/db/migrate/20140404195334_create_policemen.rb
|
227
231
|
- test/dummy/db/migrate/20151120190645_create_concurrent_badgers.rb
|
232
|
+
- test/dummy/db/migrate/20160118182655_create_doppelgangers.rb
|
228
233
|
- test/dummy/db/schema.rb
|
229
234
|
- test/dummy/db/test.sqlite3
|
230
235
|
- test/dummy/log/development.log
|
@@ -236,5 +241,5 @@ test_files:
|
|
236
241
|
- test/dummy/Rakefile
|
237
242
|
- test/dummy/README.rdoc
|
238
243
|
- test/dummy/script/rails
|
244
|
+
- test/multiple_sequences_test.rb
|
239
245
|
- test/test_helper.rb
|
240
|
-
has_rdoc:
|