transient_record 1.0.0 → 1.0.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 +4 -4
- data/lib/transient_record.rb +16 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 62717fcb04dc95460008a291475193ad256735122cef3502311ac02d62326baf
|
4
|
+
data.tar.gz: c0d9ac5cd578b60eb9e6e5774886d5e16737eb773766f999b9c201d5a923471c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fb93249d31a827da8ef2a652e9ebe96435d93468bd392d4a228b2200ae03fef6673c0b4995970927f5aa049b4f11d16d096b23fe8f8312749fb8562f45872083
|
7
|
+
data.tar.gz: 36c7bf8748bee4035084b33be89871bb1eeee83f7a75d02a16f52e769bc09587d145318df1279a2932d399ce76245b76f8d9995314d41ba8cbd2a8b9218827a2
|
data/lib/transient_record.rb
CHANGED
@@ -35,7 +35,10 @@
|
|
35
35
|
# end
|
36
36
|
module TransientRecord
|
37
37
|
# Transient Record version number.
|
38
|
-
VERSION = "1.0.
|
38
|
+
VERSION = "1.0.1"
|
39
|
+
|
40
|
+
# A class representing Transient Record errors.
|
41
|
+
class Error < RuntimeError; end
|
39
42
|
|
40
43
|
# A module where all temporary models are defined.
|
41
44
|
#
|
@@ -74,6 +77,10 @@ module TransientRecord
|
|
74
77
|
TransientRecord.define_model(*args, &block)
|
75
78
|
end
|
76
79
|
|
80
|
+
# Transient table names are stored in a module instance variable, so that
|
81
|
+
# only transient tables can be removed in .cleanup.
|
82
|
+
@transient_tables = []
|
83
|
+
|
77
84
|
class << self
|
78
85
|
# Create a transient table.
|
79
86
|
#
|
@@ -101,6 +108,7 @@ module TransientRecord
|
|
101
108
|
# @see https://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/SchemaStatements.html#method-i-create_table Documentation for #create_table in Ruby on Rails
|
102
109
|
def create_table table_name, options = {}, &block
|
103
110
|
table_name = table_name.to_sym
|
111
|
+
@transient_tables << table_name
|
104
112
|
|
105
113
|
::ActiveRecord::Migration.suppress_messages do
|
106
114
|
::ActiveRecord::Migration.create_table table_name, **options, &block
|
@@ -178,7 +186,7 @@ module TransientRecord
|
|
178
186
|
Models.remove_all_consts
|
179
187
|
|
180
188
|
connection = ::ActiveRecord::Base.connection
|
181
|
-
tables_to_remove =
|
189
|
+
tables_to_remove = @transient_tables
|
182
190
|
drop_attempts = tables_to_remove.count * (1 + tables_to_remove.count) / 2
|
183
191
|
|
184
192
|
drop_attempts.times do
|
@@ -194,6 +202,12 @@ module TransientRecord
|
|
194
202
|
end
|
195
203
|
end
|
196
204
|
|
205
|
+
if !@transient_tables.empty?
|
206
|
+
raise Error.new(<<~ERROR)
|
207
|
+
The following transient tables could not be removed: #{@transient_tables.join(', ')}.
|
208
|
+
ERROR
|
209
|
+
end
|
210
|
+
|
197
211
|
GC.start
|
198
212
|
|
199
213
|
nil
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: transient_record
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Greg Navis
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-01-
|
11
|
+
date: 2023-01-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|