historiographer 3.1.1 → 4.0.0
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/.ruby-version +1 -1
- data/Gemfile +1 -1
- data/Gemfile.lock +1 -1
- data/VERSION +1 -1
- data/historiographer.gemspec +4 -4
- data/lib/historiographer/history_migration.rb +7 -2
- data/lib/historiographer.rb +30 -25
- data/spec/examples.txt +30 -27
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f16398b9f6b0a3d58501a2115eabca0e0f93a938d04eeb4c21d3713f9b70079a
|
4
|
+
data.tar.gz: a460ef65372e236b001225b1028837eb7ba107e8d45d958c39d003be0cd64db4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3b545edcfe0076f0e83f5478347a9298fce77118d7274ad39ce8304844637b7ee15980e66c02dff36321eda4e36b0defdb10b6c33cc7486fba47e780043e5f42
|
7
|
+
data.tar.gz: f828cf26cc357fb0b3e2750bfcc1f62dc628c1579f1fa3356062f34314545783bb6ecb80366e4ac9d6988eae8374168afeb0d29c166daa9dbd7c860074494de4
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
3.0.2
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
4.0.0
|
data/historiographer.gemspec
CHANGED
@@ -2,16 +2,16 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: historiographer
|
5
|
+
# stub: historiographer 4.0.0 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "historiographer".freeze
|
9
|
-
s.version = "
|
9
|
+
s.version = "4.0.0"
|
10
10
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
|
12
12
|
s.require_paths = ["lib".freeze]
|
13
13
|
s.authors = ["brettshollenberger".freeze]
|
14
|
-
s.date = "
|
14
|
+
s.date = "2023-08-22"
|
15
15
|
s.description = "Creates separate tables for each history table".freeze
|
16
16
|
s.email = "brett.shollenberger@gmail.com".freeze
|
17
17
|
s.extra_rdoc_files = [
|
@@ -62,7 +62,7 @@ Gem::Specification.new do |s|
|
|
62
62
|
]
|
63
63
|
s.homepage = "http://github.com/brettshollenberger/historiographer".freeze
|
64
64
|
s.licenses = ["MIT".freeze]
|
65
|
-
s.rubygems_version = "3.2.
|
65
|
+
s.rubygems_version = "3.2.22".freeze
|
66
66
|
s.summary = "Create histories of your ActiveRecord tables".freeze
|
67
67
|
|
68
68
|
if s.respond_to? :specification_version then
|
@@ -34,7 +34,12 @@ module Historiographer
|
|
34
34
|
opts = {}
|
35
35
|
opts.merge!(column.as_json.clone)
|
36
36
|
|
37
|
-
|
37
|
+
if RUBY_VERSION.to_i >= 3
|
38
|
+
puts "Hello"
|
39
|
+
send(column.type, column.name, **opts.symbolize_keys!)
|
40
|
+
else
|
41
|
+
send(column.type, column.name, opts.symbolize_keys!)
|
42
|
+
end
|
38
43
|
end
|
39
44
|
|
40
45
|
datetime :history_started_at, null: false
|
@@ -86,4 +91,4 @@ module Historiographer
|
|
86
91
|
|
87
92
|
end
|
88
93
|
end
|
89
|
-
end
|
94
|
+
end
|
data/lib/historiographer.rb
CHANGED
@@ -1,8 +1,11 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
require_relative
|
5
|
-
require_relative
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'active_support/all'
|
4
|
+
require_relative './historiographer/history'
|
5
|
+
require_relative './historiographer/postgres_migration'
|
6
|
+
require_relative './historiographer/safe'
|
7
|
+
require_relative './historiographer/relation'
|
8
|
+
require_relative './historiographer/silent'
|
6
9
|
|
7
10
|
# Historiographer takes "histories" (think audits or snapshots) of your model whenever you make changes.
|
8
11
|
#
|
@@ -74,7 +77,7 @@ module Historiographer
|
|
74
77
|
|
75
78
|
class HistoryUserIdMissingError < StandardError; end
|
76
79
|
|
77
|
-
UTC = Time.now.in_time_zone(
|
80
|
+
UTC = Time.now.in_time_zone('UTC').time_zone
|
78
81
|
|
79
82
|
included do |base|
|
80
83
|
after_save :record_history, if: :should_record_history?
|
@@ -86,7 +89,7 @@ module Historiographer
|
|
86
89
|
|
87
90
|
def validate_history_user_id_present
|
88
91
|
if @no_history.nil? && (!history_user_id.present? || !history_user_id.is_a?(Integer))
|
89
|
-
errors.add(:history_user_id,
|
92
|
+
errors.add(:history_user_id, 'must be an integer')
|
90
93
|
end
|
91
94
|
end
|
92
95
|
|
@@ -95,7 +98,7 @@ module Historiographer
|
|
95
98
|
def destroy_with_history(history_user_id: nil)
|
96
99
|
history_user_absent_action if history_user_id.nil?
|
97
100
|
|
98
|
-
current_history = histories.where(history_ended_at: nil).order(
|
101
|
+
current_history = histories.where(history_ended_at: nil).order('id desc').limit(1).last
|
99
102
|
current_history.update!(history_ended_at: UTC.now) if current_history.present?
|
100
103
|
|
101
104
|
if respond_to?(:paranoia_destroy)
|
@@ -138,7 +141,7 @@ module Historiographer
|
|
138
141
|
when 0..5 then changed? && valid?
|
139
142
|
when 5.1..7 then saved_changes?
|
140
143
|
else
|
141
|
-
raise
|
144
|
+
raise 'Unsupported Rails version'
|
142
145
|
end
|
143
146
|
end
|
144
147
|
|
@@ -157,7 +160,7 @@ module Historiographer
|
|
157
160
|
|
158
161
|
begin
|
159
162
|
class_name.constantize
|
160
|
-
rescue
|
163
|
+
rescue StandardError
|
161
164
|
history_class_initializer = Class.new(ActiveRecord::Base) do
|
162
165
|
end
|
163
166
|
|
@@ -170,9 +173,14 @@ module Historiographer
|
|
170
173
|
raise "#{base} already has histories. Talk to Brett if this is a legit use case."
|
171
174
|
else
|
172
175
|
opts = { class_name: class_name }
|
173
|
-
opts
|
174
|
-
|
175
|
-
|
176
|
+
opts[:foreign_key] = klass.history_foreign_key if klass.respond_to?(:history_foreign_key)
|
177
|
+
if RUBY_VERSION.to_i >= 3
|
178
|
+
has_many :histories, **opts
|
179
|
+
has_one :current_history, -> { current }, **opts
|
180
|
+
else
|
181
|
+
has_many :histories, opts
|
182
|
+
has_one :current_history, -> { current }, opts
|
183
|
+
end
|
176
184
|
end
|
177
185
|
|
178
186
|
klass.send(:include, Historiographer::History) unless klass.ancestors.include?(Historiographer::History)
|
@@ -187,14 +195,12 @@ module Historiographer
|
|
187
195
|
module UpdateColumnsWithHistory
|
188
196
|
def update_columns(*args)
|
189
197
|
opts = args.extract_options!
|
190
|
-
any_changes = opts.keys.reject { |k| k ==
|
198
|
+
any_changes = opts.keys.reject { |k| k == 'id' }.any?
|
191
199
|
|
192
200
|
transaction do
|
193
201
|
persisted = super(opts)
|
194
202
|
|
195
|
-
if any_changes && persisted
|
196
|
-
record_history
|
197
|
-
end
|
203
|
+
record_history if any_changes && persisted
|
198
204
|
end
|
199
205
|
end
|
200
206
|
end
|
@@ -216,7 +222,7 @@ module Historiographer
|
|
216
222
|
private
|
217
223
|
|
218
224
|
def history_user_absent_action
|
219
|
-
raise HistoryUserIdMissingError
|
225
|
+
raise HistoryUserIdMissingError, 'history_user_id must be passed in order to save record with histories! If you are in a context with no history_user_id, explicitly call #save_without_user'
|
220
226
|
end
|
221
227
|
|
222
228
|
#
|
@@ -233,23 +239,22 @@ module Historiographer
|
|
233
239
|
foreign_key = history_class.history_foreign_key
|
234
240
|
|
235
241
|
now = UTC.now
|
236
|
-
attrs.merge!(foreign_key => attrs[
|
242
|
+
attrs.merge!(foreign_key => attrs['id'], history_started_at: now, history_user_id: history_user_id)
|
237
243
|
|
238
|
-
attrs = attrs.except(
|
244
|
+
attrs = attrs.except('id')
|
239
245
|
|
240
|
-
current_history = histories.where(history_ended_at: nil).order(
|
246
|
+
current_history = histories.where(history_ended_at: nil).order('id desc').limit(1).last
|
241
247
|
|
242
|
-
|
243
|
-
raise "Need foreign key and history class to save history!"
|
244
|
-
else
|
248
|
+
if foreign_key.present? && history_class.present?
|
245
249
|
history_class.create!(attrs)
|
246
250
|
current_history.update!(history_ended_at: now) if current_history.present?
|
251
|
+
else
|
252
|
+
raise 'Need foreign key and history class to save history!'
|
247
253
|
end
|
248
254
|
end
|
249
255
|
end
|
250
256
|
|
251
257
|
class_methods do
|
252
|
-
|
253
258
|
#
|
254
259
|
# E.g. SponsoredProductCampaign => SponsoredProductCampaignHistory
|
255
260
|
#
|
data/spec/examples.txt
CHANGED
@@ -1,29 +1,32 @@
|
|
1
1
|
example_id | status | run_time |
|
2
2
|
----------------------------------------- | ------ | --------------- |
|
3
|
-
./spec/historiographer_spec.rb[1:1:1] | passed | 0.
|
4
|
-
./spec/historiographer_spec.rb[1:1:2] | passed | 0.
|
5
|
-
./spec/historiographer_spec.rb[1:1:3] | passed | 0.
|
6
|
-
./spec/historiographer_spec.rb[1:2:1] | passed | 0.
|
7
|
-
./spec/historiographer_spec.rb[1:2:2] | passed | 0.
|
8
|
-
./spec/historiographer_spec.rb[1:2:3:1:1] | passed | 0.
|
9
|
-
./spec/historiographer_spec.rb[1:2:3:1:2] | passed | 0.
|
10
|
-
./spec/historiographer_spec.rb[1:2:3:2:1] | passed | 0.
|
11
|
-
./spec/historiographer_spec.rb[1:2:3:2:2] | passed | 0.
|
12
|
-
./spec/historiographer_spec.rb[1:2:3:2:3] | passed | 0.
|
13
|
-
./spec/historiographer_spec.rb[1:2:3:3:1] | passed | 0.
|
14
|
-
./spec/historiographer_spec.rb[1:2:3:3:2] | passed | 0.
|
15
|
-
./spec/historiographer_spec.rb[1:2:4:1] | passed | 0.
|
16
|
-
./spec/historiographer_spec.rb[1:2:4:2] | passed | 0.
|
17
|
-
./spec/historiographer_spec.rb[1:2:4:3] | passed | 0.
|
18
|
-
./spec/historiographer_spec.rb[1:2:5]
|
19
|
-
./spec/historiographer_spec.rb[1:2:
|
20
|
-
./spec/historiographer_spec.rb[1:2:
|
21
|
-
./spec/historiographer_spec.rb[1:
|
22
|
-
./spec/historiographer_spec.rb[1:
|
23
|
-
./spec/historiographer_spec.rb[1:
|
24
|
-
./spec/historiographer_spec.rb[1:
|
25
|
-
./spec/historiographer_spec.rb[1:
|
26
|
-
./spec/historiographer_spec.rb[1:
|
27
|
-
./spec/historiographer_spec.rb[1:
|
28
|
-
./spec/historiographer_spec.rb[1:
|
29
|
-
./spec/historiographer_spec.rb[1:
|
3
|
+
./spec/historiographer_spec.rb[1:1:1] | passed | 0.05541 seconds |
|
4
|
+
./spec/historiographer_spec.rb[1:1:2] | passed | 0.04942 seconds |
|
5
|
+
./spec/historiographer_spec.rb[1:1:3] | passed | 0.02648 seconds |
|
6
|
+
./spec/historiographer_spec.rb[1:2:1] | passed | 0.03832 seconds |
|
7
|
+
./spec/historiographer_spec.rb[1:2:2] | passed | 0.00076 seconds |
|
8
|
+
./spec/historiographer_spec.rb[1:2:3:1:1] | passed | 0.04672 seconds |
|
9
|
+
./spec/historiographer_spec.rb[1:2:3:1:2] | passed | 0.01971 seconds |
|
10
|
+
./spec/historiographer_spec.rb[1:2:3:2:1] | passed | 0.12226 seconds |
|
11
|
+
./spec/historiographer_spec.rb[1:2:3:2:2] | passed | 0.09424 seconds |
|
12
|
+
./spec/historiographer_spec.rb[1:2:3:2:3] | passed | 0.05644 seconds |
|
13
|
+
./spec/historiographer_spec.rb[1:2:3:3:1] | passed | 0.16536 seconds |
|
14
|
+
./spec/historiographer_spec.rb[1:2:3:3:2] | passed | 0.01638 seconds |
|
15
|
+
./spec/historiographer_spec.rb[1:2:4:1] | passed | 0.00552 seconds |
|
16
|
+
./spec/historiographer_spec.rb[1:2:4:2] | passed | 0.01095 seconds |
|
17
|
+
./spec/historiographer_spec.rb[1:2:4:3] | passed | 0.0022 seconds |
|
18
|
+
./spec/historiographer_spec.rb[1:2:5:1] | passed | 0.08367 seconds |
|
19
|
+
./spec/historiographer_spec.rb[1:2:5:2] | passed | 0.10781 seconds |
|
20
|
+
./spec/historiographer_spec.rb[1:2:5:3] | passed | 0.00516 seconds |
|
21
|
+
./spec/historiographer_spec.rb[1:2:6] | passed | 0.00482 seconds |
|
22
|
+
./spec/historiographer_spec.rb[1:2:7] | passed | 0.00642 seconds |
|
23
|
+
./spec/historiographer_spec.rb[1:2:8] | passed | 0.00926 seconds |
|
24
|
+
./spec/historiographer_spec.rb[1:3:1] | passed | 0.01607 seconds |
|
25
|
+
./spec/historiographer_spec.rb[1:4:1] | passed | 0.03777 seconds |
|
26
|
+
./spec/historiographer_spec.rb[1:5:1] | passed | 0.04254 seconds |
|
27
|
+
./spec/historiographer_spec.rb[1:5:2] | passed | 0.02652 seconds |
|
28
|
+
./spec/historiographer_spec.rb[1:6:1] | passed | 0.23851 seconds |
|
29
|
+
./spec/historiographer_spec.rb[1:6:2] | passed | 0.16412 seconds |
|
30
|
+
./spec/historiographer_spec.rb[1:7:1] | passed | 0.07495 seconds |
|
31
|
+
./spec/historiographer_spec.rb[1:8:1] | passed | 0.02917 seconds |
|
32
|
+
./spec/historiographer_spec.rb[1:9:1] | passed | 0.0228 seconds |
|
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
|
+
version: 4.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- brettshollenberger
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-08-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -287,7 +287,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
287
287
|
- !ruby/object:Gem::Version
|
288
288
|
version: '0'
|
289
289
|
requirements: []
|
290
|
-
rubygems_version: 3.2.
|
290
|
+
rubygems_version: 3.2.22
|
291
291
|
signing_key:
|
292
292
|
specification_version: 4
|
293
293
|
summary: Create histories of your ActiveRecord tables
|