historiographer 3.1.0 → 3.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +1 -0
- data/Gemfile.lock +68 -0
- data/VERSION +1 -1
- data/historiographer.gemspec +5 -3
- data/lib/historiographer.rb +23 -23
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 51da7d8b48ed957be4d861ebc29d87cce064268091b882329b256037d0a81174
|
4
|
+
data.tar.gz: c8882522095c285fed79be3f1234487fecd7b8329f737f610100d5741a69775b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2a359fa0aab667e275f08f3b683da62e199413a6f4af26e45ebddcf78b86f10600df8797508bbb68e09a4b3dddbdcb0453af9aee1348cba0c58bee028b6d163e
|
7
|
+
data.tar.gz: b7672d46b9765f1b20ee630bd220dcd40712b5768da9a42e0062cdf922639d4c836ee5d4a96cf352c7da249670359ee81f0c8fbbd9d1a0279ebdbda0dc3b9c2f
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -18,6 +18,25 @@ GIT
|
|
18
18
|
GEM
|
19
19
|
remote: https://rubygems.org/
|
20
20
|
specs:
|
21
|
+
actioncable (6.1.4.4)
|
22
|
+
actionpack (= 6.1.4.4)
|
23
|
+
activesupport (= 6.1.4.4)
|
24
|
+
nio4r (~> 2.0)
|
25
|
+
websocket-driver (>= 0.6.1)
|
26
|
+
actionmailbox (6.1.4.4)
|
27
|
+
actionpack (= 6.1.4.4)
|
28
|
+
activejob (= 6.1.4.4)
|
29
|
+
activerecord (= 6.1.4.4)
|
30
|
+
activestorage (= 6.1.4.4)
|
31
|
+
activesupport (= 6.1.4.4)
|
32
|
+
mail (>= 2.7.1)
|
33
|
+
actionmailer (6.1.4.4)
|
34
|
+
actionpack (= 6.1.4.4)
|
35
|
+
actionview (= 6.1.4.4)
|
36
|
+
activejob (= 6.1.4.4)
|
37
|
+
activesupport (= 6.1.4.4)
|
38
|
+
mail (~> 2.5, >= 2.5.4)
|
39
|
+
rails-dom-testing (~> 2.0)
|
21
40
|
actionpack (6.1.4.4)
|
22
41
|
actionview (= 6.1.4.4)
|
23
42
|
activesupport (= 6.1.4.4)
|
@@ -25,12 +44,21 @@ GEM
|
|
25
44
|
rack-test (>= 0.6.3)
|
26
45
|
rails-dom-testing (~> 2.0)
|
27
46
|
rails-html-sanitizer (~> 1.0, >= 1.2.0)
|
47
|
+
actiontext (6.1.4.4)
|
48
|
+
actionpack (= 6.1.4.4)
|
49
|
+
activerecord (= 6.1.4.4)
|
50
|
+
activestorage (= 6.1.4.4)
|
51
|
+
activesupport (= 6.1.4.4)
|
52
|
+
nokogiri (>= 1.8.5)
|
28
53
|
actionview (6.1.4.4)
|
29
54
|
activesupport (= 6.1.4.4)
|
30
55
|
builder (~> 3.1)
|
31
56
|
erubi (~> 1.4)
|
32
57
|
rails-dom-testing (~> 2.0)
|
33
58
|
rails-html-sanitizer (~> 1.1, >= 1.2.0)
|
59
|
+
activejob (6.1.4.4)
|
60
|
+
activesupport (= 6.1.4.4)
|
61
|
+
globalid (>= 0.3.6)
|
34
62
|
activemodel (6.1.4.4)
|
35
63
|
activesupport (= 6.1.4.4)
|
36
64
|
activerecord (6.1.4.4)
|
@@ -38,6 +66,13 @@ GEM
|
|
38
66
|
activesupport (= 6.1.4.4)
|
39
67
|
activerecord-import (1.3.0)
|
40
68
|
activerecord (>= 4.2)
|
69
|
+
activestorage (6.1.4.4)
|
70
|
+
actionpack (= 6.1.4.4)
|
71
|
+
activejob (= 6.1.4.4)
|
72
|
+
activerecord (= 6.1.4.4)
|
73
|
+
activesupport (= 6.1.4.4)
|
74
|
+
marcel (~> 1.0.0)
|
75
|
+
mini_mime (>= 1.1.0)
|
41
76
|
activesupport (6.1.4.4)
|
42
77
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
43
78
|
i18n (>= 1.6, < 2)
|
@@ -78,6 +113,8 @@ GEM
|
|
78
113
|
hashie (>= 3.4)
|
79
114
|
mime-types (>= 1.16, < 3.0)
|
80
115
|
oauth2 (~> 1.0)
|
116
|
+
globalid (1.0.0)
|
117
|
+
activesupport (>= 5.0)
|
81
118
|
guard (2.18.0)
|
82
119
|
formatador (>= 0.2.4)
|
83
120
|
listen (>= 2.7, < 4.0)
|
@@ -105,8 +142,12 @@ GEM
|
|
105
142
|
crass (~> 1.0.2)
|
106
143
|
nokogiri (>= 1.5.9)
|
107
144
|
lumberjack (1.2.8)
|
145
|
+
mail (2.7.1)
|
146
|
+
mini_mime (>= 0.1.1)
|
147
|
+
marcel (1.0.2)
|
108
148
|
method_source (1.0.0)
|
109
149
|
mime-types (2.99.3)
|
150
|
+
mini_mime (1.1.2)
|
110
151
|
mini_portile2 (2.8.0)
|
111
152
|
minitest (5.16.3)
|
112
153
|
multi_json (1.15.0)
|
@@ -114,6 +155,7 @@ GEM
|
|
114
155
|
multipart-post (2.2.3)
|
115
156
|
mysql2 (0.5.0)
|
116
157
|
nenv (0.3.0)
|
158
|
+
nio4r (2.5.8)
|
117
159
|
nokogiri (1.13.8)
|
118
160
|
mini_portile2 (~> 2.8.0)
|
119
161
|
racc (~> 1.4)
|
@@ -138,6 +180,21 @@ GEM
|
|
138
180
|
rack (2.2.4)
|
139
181
|
rack-test (1.1.0)
|
140
182
|
rack (>= 1.0, < 3)
|
183
|
+
rails (6.1.4.4)
|
184
|
+
actioncable (= 6.1.4.4)
|
185
|
+
actionmailbox (= 6.1.4.4)
|
186
|
+
actionmailer (= 6.1.4.4)
|
187
|
+
actionpack (= 6.1.4.4)
|
188
|
+
actiontext (= 6.1.4.4)
|
189
|
+
actionview (= 6.1.4.4)
|
190
|
+
activejob (= 6.1.4.4)
|
191
|
+
activemodel (= 6.1.4.4)
|
192
|
+
activerecord (= 6.1.4.4)
|
193
|
+
activestorage (= 6.1.4.4)
|
194
|
+
activesupport (= 6.1.4.4)
|
195
|
+
bundler (>= 1.15.0)
|
196
|
+
railties (= 6.1.4.4)
|
197
|
+
sprockets-rails (>= 2.0.0)
|
141
198
|
rails-dom-testing (2.0.3)
|
142
199
|
activesupport (>= 4.2.0)
|
143
200
|
nokogiri (>= 1.6)
|
@@ -178,6 +235,13 @@ GEM
|
|
178
235
|
simplecov_json_formatter (~> 0.1)
|
179
236
|
simplecov-html (0.12.3)
|
180
237
|
simplecov_json_formatter (0.1.3)
|
238
|
+
sprockets (4.1.1)
|
239
|
+
concurrent-ruby (~> 1.0)
|
240
|
+
rack (> 1, < 3)
|
241
|
+
sprockets-rails (3.4.2)
|
242
|
+
actionpack (>= 5.2)
|
243
|
+
activesupport (>= 5.2)
|
244
|
+
sprockets (>= 3.0.0)
|
181
245
|
standalone_migrations (6.1.0)
|
182
246
|
activerecord (>= 4.2.7, < 6.2.0, != 5.2.3.rc1, != 5.2.3)
|
183
247
|
railties (>= 4.2.7, < 6.2.0, != 5.2.3.rc1, != 5.2.3)
|
@@ -188,6 +252,9 @@ GEM
|
|
188
252
|
timecop (0.9.4)
|
189
253
|
tzinfo (2.0.5)
|
190
254
|
concurrent-ruby (~> 1.0)
|
255
|
+
websocket-driver (0.7.5)
|
256
|
+
websocket-extensions (>= 0.1.0)
|
257
|
+
websocket-extensions (0.1.5)
|
191
258
|
zeitwerk (2.6.1)
|
192
259
|
|
193
260
|
PLATFORMS
|
@@ -207,6 +274,7 @@ DEPENDENCIES
|
|
207
274
|
paranoia
|
208
275
|
pg
|
209
276
|
pry
|
277
|
+
rails (>= 6)
|
210
278
|
rdoc (~> 3.12)
|
211
279
|
rollbar
|
212
280
|
rspec
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
3.1.
|
1
|
+
3.1.2
|
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 3.1.
|
5
|
+
# stub: historiographer 3.1.2 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "historiographer".freeze
|
9
|
-
s.version = "3.1.
|
9
|
+
s.version = "3.1.2"
|
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 = "2022-10-
|
14
|
+
s.date = "2022-10-19"
|
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 = [
|
@@ -73,6 +73,7 @@ Gem::Specification.new do |s|
|
|
73
73
|
s.add_runtime_dependency(%q<activerecord>.freeze, [">= 6"])
|
74
74
|
s.add_runtime_dependency(%q<activerecord-import>.freeze, [">= 0"])
|
75
75
|
s.add_runtime_dependency(%q<activesupport>.freeze, [">= 0"])
|
76
|
+
s.add_runtime_dependency(%q<rails>.freeze, [">= 6"])
|
76
77
|
s.add_runtime_dependency(%q<rollbar>.freeze, [">= 0"])
|
77
78
|
s.add_development_dependency(%q<mysql2>.freeze, ["= 0.5"])
|
78
79
|
s.add_development_dependency(%q<paranoia>.freeze, [">= 0"])
|
@@ -88,6 +89,7 @@ Gem::Specification.new do |s|
|
|
88
89
|
s.add_dependency(%q<activerecord>.freeze, [">= 6"])
|
89
90
|
s.add_dependency(%q<activerecord-import>.freeze, [">= 0"])
|
90
91
|
s.add_dependency(%q<activesupport>.freeze, [">= 0"])
|
92
|
+
s.add_dependency(%q<rails>.freeze, [">= 6"])
|
91
93
|
s.add_dependency(%q<rollbar>.freeze, [">= 0"])
|
92
94
|
s.add_dependency(%q<mysql2>.freeze, ["= 0.5"])
|
93
95
|
s.add_dependency(%q<paranoia>.freeze, [">= 0"])
|
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,7 +173,7 @@ 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
|
176
|
+
opts[:foreign_key] = klass.history_foreign_key if klass.respond_to?(:history_foreign_key)
|
174
177
|
has_many :histories, opts
|
175
178
|
has_one :current_history, -> { current }, opts
|
176
179
|
end
|
@@ -187,14 +190,12 @@ module Historiographer
|
|
187
190
|
module UpdateColumnsWithHistory
|
188
191
|
def update_columns(*args)
|
189
192
|
opts = args.extract_options!
|
190
|
-
any_changes = opts.keys.reject { |k| k ==
|
193
|
+
any_changes = opts.keys.reject { |k| k == 'id' }.any?
|
191
194
|
|
192
195
|
transaction do
|
193
196
|
persisted = super(opts)
|
194
197
|
|
195
|
-
if any_changes && persisted
|
196
|
-
record_history
|
197
|
-
end
|
198
|
+
record_history if any_changes && persisted
|
198
199
|
end
|
199
200
|
end
|
200
201
|
end
|
@@ -216,7 +217,7 @@ module Historiographer
|
|
216
217
|
private
|
217
218
|
|
218
219
|
def history_user_absent_action
|
219
|
-
raise HistoryUserIdMissingError
|
220
|
+
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
221
|
end
|
221
222
|
|
222
223
|
#
|
@@ -233,23 +234,22 @@ module Historiographer
|
|
233
234
|
foreign_key = history_class.history_foreign_key
|
234
235
|
|
235
236
|
now = UTC.now
|
236
|
-
attrs.merge!(foreign_key => attrs[
|
237
|
+
attrs.merge!(foreign_key => attrs['id'], history_started_at: now, history_user_id: history_user_id)
|
237
238
|
|
238
|
-
attrs = attrs.except(
|
239
|
+
attrs = attrs.except('id')
|
239
240
|
|
240
|
-
current_history = histories.where(history_ended_at: nil).order(
|
241
|
+
current_history = histories.where(history_ended_at: nil).order('id desc').limit(1).last
|
241
242
|
|
242
|
-
|
243
|
-
raise "Need foreign key and history class to save history!"
|
244
|
-
else
|
243
|
+
if foreign_key.present? && history_class.present?
|
245
244
|
history_class.create!(attrs)
|
246
245
|
current_history.update!(history_ended_at: now) if current_history.present?
|
246
|
+
else
|
247
|
+
raise 'Need foreign key and history class to save history!'
|
247
248
|
end
|
248
249
|
end
|
249
250
|
end
|
250
251
|
|
251
252
|
class_methods do
|
252
|
-
|
253
253
|
#
|
254
254
|
# E.g. SponsoredProductCampaign => SponsoredProductCampaignHistory
|
255
255
|
#
|
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: 3.1.
|
4
|
+
version: 3.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- brettshollenberger
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-10-
|
11
|
+
date: 2022-10-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rails
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '6'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '6'
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
70
|
name: rollbar
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|