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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/transient_record.rb +16 -2
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9567dc6a94b5693ba7522664172ec95257734f81820307ed705d1a8a55323aef
4
- data.tar.gz: 82833fbb5361c27361347d89b38fb709a102fa5be820be30710a5b1debc061de
3
+ metadata.gz: 62717fcb04dc95460008a291475193ad256735122cef3502311ac02d62326baf
4
+ data.tar.gz: c0d9ac5cd578b60eb9e6e5774886d5e16737eb773766f999b9c201d5a923471c
5
5
  SHA512:
6
- metadata.gz: 2a5ce0b5c9859a9e88ee78b119891cbc8f2daaa930db25a52fb14a6e93723d1d91e850a67f99fd70b8c1ccda80a52f206bb83a529f8cd52e1e11c9e9fe89c657
7
- data.tar.gz: 3c64275220d6138377788c9e294b3f67f5285801ac977e03933489a65654604248a757feeca210cd7b642c01d08941e534d510f9814c252d1d5e8885b298f4d7
6
+ metadata.gz: fb93249d31a827da8ef2a652e9ebe96435d93468bd392d4a228b2200ae03fef6673c0b4995970927f5aa049b4f11d16d096b23fe8f8312749fb8562f45872083
7
+ data.tar.gz: 36c7bf8748bee4035084b33be89871bb1eeee83f7a75d02a16f52e769bc09587d145318df1279a2932d399ce76245b76f8d9995314d41ba8cbd2a8b9218827a2
@@ -35,7 +35,10 @@
35
35
  # end
36
36
  module TransientRecord
37
37
  # Transient Record version number.
38
- VERSION = "1.0.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 = connection.tables
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.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-24 00:00:00.000000000 Z
11
+ date: 2023-01-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord