paper_trail_scrapbook 0.1.18 → 0.1.19

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
- SHA256:
3
- metadata.gz: aa47cf69ac7a2144dc53b73398b15ca2de056a755288b8d046dff1b5a81f72ac
4
- data.tar.gz: d3287790361e5a2ebca3faec7898f242593658386fcff8edb682e5b61680681c
2
+ SHA1:
3
+ metadata.gz: edc42760ad65ddabf5e4b5cbe6078a2106e05fd3
4
+ data.tar.gz: f414b720536a35971713cd2ab6615665861be9f0
5
5
  SHA512:
6
- metadata.gz: 5f160146eca7e32aa5f1bad9251db38b9a25f58f404c0b02f70526a450a86e294983e1bd5a9be3903cceb76d1d5e6746d0dfef941fa59bd6931c1059581114d7
7
- data.tar.gz: c1af014f91175252110e50459bc33f594ff4a5d1edfd738ea7502f83ed8d9e7c79d70081fb7ac0cd003ea4779bece333628e714712232834149949897ec7967e
6
+ metadata.gz: db255b9d214220f0161e76d0cc748b5a315be057fded74adfbaa4b79aa58403791196283381074050d0a3cb3fcc49b667ee57662268f6835c47b5b651c8f75cc
7
+ data.tar.gz: f05cfe2ca064ace2658641863635d640bf425cee52d5c57b9a14f51f63d849e2572f06b056468f175be867056a51891b95fab38545dc38974d1543cf7e2e42f9
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- paper_trail_scrapbook (0.1.18)
4
+ paper_trail_scrapbook (0.1.19)
5
5
  activerecord
6
6
  adamantium
7
7
  concord
@@ -61,7 +61,7 @@ GEM
61
61
  i18n (1.7.0)
62
62
  concurrent-ruby (~> 1.0)
63
63
  ice_nine (0.11.2)
64
- json (2.1.0)
64
+ json (2.3.1)
65
65
  loofah (2.3.1)
66
66
  crass (~> 1.0.2)
67
67
  nokogiri (>= 1.5.9)
@@ -109,7 +109,7 @@ GEM
109
109
  pg (0.18.4)
110
110
  powerpack (0.1.1)
111
111
  procto (0.0.3)
112
- rack (2.0.8)
112
+ rack (2.2.3)
113
113
  rack-test (1.1.0)
114
114
  rack (>= 1.0, < 3)
115
115
  rails-dom-testing (2.0.3)
@@ -180,6 +180,7 @@ GEM
180
180
 
181
181
  PLATFORMS
182
182
  ruby
183
+ x86_64-darwin-20
183
184
 
184
185
  DEPENDENCIES
185
186
  codeclimate-test-reporter (~> 1.0.7)
@@ -202,4 +203,4 @@ DEPENDENCIES
202
203
  timecop (~> 0.8.0)
203
204
 
204
205
  BUNDLED WITH
205
- 2.1.4
206
+ 2.2.2
data/README.md CHANGED
@@ -16,7 +16,7 @@ Add PaperTrailScrapBook to your `Gemfile`.
16
16
  ### Configuration
17
17
 
18
18
  This gem is dependent on [PaperTrail](https://github.com/paper-trail-gem/paper_trail),
19
- and specifically, on the `object_changes` column in the `PaperTrail::Version`
19
+ and specifically, on the `object_changes` column in the `PaperTrail::Version`
20
20
  table. If your `PaperTrail` installation does not include this column, you can
21
21
  add it manually, or re-run the `PaperTrail` generator:
22
22
 
@@ -78,12 +78,12 @@ widget = Widget.find 42
78
78
  text = PaperTrailScrapbook::LifeHistory.new(widget).story
79
79
  # On Wednesday, 07 Jun 2017 at 2:37 PM, Rob Owens created the following Widget information:
80
80
  # • email: Tim@example.com
81
- # • name: Tim's Widget
81
+ # • name: Tim's Widget
82
82
  # • built: true
83
83
  # • created_by: Rob Owens[1742]
84
84
  # • provider: RedCharge[3113]
85
85
  # • cost: 29612.0
86
- # • discounted_price: 29612.0
86
+ # • discounted_price: 29612.0
87
87
  ```
88
88
 
89
89
  If desired, you can implement a `trailed_related_content` method in your model
@@ -118,18 +118,64 @@ text = PaperTrailScrapbook::LifeHistory.new(widget).story
118
118
  #
119
119
  # On Wednesday, 07 Jun 2017 at 2:37 PM, Rob Owens created the following Widget information:
120
120
  # • email: Tim@example.com
121
- # • name: Tim's Widget
121
+ # • name: Tim's Widget
122
122
  # • manufacturer: WidgetsAreUs[411]
123
123
  # •: 1234
124
- #
124
+ #
125
125
  # On Thursday, 23 Oct 2017 at 7:55 AM PDT, Rob Owens updated Manufacturer[411]:
126
126
  # • name: WidgetsRUs
127
- #
127
+ #
128
128
  # On Friday, 24 Oct 2017 at 10:10 AM PDT, Rob Owens created the following Attachment[212] information:
129
129
  # • name: Electromagnet
130
130
  # • widget: Tim's Widget[1234]
131
131
  # •: 212
132
- #
132
+ #
133
+ ```
134
+
135
+ `PaperTrailScrapbook` also implements a `version_filter` hook to provide a flexible way to filter which versions appear in a object's history. For example, if we only wanted our `Widget` class to include history for its manufacturer after the widget was created, we might implement `Widget#version_filter` like this:
136
+
137
+ ```ruby
138
+ class Widget < ApplicationRecord
139
+ has_paper_trail
140
+
141
+ def trailed_related_content
142
+ attachments | [manufacturer]
143
+ end
144
+
145
+ def version_filter(version)
146
+ case version.item_type
147
+ when 'Manufacturer'
148
+ if version.created_at < created_at
149
+ return nil
150
+ end
151
+ end
152
+ version
153
+ end
154
+
155
+ ...
156
+ ```
157
+
158
+ Then, the above history would be:
159
+
160
+ ```ruby
161
+ widget = Widget.find 42
162
+
163
+ text = PaperTrailScrapbook::LifeHistory.new(widget).story
164
+
165
+ # On Wednesday, 07 Jun 2017 at 2:37 PM, Rob Owens created the following Widget information:
166
+ # • email: Tim@example.com
167
+ # • name: Tim's Widget
168
+ # • manufacturer: WidgetsAreUs[411]
169
+ # •: 1234
170
+ #
171
+ # On Thursday, 23 Oct 2017 at 7:55 AM PDT, Rob Owens updated Manufacturer[411]:
172
+ # • name: WidgetsRUs
173
+ #
174
+ # On Friday, 24 Oct 2017 at 10:10 AM PDT, Rob Owens created the following Attachment[212] information:
175
+ # • name: Electromagnet
176
+ # • widget: Tim's Widget[1234]
177
+ # •: 212
178
+ #
133
179
  ```
134
180
 
135
181
  ### User Journal
@@ -8,14 +8,7 @@ module PaperTrailScrapbook
8
8
  class LifeHistory
9
9
  def initialize(object)
10
10
  @object = object
11
- @versions = object.versions
12
- if object.respond_to?(:trailed_related_content)
13
- object.trailed_related_content.compact.each do |trc|
14
- @versions |= trc.versions
15
- end
16
- end
17
-
18
- @versions = @versions.sort_by(&:created_at)
11
+ @versions = Versions.new(object).versions
19
12
  end
20
13
 
21
14
  # Retries textual historical analysis of versions
@@ -2,5 +2,5 @@
2
2
 
3
3
  module PaperTrailScrapbook
4
4
  # Current version
5
- VERSION = '0.1.18'
5
+ VERSION = '0.1.19'
6
6
  end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PaperTrailScrapbook
4
+ class Versions
5
+ include Concord.new(:object)
6
+
7
+ def versions
8
+ filtered(object.versions | related_content).sort_by(&:created_at)
9
+ end
10
+
11
+ def related_content
12
+ unless object.respond_to?(:trailed_related_content)
13
+ return []
14
+ end
15
+
16
+ object.trailed_related_content.compact.flat_map(&:versions)
17
+ end
18
+
19
+ def filtered(object_versions)
20
+ unless object.respond_to?(:version_filter)
21
+ return object_versions
22
+ end
23
+
24
+ object_versions.select { |v| object.version_filter(v) }
25
+ end
26
+
27
+ end
28
+
29
+ end
@@ -0,0 +1,95 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+ require 'paper_trail_scrapbook/versions'
5
+
6
+ module PaperTrailScrapbook
7
+ ::RSpec.describe Versions do
8
+ before do
9
+ PaperTrailScrapbook.config.whodunnit_class = Person
10
+ PaperTrail.request.whodunnit = person.id
11
+ end
12
+
13
+ let(:book) do
14
+ Book.new(title: 'How the Grinch stole Xmas').tap(&:save!)
15
+ end
16
+ let(:person) { Person.create(name: 'The Tim Man') }
17
+ let!(:authorship) do
18
+ Authorship.new(book: book, author: person).tap(&:save!)
19
+ end
20
+
21
+ let(:object) { described_class.new(book) }
22
+
23
+ describe '#versions' do
24
+ it 'versions' do
25
+ book.update!(title: 'New Title')
26
+
27
+ result = object.versions
28
+
29
+ expect(result).to eql(book.versions.to_a)
30
+ expect(result.size).to equal(2)
31
+ end
32
+ end
33
+
34
+ describe '#related_content' do
35
+ it 'related_content returns nothing if no related content' do
36
+ result = object.related_content
37
+
38
+ expect(result).to eql([])
39
+ end
40
+
41
+ it 'returns related content' do
42
+ allow(book).to receive(:respond_to?)
43
+ .with(:trailed_related_content).and_return(true)
44
+ allow(book).to receive(:respond_to?)
45
+ .with(:trailed_related_content, true).and_return(true)
46
+ allow(book).to receive(:trailed_related_content) do
47
+ book.authorships
48
+ end
49
+
50
+ result = object.related_content
51
+
52
+ expect(result).to eql(authorship.versions.to_a)
53
+ end
54
+ end
55
+
56
+ describe '#filtered' do
57
+ it 'returns versions if no filter' do
58
+ result = object.filtered(book.versions.to_a)
59
+
60
+ expect(result).to eql(book.versions.to_a)
61
+ end
62
+
63
+ it 'returns filtered versions if filter' do
64
+ allow(book).to receive(:respond_to?)
65
+ .with(:version_filter, true).and_return(true)
66
+ allow(book).to receive(:respond_to?)
67
+ .with(:version_filter).and_return(true)
68
+ allow(book).to receive(:version_filter) do |_version|
69
+ nil
70
+ end
71
+
72
+ result = object.filtered(book.versions.to_a)
73
+
74
+ expect(result).to eql([])
75
+ end
76
+
77
+ it 'returns filtered versions if filter' do
78
+ book.update!(title: 'New Title')
79
+
80
+ allow(book).to receive(:respond_to?).with(:version_filter, true).and_return(true)
81
+ allow(book).to receive(:respond_to?).with(:version_filter).and_return(true)
82
+ allow(book).to receive(:version_filter) do |version|
83
+ if version.event.eql?('update')
84
+ version
85
+ end
86
+ end
87
+
88
+ result = object.filtered(book.versions)
89
+
90
+ expect(result).to eql([book.versions.last])
91
+ expect(result.size).not_to eql(book.versions.size)
92
+ end
93
+ end
94
+ end
95
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: paper_trail_scrapbook
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.18
4
+ version: 0.1.19
5
5
  platform: ruby
6
6
  authors:
7
7
  - Timothy Chambers
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-03-06 00:00:00.000000000 Z
11
+ date: 2020-12-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -340,6 +340,7 @@ files:
340
340
  - lib/paper_trail_scrapbook/user_journal.rb
341
341
  - lib/paper_trail_scrapbook/version.rb
342
342
  - lib/paper_trail_scrapbook/version_helpers.rb
343
+ - lib/paper_trail_scrapbook/versions.rb
343
344
  - log/mutant/pts.log
344
345
  - paper_trail_scrapbook.gemspec
345
346
  - pkg/paper_trail_scrapbook-0.0.2.gem
@@ -425,13 +426,14 @@ files:
425
426
  - spec/paper_trail_scrapbook/user_journal_spec.rb
426
427
  - spec/paper_trail_scrapbook/version_helpers_spec.rb
427
428
  - spec/paper_trail_scrapbook/version_spec.rb
429
+ - spec/paper_trail_scrapbook/versions_spec.rb
428
430
  - spec/paper_trail_scrapbook_spec.rb
429
431
  - spec/spec_helper.rb
430
432
  homepage: https://github.com/hintmedia/paper_trail_scrapbook
431
433
  licenses:
432
434
  - MIT
433
435
  metadata: {}
434
- post_install_message:
436
+ post_install_message:
435
437
  rdoc_options: []
436
438
  require_paths:
437
439
  - lib
@@ -446,8 +448,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
446
448
  - !ruby/object:Gem::Version
447
449
  version: 1.3.6
448
450
  requirements: []
449
- rubygems_version: 3.1.2
450
- signing_key:
451
+ rubyforge_project:
452
+ rubygems_version: 2.5.2.3
453
+ signing_key:
451
454
  specification_version: 4
452
455
  summary: Paper Trail Scrapbook
453
456
  test_files: []