historiographer 1.0.2 → 1.1.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/README.md +2 -2
- data/VERSION +1 -1
- data/historiographer.gemspec +3 -3
- data/lib/historiographer.rb +25 -7
- data/lib/historiographer/history.rb +2 -3
- data/spec/historiographer_spec.rb +19 -4
- 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: 433e733811c7f23a3044282b54c87832abc944e3f46817d16036c87778f938ff
|
4
|
+
data.tar.gz: 54e27e8e68ab4512bb5edf146d1c210f9072ad99346d8a1ced37e6766d014d3b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1abd0b29fc36c284fb6e8c5da6c884640678ce0dd9b58c089b15056897514f7cd47b8d4117e54b3549d306be6ce0a08c36f772724bc741fd09cf782a174c0415
|
7
|
+
data.tar.gz: c63eecd58ea1b7ad604d3cf049735b2fed3bdd403aa2c508190a3907b6dfcaf7ecb6094b9ac14bf2fb0d5574e8277a0c2b05ef06d25a8291bfbc3306c419decb
|
data/README.md
CHANGED
@@ -85,7 +85,7 @@ Additionally it will add indices on:
|
|
85
85
|
The primary model should include `Historiographer`:
|
86
86
|
|
87
87
|
```ruby
|
88
|
-
class Post
|
88
|
+
class Post < ActiveRecord::Base
|
89
89
|
include Historiographer
|
90
90
|
end
|
91
91
|
```
|
@@ -93,7 +93,7 @@ end
|
|
93
93
|
You should also make a `PostHistory` class if you're going to query `PostHistory` from Rails:
|
94
94
|
|
95
95
|
```ruby
|
96
|
-
class PostHistory
|
96
|
+
class PostHistory < ActiveRecord::Base
|
97
97
|
end
|
98
98
|
```
|
99
99
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.0
|
1
|
+
1.1.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 1.0
|
5
|
+
# stub: historiographer 1.1.0 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "historiographer".freeze
|
9
|
-
s.version = "1.0
|
9
|
+
s.version = "1.1.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 = "2019-
|
14
|
+
s.date = "2019-10-11"
|
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 = [
|
data/lib/historiographer.rb
CHANGED
@@ -89,6 +89,22 @@ module Historiographer
|
|
89
89
|
end
|
90
90
|
end
|
91
91
|
|
92
|
+
alias_method :destroy_without_history, :destroy
|
93
|
+
def destroy_with_history(history_user_id: )
|
94
|
+
current_history = histories.where(history_ended_at: nil).order("id desc").limit(1).last
|
95
|
+
current_history.update!(history_ended_at: UTC.now) if current_history.present?
|
96
|
+
|
97
|
+
if respond_to?(:paranoia_destroy)
|
98
|
+
self.history_user_id = history_user_id
|
99
|
+
paranoia_destroy
|
100
|
+
else
|
101
|
+
@no_history = true
|
102
|
+
destroy_without_history
|
103
|
+
@no_history = false
|
104
|
+
end
|
105
|
+
end
|
106
|
+
alias_method :destroy, :destroy_with_history
|
107
|
+
|
92
108
|
def assign_attributes(new_attributes)
|
93
109
|
huid = new_attributes[:history_user_id]
|
94
110
|
|
@@ -133,13 +149,6 @@ module Historiographer
|
|
133
149
|
|
134
150
|
class_name = "#{base.name}History"
|
135
151
|
|
136
|
-
if base.respond_to?(:histories)
|
137
|
-
raise "#{base} already has histories. Talk to Brett if this is a legit use case."
|
138
|
-
else
|
139
|
-
has_many :histories, class_name: class_name
|
140
|
-
has_one :current_history, -> { current }, class_name: class_name
|
141
|
-
end
|
142
|
-
|
143
152
|
begin
|
144
153
|
class_name.constantize
|
145
154
|
rescue
|
@@ -151,6 +160,15 @@ module Historiographer
|
|
151
160
|
|
152
161
|
klass = class_name.constantize
|
153
162
|
|
163
|
+
if base.respond_to?(:histories)
|
164
|
+
raise "#{base} already has histories. Talk to Brett if this is a legit use case."
|
165
|
+
else
|
166
|
+
opts = { class_name: class_name }
|
167
|
+
opts.merge!(foreign_key: klass.history_foreign_key) if klass.respond_to?(:history_foreign_key)
|
168
|
+
has_many :histories, opts
|
169
|
+
has_one :current_history, -> { current }, opts
|
170
|
+
end
|
171
|
+
|
154
172
|
klass.send(:include, Historiographer::History) unless klass.ancestors.include?(Historiographer::History)
|
155
173
|
|
156
174
|
#
|
@@ -61,7 +61,6 @@ module Historiographer
|
|
61
61
|
extend ActiveSupport::Concern
|
62
62
|
|
63
63
|
included do |base|
|
64
|
-
|
65
64
|
#
|
66
65
|
# A History class (e.g. RetailerProductHistory) will gain
|
67
66
|
# access to a current scope, returning
|
@@ -93,7 +92,7 @@ module Historiographer
|
|
93
92
|
# "RetailerProductHistory."
|
94
93
|
#
|
95
94
|
foreign_class_name = base.name.gsub(/History$/) {} # e.g. "RetailerProductHistory" => "RetailerProduct"
|
96
|
-
association_name = foreign_class_name.underscore.to_sym # e.g. "RetailerProduct"
|
95
|
+
association_name = foreign_class_name.split("::").last.underscore.to_sym # e.g. "RetailerProduct" => :retailer_product
|
97
96
|
|
98
97
|
#
|
99
98
|
# Historiographer will automatically setup the association
|
@@ -172,4 +171,4 @@ module Historiographer
|
|
172
171
|
end
|
173
172
|
end
|
174
173
|
end
|
175
|
-
end
|
174
|
+
end
|
@@ -266,15 +266,30 @@ describe Historiographer do
|
|
266
266
|
end
|
267
267
|
|
268
268
|
describe "Deletion" do
|
269
|
-
it "records deleted_at on primary and history if you use acts_as_paranoid" do
|
269
|
+
it "records deleted_at and history_user_id on primary and history if you use acts_as_paranoid" do
|
270
|
+
post = create_post
|
271
|
+
|
272
|
+
expect {
|
273
|
+
post.destroy(history_user_id: 2)
|
274
|
+
}.to_not change {
|
275
|
+
PostHistory.count
|
276
|
+
}
|
277
|
+
|
278
|
+
expect(PostHistory.last.history_ended_at).to_not be_nil
|
279
|
+
expect(PostHistory.last.deleted_at).to be_nil
|
270
280
|
class Post
|
271
281
|
acts_as_paranoid
|
272
282
|
end
|
273
283
|
|
274
|
-
post =
|
284
|
+
post = Post.create(
|
285
|
+
title: "Post 1",
|
286
|
+
body: "Great post",
|
287
|
+
author_id: 1,
|
288
|
+
history_user_id: user.id
|
289
|
+
)
|
275
290
|
|
276
291
|
expect {
|
277
|
-
post.destroy
|
292
|
+
post.destroy(history_user_id: 2)
|
278
293
|
}.to change {
|
279
294
|
PostHistory.count
|
280
295
|
}.by 1
|
@@ -282,7 +297,7 @@ describe Historiographer do
|
|
282
297
|
expect(Post.unscoped.where.not(deleted_at: nil).count).to eq 1
|
283
298
|
expect(Post.unscoped.where(deleted_at: nil).count).to eq 0
|
284
299
|
expect(PostHistory.where.not(deleted_at: nil).count).to eq 1
|
285
|
-
expect(PostHistory.
|
300
|
+
expect(PostHistory.last.history_user_id).to eq 2
|
286
301
|
end
|
287
302
|
end
|
288
303
|
|
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: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- brettshollenberger
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-10-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|