transient_record 1.0.0.rc1 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/lib/transient_record.rb +16 -2
  4. metadata +4 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 05ecb3ea508a5454c5a108e2f46ef5e0a390a4467aa5a965db12094bf955dfaf
4
- data.tar.gz: 39d965ea81d0ca307db1c0559c91fe5713df7a44206b5893470e617a479f851c
3
+ metadata.gz: 62717fcb04dc95460008a291475193ad256735122cef3502311ac02d62326baf
4
+ data.tar.gz: c0d9ac5cd578b60eb9e6e5774886d5e16737eb773766f999b9c201d5a923471c
5
5
  SHA512:
6
- metadata.gz: b04aa876557bcfe4488a42f97786c3abdfe6d4621fe6e9956708e005fc0b5a0f51c13fa65e5261c7ce89186e0691107f0c9ce3ce0e998796ef20425a0800d79f
7
- data.tar.gz: 934d8eb96dc127056a33e1907649eaf17dbb0b01902345c3f48cfdb6c495da976c63221aadf5070ba7b5d9aad4e92c557277462a25ac5109458821d9dbc0542c
6
+ metadata.gz: fb93249d31a827da8ef2a652e9ebe96435d93468bd392d4a228b2200ae03fef6673c0b4995970927f5aa049b4f11d16d096b23fe8f8312749fb8562f45872083
7
+ data.tar.gz: 36c7bf8748bee4035084b33be89871bb1eeee83f7a75d02a16f52e769bc09587d145318df1279a2932d399ce76245b76f8d9995314d41ba8cbd2a8b9218827a2
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Transient Record
2
2
 
3
- `transient-record` is a gem to define temporary tables and Active Record models
3
+ `transient_record` is a gem to define temporary tables and Active Record models
4
4
  for testing purposes. It's a great tool for testing **generic Active Record code
5
5
  and libraries**.
6
6
 
@@ -35,7 +35,10 @@
35
35
  # end
36
36
  module TransientRecord
37
37
  # Transient Record version number.
38
- VERSION = "1.0.0.rc1"
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.rc1
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-17 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
@@ -148,9 +148,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
148
148
  version: 2.4.0
149
149
  required_rubygems_version: !ruby/object:Gem::Requirement
150
150
  requirements:
151
- - - ">"
151
+ - - ">="
152
152
  - !ruby/object:Gem::Version
153
- version: 1.3.1
153
+ version: '0'
154
154
  requirements: []
155
155
  rubygems_version: 3.2.33
156
156
  signing_key: