historiographer 3.1.1 → 3.1.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d006e4c71b92e795f4f59b5acc12b9485a456ad145f420e270ec72e0d708971f
4
- data.tar.gz: 93fdc339e3a603b8d9c51aa22a51b911b2eb45f30e1b498b1c72854e4f99b6cd
3
+ metadata.gz: 51da7d8b48ed957be4d861ebc29d87cce064268091b882329b256037d0a81174
4
+ data.tar.gz: c8882522095c285fed79be3f1234487fecd7b8329f737f610100d5741a69775b
5
5
  SHA512:
6
- metadata.gz: 772f6e593fe7efd820cd26fb65a1e22142e1b968d74cb571989d4134723f0e6484f6fc46d2fd283e662e87377f9dc51204d697ca97212f751c0c073b51057f87
7
- data.tar.gz: d79129aaf645d28b53989a3576b9989ec93c8839a4b265e99dac5fa6ae199607b00eef4c4f9eb42c0851a52a07120df0eeb3bbf17fad83996910ff35d235503f
6
+ metadata.gz: 2a359fa0aab667e275f08f3b683da62e199413a6f4af26e45ebddcf78b86f10600df8797508bbb68e09a4b3dddbdcb0453af9aee1348cba0c58bee028b6d163e
7
+ data.tar.gz: b7672d46b9765f1b20ee630bd220dcd40712b5768da9a42e0062cdf922639d4c836ee5d4a96cf352c7da249670359ee81f0c8fbbd9d1a0279ebdbda0dc3b9c2f
data/VERSION CHANGED
@@ -1 +1 @@
1
- 3.1.1
1
+ 3.1.2
@@ -2,11 +2,11 @@
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 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.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]
@@ -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,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.merge!(foreign_key: klass.history_foreign_key) if klass.respond_to?(:history_foreign_key)
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 == "id" }.any?
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.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")
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["id"], history_started_at: now, history_user_id: history_user_id)
237
+ attrs.merge!(foreign_key => attrs['id'], history_started_at: now, history_user_id: history_user_id)
237
238
 
238
- attrs = attrs.except("id")
239
+ attrs = attrs.except('id')
239
240
 
240
- current_history = histories.where(history_ended_at: nil).order("id desc").limit(1).last
241
+ current_history = histories.where(history_ended_at: nil).order('id desc').limit(1).last
241
242
 
242
- unless foreign_key.present? && history_class.present?
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,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: historiographer
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.1
4
+ version: 3.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - brettshollenberger