historiographer 3.1.1 → 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d006e4c71b92e795f4f59b5acc12b9485a456ad145f420e270ec72e0d708971f
4
- data.tar.gz: 93fdc339e3a603b8d9c51aa22a51b911b2eb45f30e1b498b1c72854e4f99b6cd
3
+ metadata.gz: f16398b9f6b0a3d58501a2115eabca0e0f93a938d04eeb4c21d3713f9b70079a
4
+ data.tar.gz: a460ef65372e236b001225b1028837eb7ba107e8d45d958c39d003be0cd64db4
5
5
  SHA512:
6
- metadata.gz: 772f6e593fe7efd820cd26fb65a1e22142e1b968d74cb571989d4134723f0e6484f6fc46d2fd283e662e87377f9dc51204d697ca97212f751c0c073b51057f87
7
- data.tar.gz: d79129aaf645d28b53989a3576b9989ec93c8839a4b265e99dac5fa6ae199607b00eef4c4f9eb42c0851a52a07120df0eeb3bbf17fad83996910ff35d235503f
6
+ metadata.gz: 3b545edcfe0076f0e83f5478347a9298fce77118d7274ad39ce8304844637b7ee15980e66c02dff36321eda4e36b0defdb10b6c33cc7486fba47e780043e5f42
7
+ data.tar.gz: f828cf26cc357fb0b3e2750bfcc1f62dc628c1579f1fa3356062f34314545783bb6ecb80366e4ac9d6988eae8374168afeb0d29c166daa9dbd7c860074494de4
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.6.3
1
+ 3.0.2
data/Gemfile CHANGED
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  source 'https://rubygems.org'
4
- ruby '2.6.3'
4
+ ruby '3.0.2'
5
5
 
6
6
  gem 'activerecord', '>= 6'
7
7
  gem 'activerecord-import'
data/Gemfile.lock CHANGED
@@ -283,7 +283,7 @@ DEPENDENCIES
283
283
  timecop
284
284
 
285
285
  RUBY VERSION
286
- ruby 2.6.3p62
286
+ ruby 3.0.2p107
287
287
 
288
288
  BUNDLED WITH
289
289
  1.17.3
data/VERSION CHANGED
@@ -1 +1 @@
1
- 3.1.1
1
+ 4.0.0
@@ -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.1 ruby lib
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 = "3.1.1"
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 = "2022-10-19"
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.23".freeze
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
- send(column.type, column.name, opts.symbolize_keys!)
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
@@ -1,8 +1,11 @@
1
- require "active_support/all"
2
- require_relative "./historiographer/history"
3
- require_relative "./historiographer/postgres_migration"
4
- require_relative "./historiographer/safe"
5
- require_relative "./historiographer/relation"
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("UTC").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, "must be an integer")
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("id desc").limit(1).last
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 "Unsupported Rails version"
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.merge!(foreign_key: klass.history_foreign_key) if klass.respond_to?(:history_foreign_key)
174
- has_many :histories, opts
175
- has_one :current_history, -> { current }, opts
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 == "id" }.any?
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.new("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")
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["id"], history_started_at: now, history_user_id: history_user_id)
242
+ attrs.merge!(foreign_key => attrs['id'], history_started_at: now, history_user_id: history_user_id)
237
243
 
238
- attrs = attrs.except("id")
244
+ attrs = attrs.except('id')
239
245
 
240
- current_history = histories.where(history_ended_at: nil).order("id desc").limit(1).last
246
+ current_history = histories.where(history_ended_at: nil).order('id desc').limit(1).last
241
247
 
242
- unless foreign_key.present? && history_class.present?
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.00973 seconds |
4
- ./spec/historiographer_spec.rb[1:1:2] | passed | 0.01848 seconds |
5
- ./spec/historiographer_spec.rb[1:1:3] | passed | 0.0092 seconds |
6
- ./spec/historiographer_spec.rb[1:2:1] | passed | 0.02492 seconds |
7
- ./spec/historiographer_spec.rb[1:2:2] | passed | 0.00099 seconds |
8
- ./spec/historiographer_spec.rb[1:2:3:1:1] | passed | 0.13892 seconds |
9
- ./spec/historiographer_spec.rb[1:2:3:1:2] | passed | 0.1202 seconds |
10
- ./spec/historiographer_spec.rb[1:2:3:2:1] | passed | 0.02734 seconds |
11
- ./spec/historiographer_spec.rb[1:2:3:2:2] | passed | 0.04699 seconds |
12
- ./spec/historiographer_spec.rb[1:2:3:2:3] | passed | 0.02185 seconds |
13
- ./spec/historiographer_spec.rb[1:2:3:3:1] | passed | 0.08042 seconds |
14
- ./spec/historiographer_spec.rb[1:2:3:3:2] | passed | 0.02825 seconds |
15
- ./spec/historiographer_spec.rb[1:2:4:1] | passed | 0.02411 seconds |
16
- ./spec/historiographer_spec.rb[1:2:4:2] | passed | 0.01286 seconds |
17
- ./spec/historiographer_spec.rb[1:2:4:3] | passed | 0.00469 seconds |
18
- ./spec/historiographer_spec.rb[1:2:5] | passed | 0.00478 seconds |
19
- ./spec/historiographer_spec.rb[1:2:6] | passed | 0.0035 seconds |
20
- ./spec/historiographer_spec.rb[1:2:7] | passed | 0.01157 seconds |
21
- ./spec/historiographer_spec.rb[1:3:1] | passed | 0.09042 seconds |
22
- ./spec/historiographer_spec.rb[1:4:1] | passed | 0.05553 seconds |
23
- ./spec/historiographer_spec.rb[1:5:1] | passed | 0.0104 seconds |
24
- ./spec/historiographer_spec.rb[1:5:2] | passed | 0.00905 seconds |
25
- ./spec/historiographer_spec.rb[1:6:1] | passed | 0.02652 seconds |
26
- ./spec/historiographer_spec.rb[1:6:2] | passed | 0.04419 seconds |
27
- ./spec/historiographer_spec.rb[1:7:1] | passed | 0.02102 seconds |
28
- ./spec/historiographer_spec.rb[1:8:1] | passed | 0.02556 seconds |
29
- ./spec/historiographer_spec.rb[1:9:1] | passed | 0.01444 seconds |
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: 3.1.1
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: 2022-10-19 00:00:00.000000000 Z
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.23
290
+ rubygems_version: 3.2.22
291
291
  signing_key:
292
292
  specification_version: 4
293
293
  summary: Create histories of your ActiveRecord tables