historiographer 4.1.3 → 4.1.4
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/historiographer/history.rb +1 -1
- data/lib/historiographer/version.rb +1 -1
- data/lib/historiographer.rb +28 -17
- 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: ec4560a7984db99bb67a91f6ed46ffd5e0e0b68b208b9f5c56079d5d0c967c06
|
4
|
+
data.tar.gz: 558f4f69363da666c55ad58bdf4aa1108e405c96d54e2ae4d96f4d7baa87e4a0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 803285240c47f720ae89ba027d1143e7b0e63ed765bb26399b7d126e2c04449664604a7488553f8996f89c3736d86909ed52702fcc5fb4bf7df2cb2fa5de4a44
|
7
|
+
data.tar.gz: 263c7cd005f3cd3589a1ed47c62d7127844686c5b945e1835995b99151b0bbceb6b72c86bac80e09b17efde796e3eeef2b34a0d9f33fb99945915e14b1c9aef8
|
@@ -180,7 +180,7 @@ module Historiographer
|
|
180
180
|
def history_foreign_key
|
181
181
|
return @history_foreign_key if @history_foreign_key
|
182
182
|
|
183
|
-
@history_foreign_key = sti_base_class.
|
183
|
+
@history_foreign_key = sti_base_class.table_name.singularize.foreign_key
|
184
184
|
end
|
185
185
|
|
186
186
|
def sti_base_class
|
data/lib/historiographer.rb
CHANGED
@@ -185,12 +185,30 @@ module Historiographer
|
|
185
185
|
begin
|
186
186
|
class_name.constantize
|
187
187
|
rescue StandardError
|
188
|
+
# Get the base table name without _histories suffix
|
189
|
+
base_table = base.table_name.sub(/_histories$/, '')
|
190
|
+
|
188
191
|
history_class_initializer = Class.new(base) do
|
189
|
-
self.table_name = "#{
|
190
|
-
|
192
|
+
self.table_name = "#{base_table}_histories"
|
193
|
+
|
194
|
+
# Handle STI properly
|
195
|
+
self.inheritance_column = base.inheritance_column if base.respond_to?(:inheritance_column)
|
191
196
|
end
|
192
197
|
|
193
|
-
|
198
|
+
# Split the class name into module parts and the actual class name
|
199
|
+
module_parts = class_name.split('::')
|
200
|
+
final_class_name = module_parts.pop
|
201
|
+
|
202
|
+
# Navigate through module hierarchy
|
203
|
+
target_module = module_parts.inject(Object) do |mod, module_name|
|
204
|
+
mod.const_defined?(module_name) ? mod.const_get(module_name) : mod.const_set(module_name, Module.new)
|
205
|
+
end
|
206
|
+
|
207
|
+
# Set the constant in the correct module
|
208
|
+
history_class = target_module.const_set(final_class_name, history_class_initializer)
|
209
|
+
|
210
|
+
# Now that the class is named, include the History module and extend class methods
|
211
|
+
history_class.send(:include, Historiographer::History)
|
194
212
|
end
|
195
213
|
|
196
214
|
klass = class_name.constantize
|
@@ -259,21 +277,13 @@ module Historiographer
|
|
259
277
|
end
|
260
278
|
end)
|
261
279
|
|
262
|
-
|
263
|
-
|
264
|
-
else
|
265
|
-
opts = { class_name: class_name }
|
266
|
-
opts[:foreign_key] = klass.history_foreign_key if klass.respond_to?(:history_foreign_key)
|
267
|
-
if RUBY_VERSION.to_i >= 3
|
268
|
-
has_many :histories, **opts
|
269
|
-
has_one :current_history, -> { current }, **opts
|
270
|
-
else
|
271
|
-
has_many :histories, opts
|
272
|
-
has_one :current_history, -> { current }, opts
|
273
|
-
end
|
280
|
+
def histories
|
281
|
+
history_class.where(history_class.history_foreign_key => self.send(self.class.primary_key))
|
274
282
|
end
|
275
283
|
|
276
|
-
|
284
|
+
def current_history
|
285
|
+
history_class.where(history_class.history_foreign_key => self.send(self.class.primary_key)).current&.first
|
286
|
+
end
|
277
287
|
|
278
288
|
#
|
279
289
|
# The acts_as_paranoid gem, which we tend to use with our History classes,
|
@@ -364,7 +374,8 @@ module Historiographer
|
|
364
374
|
|
365
375
|
# For STI, ensure we use the correct history class type
|
366
376
|
if self.class.sti_enabled?
|
367
|
-
|
377
|
+
type_column = self.class.inheritance_column
|
378
|
+
attrs[type_column] = "#{self.class.name}History"
|
368
379
|
end
|
369
380
|
|
370
381
|
attrs = attrs.except('id')
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: historiographer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.1.
|
4
|
+
version: 4.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- brettshollenberger
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-11-
|
11
|
+
date: 2024-11-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|