transient_record 2.0.0 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +11 -0
- data/lib/transient_record.rb +32 -11
- metadata +46 -22
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4211a0125277e2db4878ea00018ee3f9e1509a05570cacf2aa386327f06e2698
|
4
|
+
data.tar.gz: 1fe18d87b43f1d371ec3d40995c74fc9b5309acf727d75423cc0c4a5c9ee9932
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1937db626c3d1fd04b74131286c24164ba3f205853f49b2575428823df8121ace467b5f4df6dabebb1f5cfae9f0d0ae63531a3ac325ca99bd6e7e06c46676460
|
7
|
+
data.tar.gz: af21ea9a803ad6255583e6d928358fb185fc71290dccb0afe5d6f8ebafe6cdea7f457f2e4c2e00448b19e1798e1150dbf9f6fc341d44521d91e53e672db1c1b2
|
data/README.md
CHANGED
@@ -7,6 +7,10 @@ and libraries**.
|
|
7
7
|
The library was extracted from [active_record_doctor](https://github.com/gregnavis/active_record_doctor)
|
8
8
|
to allow reuse.
|
9
9
|
|
10
|
+
## Requirements
|
11
|
+
|
12
|
+
Transient Record requires Ruby 3.1 or newer and Active Record 7.0 or newer.
|
13
|
+
|
10
14
|
## Installation
|
11
15
|
|
12
16
|
Installing Transient Record is a two-step process.
|
@@ -138,6 +142,13 @@ class Primary::User < ActiveRecord::Base
|
|
138
142
|
end
|
139
143
|
```
|
140
144
|
|
145
|
+
If you need to run an arbitrary query in a given context you can do so via
|
146
|
+
`#execute`, which is a wrapper around [the method with the same name in Rails](https://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/DatabaseStatements.html#method-i-execute):
|
147
|
+
|
148
|
+
```ruby
|
149
|
+
Primary.execute("CREATE ROLE gregnavis")
|
150
|
+
```
|
151
|
+
|
141
152
|
## Caveats and Limitations
|
142
153
|
|
143
154
|
Transient Record does **NOT** default to using temporary tables (created via
|
data/lib/transient_record.rb
CHANGED
@@ -60,7 +60,6 @@
|
|
60
60
|
# user = Primary::User.new email: nil
|
61
61
|
#
|
62
62
|
# @example Creating a table and a model in another database
|
63
|
-
# #
|
64
63
|
# Analytics = TransientRecord.context_for AnalyticsRecord
|
65
64
|
#
|
66
65
|
# Analytics.create_table :events do |t|
|
@@ -70,9 +69,17 @@
|
|
70
69
|
# end
|
71
70
|
#
|
72
71
|
# event = Analytics::Event.new
|
72
|
+
#
|
73
|
+
# @example Executing an arbitrary query
|
74
|
+
# # Create a Transient Record context.
|
75
|
+
# Primary = TransientRecord.context_for ActiveRecord::Base
|
76
|
+
#
|
77
|
+
# # Call #execute on the context, which is delegated to the same method
|
78
|
+
# # provided by Rails.
|
79
|
+
# Primary.execute("CREATE ROLE gregnavis")
|
73
80
|
class TransientRecord
|
74
81
|
# Transient Record version number.
|
75
|
-
VERSION = "
|
82
|
+
VERSION = "3.0.0"
|
76
83
|
|
77
84
|
# A class representing Transient Record errors.
|
78
85
|
class Error < RuntimeError; end
|
@@ -90,7 +97,7 @@ class TransientRecord
|
|
90
97
|
# @param base_class [Class] class inheriting from {::ActiveRecord::Base}
|
91
98
|
# @return [Module] module where transient models will be defined; the module
|
92
99
|
# extends {Context}, so it's instance methods can be called on the module.
|
93
|
-
def context_for
|
100
|
+
def context_for(base_class)
|
94
101
|
@contexts[base_class] ||= Context.create base_class
|
95
102
|
end
|
96
103
|
|
@@ -114,7 +121,7 @@ class TransientRecord
|
|
114
121
|
# @return [Module] context module used as a namespace for models
|
115
122
|
#
|
116
123
|
# @api private
|
117
|
-
def self.create
|
124
|
+
def self.create(base_class)
|
118
125
|
Module.new do
|
119
126
|
extend Context
|
120
127
|
@base_class = base_class
|
@@ -147,11 +154,11 @@ class TransientRecord
|
|
147
154
|
# @return [ModelDefinitionProxy]
|
148
155
|
#
|
149
156
|
# @see https://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/SchemaStatements.html#method-i-create_table Documentation for #create_table in Ruby on Rails
|
150
|
-
def create_table
|
157
|
+
def create_table(table_name, options = {}, &)
|
151
158
|
table_name = table_name.to_sym
|
152
159
|
@transient_tables << table_name
|
153
160
|
|
154
|
-
@base_class.connection.create_table
|
161
|
+
@base_class.connection.create_table(table_name, **options, &)
|
155
162
|
|
156
163
|
ModelDefinitionProxy.new self, table_name
|
157
164
|
end
|
@@ -188,7 +195,7 @@ class TransientRecord
|
|
188
195
|
# @yield class definition
|
189
196
|
#
|
190
197
|
# @return [nil]
|
191
|
-
def define_model
|
198
|
+
def define_model(model_name, base_class = nil, &)
|
192
199
|
base_class ||= @base_class
|
193
200
|
|
194
201
|
if base_class > @base_class
|
@@ -200,11 +207,25 @@ class TransientRecord
|
|
200
207
|
klass = Class.new base_class
|
201
208
|
const_set model_name, klass
|
202
209
|
|
203
|
-
klass.class_eval(&
|
210
|
+
klass.class_eval(&) if block_given?
|
204
211
|
|
205
212
|
nil
|
206
213
|
end
|
207
214
|
|
215
|
+
# Executes an arbitrary query.
|
216
|
+
#
|
217
|
+
# This method is a wrapper around the `#execute` method on the Active Record
|
218
|
+
# database connection adapter.
|
219
|
+
#
|
220
|
+
# @param query [String] query to execute
|
221
|
+
# @param name [String] name to log along the query
|
222
|
+
# @return The query result returned by the database connection adapter.
|
223
|
+
#
|
224
|
+
# @see https://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/DatabaseStatements.html#method-i-execute Documentation for #execute in Ruby on Rails
|
225
|
+
def execute(query, name = nil)
|
226
|
+
@base_class.connection.execute query, name
|
227
|
+
end
|
228
|
+
|
208
229
|
# Drops transient tables and models.
|
209
230
|
#
|
210
231
|
# Calling this method removes all models and drops all tables created within
|
@@ -255,13 +276,13 @@ class TransientRecord
|
|
255
276
|
# model in close succession. It's marked private as there's no need for
|
256
277
|
# callers to access it directly.
|
257
278
|
class ModelDefinitionProxy
|
258
|
-
def initialize
|
279
|
+
def initialize(context, table_name)
|
259
280
|
@context = context
|
260
281
|
@table_name = table_name
|
261
282
|
end
|
262
283
|
|
263
|
-
def define_model
|
264
|
-
@context.define_model
|
284
|
+
def define_model(...)
|
285
|
+
@context.define_model(@table_name.to_s.classify, ...)
|
265
286
|
end
|
266
287
|
end
|
267
288
|
|
metadata
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: transient_record
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Greg Navis
|
8
|
-
autorequire:
|
9
8
|
bindir: bin
|
10
9
|
cert_chain: []
|
11
|
-
date:
|
10
|
+
date: 2025-01-11 00:00:00.000000000 Z
|
12
11
|
dependencies:
|
13
12
|
- !ruby/object:Gem::Dependency
|
14
13
|
name: activerecord
|
@@ -25,47 +24,61 @@ dependencies:
|
|
25
24
|
- !ruby/object:Gem::Version
|
26
25
|
version: 4.2.0
|
27
26
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
27
|
+
name: bigdecimal
|
29
28
|
requirement: !ruby/object:Gem::Requirement
|
30
29
|
requirements:
|
31
30
|
- - ">="
|
32
31
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
32
|
+
version: 3.1.9
|
34
33
|
type: :development
|
35
34
|
prerelease: false
|
36
35
|
version_requirements: !ruby/object:Gem::Requirement
|
37
36
|
requirements:
|
38
37
|
- - ">="
|
39
38
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
39
|
+
version: 3.1.9
|
41
40
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
41
|
+
name: mutex_m
|
43
42
|
requirement: !ruby/object:Gem::Requirement
|
44
43
|
requirements:
|
45
44
|
- - ">="
|
46
45
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
46
|
+
version: 0.3.0
|
48
47
|
type: :development
|
49
48
|
prerelease: false
|
50
49
|
version_requirements: !ruby/object:Gem::Requirement
|
51
50
|
requirements:
|
52
51
|
- - ">="
|
53
52
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
53
|
+
version: 0.3.0
|
55
54
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
55
|
+
name: mysql2
|
57
56
|
requirement: !ruby/object:Gem::Requirement
|
58
57
|
requirements:
|
59
58
|
- - ">="
|
60
59
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
60
|
+
version: 0.5.3
|
62
61
|
type: :development
|
63
62
|
prerelease: false
|
64
63
|
version_requirements: !ruby/object:Gem::Requirement
|
65
64
|
requirements:
|
66
65
|
- - ">="
|
67
66
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
67
|
+
version: 0.5.3
|
68
|
+
- !ruby/object:Gem::Dependency
|
69
|
+
name: pg
|
70
|
+
requirement: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: 1.1.4
|
75
|
+
type: :development
|
76
|
+
prerelease: false
|
77
|
+
version_requirements: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: 1.1.4
|
69
82
|
- !ruby/object:Gem::Dependency
|
70
83
|
name: rake
|
71
84
|
requirement: !ruby/object:Gem::Requirement
|
@@ -81,19 +94,19 @@ dependencies:
|
|
81
94
|
- !ruby/object:Gem::Version
|
82
95
|
version: 12.3.3
|
83
96
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
97
|
+
name: sqlite3
|
85
98
|
requirement: !ruby/object:Gem::Requirement
|
86
99
|
requirements:
|
87
100
|
- - ">="
|
88
101
|
- !ruby/object:Gem::Version
|
89
|
-
version:
|
102
|
+
version: 1.5.4
|
90
103
|
type: :development
|
91
104
|
prerelease: false
|
92
105
|
version_requirements: !ruby/object:Gem::Requirement
|
93
106
|
requirements:
|
94
107
|
- - ">="
|
95
108
|
- !ruby/object:Gem::Version
|
96
|
-
version:
|
109
|
+
version: 1.5.4
|
97
110
|
- !ruby/object:Gem::Dependency
|
98
111
|
name: webrick
|
99
112
|
requirement: !ruby/object:Gem::Requirement
|
@@ -108,20 +121,34 @@ dependencies:
|
|
108
121
|
- - ">="
|
109
122
|
- !ruby/object:Gem::Version
|
110
123
|
version: 1.8.1
|
124
|
+
- !ruby/object:Gem::Dependency
|
125
|
+
name: yard
|
126
|
+
requirement: !ruby/object:Gem::Requirement
|
127
|
+
requirements:
|
128
|
+
- - ">="
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: 0.9.28
|
131
|
+
type: :development
|
132
|
+
prerelease: false
|
133
|
+
version_requirements: !ruby/object:Gem::Requirement
|
134
|
+
requirements:
|
135
|
+
- - ">="
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
version: 0.9.28
|
111
138
|
- !ruby/object:Gem::Dependency
|
112
139
|
name: rubocop
|
113
140
|
requirement: !ruby/object:Gem::Requirement
|
114
141
|
requirements:
|
115
142
|
- - ">="
|
116
143
|
- !ruby/object:Gem::Version
|
117
|
-
version: 1.
|
144
|
+
version: 1.70.0
|
118
145
|
type: :development
|
119
146
|
prerelease: false
|
120
147
|
version_requirements: !ruby/object:Gem::Requirement
|
121
148
|
requirements:
|
122
149
|
- - ">="
|
123
150
|
- !ruby/object:Gem::Version
|
124
|
-
version: 1.
|
151
|
+
version: 1.70.0
|
125
152
|
- !ruby/object:Gem::Dependency
|
126
153
|
name: rubocop-rake
|
127
154
|
requirement: !ruby/object:Gem::Requirement
|
@@ -136,7 +163,6 @@ dependencies:
|
|
136
163
|
- - ">="
|
137
164
|
- !ruby/object:Gem::Version
|
138
165
|
version: 0.6.0
|
139
|
-
description:
|
140
166
|
email:
|
141
167
|
- contact@gregnavis.com
|
142
168
|
executables: []
|
@@ -151,7 +177,6 @@ licenses:
|
|
151
177
|
- MIT
|
152
178
|
metadata:
|
153
179
|
rubygems_mfa_required: 'true'
|
154
|
-
post_install_message:
|
155
180
|
rdoc_options: []
|
156
181
|
require_paths:
|
157
182
|
- lib
|
@@ -159,15 +184,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
159
184
|
requirements:
|
160
185
|
- - ">="
|
161
186
|
- !ruby/object:Gem::Version
|
162
|
-
version:
|
187
|
+
version: 3.1.0
|
163
188
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
164
189
|
requirements:
|
165
190
|
- - ">="
|
166
191
|
- !ruby/object:Gem::Version
|
167
192
|
version: '0'
|
168
193
|
requirements: []
|
169
|
-
rubygems_version: 3.
|
170
|
-
signing_key:
|
194
|
+
rubygems_version: 3.6.2
|
171
195
|
specification_version: 4
|
172
196
|
summary: Define transient tables and Active Record models for testing purposes.
|
173
197
|
test_files: []
|