transient_record 2.0.0.rc1 → 2.0.0.rc2

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 +17 -5
  4. metadata +16 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5307d695a68a4250343b0cb8866055f626153fcebde0f0bf69213ef791c777e1
4
- data.tar.gz: 8b0185a7d93b93c179ccf69dc8cc497a4012f9dca66e1bf3d90decddf2375963
3
+ metadata.gz: cf204f3cad36d8d1e2f81a174b617293491fd05a05c0db723ba65fc8bf2dbb9e
4
+ data.tar.gz: b9beca98152782d6946e531418497d68e1cf94f590e7437ffcc3e98d3cefb3b6
5
5
  SHA512:
6
- metadata.gz: 43af400d4dccdfeebd0d5a01c7d7631fb2e43b00453b76fafd7e2e0f2f41bea66b0aa4abdbf057a3139d7dd06d903e5f54ba90c02994f7e44b9449a205729013
7
- data.tar.gz: 3c84c3764e9b8c65c1703062b6f1e4ce4a60d89823f6472a9d20ac7b6157073bb3b8082304597f01617c87e084ca361fd5407546b3d9ddecd0796d8120a8d5ad
6
+ metadata.gz: 37c95fe8e6f9ed85a0d64ae11f17e66d241dbcb728574215315b545085cbeba1d37097554cf6bf178b047cce9864aff07cc0681dfec8249363dcbd2f71e7bfed
7
+ data.tar.gz: 9eced5b248a14742aca7ae9f06b08df15962eb36ee023112b7e63755c7533a186165e8293d90e0fba19aac3ebcb23854483d99a14b46befb5912054b85077c18
data/README.md CHANGED
@@ -133,7 +133,7 @@ Models are automatically assigned to constants. In the example above, the user
133
133
  model is assigned to `Primary::User` via code roughly equivalent to:
134
134
 
135
135
  ```ruby
136
- class TransientRecord::Models::User < ActiveRecord::Base
136
+ class Primary::User < ActiveRecord::Base
137
137
  validates :email, presence: true
138
138
  end
139
139
  ```
@@ -72,7 +72,7 @@
72
72
  # event = Analytics::Event.new
73
73
  class TransientRecord
74
74
  # Transient Record version number.
75
- VERSION = "2.0.0.rc1"
75
+ VERSION = "2.0.0.rc2"
76
76
 
77
77
  # A class representing Transient Record errors.
78
78
  class Error < RuntimeError; end
@@ -162,6 +162,9 @@ class TransientRecord
162
162
  # from the class the context corresponds to and with class body defined by
163
163
  # the block passed to the method.
164
164
  #
165
+ # The base class can be customized by passing in a second argument, but it
166
+ # **must** be a subclass of the context's base class.
167
+ #
165
168
  # Transient models must be removed explicitly by calling {.cleanup} or
166
169
  # {#cleanup}.
167
170
  #
@@ -180,12 +183,21 @@ class TransientRecord
180
183
  #
181
184
  #
182
185
  # @param model_name [String, Symbol] name of model to define.
186
+ # @param base_class [Class] base class the model should inherit from
183
187
  #
184
188
  # @yield class definition
185
189
  #
186
190
  # @return [nil]
187
- def define_model model_name, &block
188
- klass = Class.new @base_class
191
+ def define_model model_name, base_class = nil, &block
192
+ base_class ||= @base_class
193
+
194
+ if base_class > @base_class
195
+ raise Error.new(<<~ERROR)
196
+ #{model_name} base class is #{base_class.name} but it must be a descendant of #{@base_class.name}
197
+ ERROR
198
+ end
199
+
200
+ klass = Class.new base_class
189
201
  const_set model_name, klass
190
202
 
191
203
  klass.class_eval(&block) if block_given?
@@ -248,8 +260,8 @@ class TransientRecord
248
260
  @table_name = table_name
249
261
  end
250
262
 
251
- def define_model &block
252
- @context.define_model @table_name.to_s.classify, &block
263
+ def define_model *args, &block
264
+ @context.define_model @table_name.to_s.classify, *args, &block
253
265
  end
254
266
  end
255
267
 
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: 2.0.0.rc1
4
+ version: 2.0.0.rc2
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-10-13 00:00:00.000000000 Z
11
+ date: 2023-10-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -94,6 +94,20 @@ dependencies:
94
94
  - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: 0.9.28
97
+ - !ruby/object:Gem::Dependency
98
+ name: webrick
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: 1.8.1
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: 1.8.1
97
111
  - !ruby/object:Gem::Dependency
98
112
  name: rubocop
99
113
  requirement: !ruby/object:Gem::Requirement