paper_trail_scrapbook 0.1.8 → 0.1.9

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
- SHA1:
3
- metadata.gz: 97a2bf7b57ccb17e58774b1577cc82a3d1abca21
4
- data.tar.gz: d889470556b4800a03da9f22100f21c05436f8e9
2
+ SHA256:
3
+ metadata.gz: 67563a25cc478a45dfcc0a63311ecec0b38db5c5e8ce3d50977e5eaf3f30ac36
4
+ data.tar.gz: 78c1e866535132c11e9e98a606ef739e973f5ed4db0a878db6ae5bf150e67c68
5
5
  SHA512:
6
- metadata.gz: 6ef3a6c2be07485324519923b9696035e72a81f5bfc37721eb1763e28f443ffc8e4da968acc2fcef1ee2be5b30d00bf1426c6cc2eeb01ab03687b2585946a6bd
7
- data.tar.gz: cd1d28c3ceac1e739735659dc907310ce4b90328ced4396eb4999b05efbef6b32ae9dc52f6b3a70358cbbe8b019de7dd7dd35b046b0a4c7a7d2acbb3db47e067
6
+ metadata.gz: fe2c6468ec05d4f1f4996a248667ac8ec7c7b3d15921df851dc9266c3ff45566e15569f9f64ebc868bef95a798fb049c33e7363a090ef05158409cc0eafa7cc1
7
+ data.tar.gz: 2eb5f79927a5e60ccaad7accd97c6eaca0afc0fa51fe4075c63a5b42d4f424a645ba531c6ebabdc558faeef126b5799269e1ef76a30d50265c67a0fbc9b64c87
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- paper_trail_scrapbook (0.1.8)
4
+ paper_trail_scrapbook (0.1.9)
5
5
  activerecord (>= 4.0, < 5.2)
6
6
  adamantium
7
7
  concord
@@ -98,11 +98,13 @@ GEM
98
98
  mutant-rspec (0.8.14)
99
99
  mutant (~> 0.8.14)
100
100
  rspec-core (>= 3.4.0, < 3.7.0)
101
- nokogiri (1.8.2)
101
+ nokogiri (1.8.4)
102
102
  mini_portile2 (~> 2.3.0)
103
- paper_trail (9.0.0)
103
+ paper_trail (9.2.0)
104
104
  activerecord (>= 4.2, < 5.3)
105
+ paper_trail-association_tracking (< 2)
105
106
  request_store (~> 1.1)
107
+ paper_trail-association_tracking (1.0.0)
106
108
  parallel (1.12.1)
107
109
  parser (2.4.0.2)
108
110
  ast (~> 2.3)
@@ -115,8 +117,8 @@ GEM
115
117
  rails-dom-testing (2.0.3)
116
118
  activesupport (>= 4.2.0)
117
119
  nokogiri (>= 1.6)
118
- rails-html-sanitizer (1.0.3)
119
- loofah (~> 2.0)
120
+ rails-html-sanitizer (1.0.4)
121
+ loofah (~> 2.2, >= 2.2.2)
120
122
  railties (5.1.4)
121
123
  actionpack (= 5.1.4)
122
124
  activesupport (= 5.1.4)
data/README.md CHANGED
@@ -69,6 +69,52 @@ text = PaperTrailScrapbook::LifeHistory.new(widget).story
69
69
  # • discounted_price: 29612.0
70
70
  ```
71
71
 
72
+ If desired, you can implement a `trailed_related_content` method in your model
73
+ that returns a collection of related objects to include in the history.
74
+
75
+ The following would, for example, cause version information for the `attachments` and `manufacturer` to be included when viewing the life story of a `Widget`:
76
+
77
+ ```ruby
78
+ class Widget < ApplicationRecord
79
+ has_paper_trail
80
+
81
+ def trailed_related_content
82
+ attachments | [manufacturer]
83
+ end
84
+
85
+ has_many :attachments
86
+ has_one :manufacturer
87
+ end
88
+ ```
89
+
90
+ A history leveraging this feature might look like this:
91
+
92
+ ```ruby
93
+ widget = Widget.find 42
94
+
95
+ text = PaperTrailScrapbook::LifeHistory.new(widget).story
96
+
97
+ # On Monday, 05 Jun 2017 at 12:37 PM, Rob Owens created the following Manufacturer[411] information:
98
+ # • email: widgetsrus@example.com
99
+ # • name: WidgetsAreUs
100
+ # •: 411
101
+ #
102
+ # On Wednesday, 07 Jun 2017 at 2:37 PM, Rob Owens created the following Widget information:
103
+ # • email: Tim@example.com
104
+ # • name: Tim's Widget
105
+ # • manufacturer: WidgetsAreUs[411]
106
+ # •: 1234
107
+ #
108
+ # On Thursday, 23 Oct 2017 at 7:55 AM PDT, Rob Owens updated Manufacturer[411]:
109
+ # • name: WidgetsRUs
110
+ #
111
+ # On Friday, 24 Oct 2017 at 10:10 AM PDT, Rob Owens created the following Attachment[212] information:
112
+ # • name: Electromagnet
113
+ # • widget: Tim's Widget[1234]
114
+ # •: 212
115
+ #
116
+ ```
117
+
72
118
  ### User Journal
73
119
 
74
120
  The `UserJournal` module provides a list of changes made by a particular
@@ -79,7 +125,7 @@ who = WhoDidIt.find 42
79
125
  text = PaperTrailScrapbook::UserJournal.new(who).story
80
126
  # Between Wednesday, 31 Dec 1969 at 4:00 PM PST and Friday, 26 Jan 2018 at 10:35 AM PST, Rob Owens made the following changes:
81
127
  #
82
- # On Wednesday, 07 Jan 2018 at 2:37 PM, Rob Owens created the following Widget information:
128
+ # On Wednesday, 07 Jan 2018 at 2:37 PM, created the following Widget information:
83
129
  # • email: Tim@example.com
84
130
  # • name: Tim's Widget
85
131
  # • built: true
@@ -107,7 +153,7 @@ You can also scope the change list to a specific class:
107
153
  text = PaperTrailScrapbook::UserJournal.new(who, klass: Widget).story
108
154
  # Between Wednesday, 31 Dec 1969 at 4:00 PM PST and Friday, 26 Jan 2018 at 10:35 AM PST, Rob Owens made the following Widget changes:
109
155
  #
110
- # On Wednesday, 07 Jan 2018 at 2:37 PM, Rob Owens created Widget[123]:
156
+ # On Wednesday, 07 Jan 2018 at 2:37 PM, created Widget[123]:
111
157
  # • email: Tim@example.com
112
158
  # • name: Tim's Widget
113
159
  # • built: true
@@ -123,7 +169,7 @@ Or view changes in a time range:
123
169
  text = PaperTrailScrapbook::UserJournal.new(who, start: 1.month.ago, end: Time.now).story
124
170
  # Between Tuesday, 26 Dec 2017 at 4:00 PM PST and Friday, 26 Jan 2018 at 4:00 PM PST, Rob Owens made the following changes:
125
171
  #
126
- # On Wednesday, 07 Jan 2018 at 2:37 PM, Rob Owens created the following Widget information:
172
+ # On Wednesday, 07 Jan 2018 at 2:37 PM, created the following Widget information:
127
173
  # • email: Tim@example.com
128
174
  # • name: Tim's Widget
129
175
  # • built: true
data/circle.yml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  machine:
3
3
  ruby:
4
- version: '2.2.7'
4
+ version: '2.3.0'
5
5
  environment:
6
6
  CC_TEST_REPORTER_ID: e0db6fd6beb8208980b2908947735982fb5a4e8a9a3cb742dc194e00df79f388
7
7
 
@@ -16,15 +16,29 @@ module PaperTrailScrapbook
16
16
  #
17
17
  def story
18
18
  updates = changes
19
- return unless create? || updates.present? || !config.filter_non_changes
19
+ return unless tell_story?(updates)
20
20
 
21
- "#{preface}\n#{updates}"
21
+ [preface, (updates unless destroy?)].compact.join("\n")
22
22
  end
23
23
 
24
24
  private
25
25
 
26
26
  def preface
27
- "On #{whenn}, #{who} #{kind} the following #{model} info:".squeeze(' ')
27
+ "On #{whenn}, #{who} #{kind} #{what}".squeeze(' ')
28
+ end
29
+
30
+ def what
31
+ if destroy?
32
+ "#{model}#{item_id}"
33
+ else
34
+ "the following #{model}#{item_id} info:"
35
+ end
36
+ end
37
+
38
+ def item_id; end
39
+
40
+ def tell_story?(updates)
41
+ create? || destroy? || updates.present? || !config.filter_non_changes
28
42
  end
29
43
  end
30
44
  end
@@ -5,7 +5,15 @@ module PaperTrailScrapbook
5
5
  #
6
6
  class LifeHistory
7
7
  def initialize(object)
8
+ @object = object
8
9
  @versions = object.versions
10
+ if object.respond_to?(:trailed_related_content)
11
+ object.trailed_related_content.compact.each do |trc|
12
+ @versions |= trc.versions
13
+ end
14
+ end
15
+
16
+ @versions = @versions.sort_by(&:created_at)
9
17
  end
10
18
 
11
19
  # Retries textual historical analysis of versions
@@ -14,12 +22,21 @@ module PaperTrailScrapbook
14
22
  #
15
23
  def story
16
24
  versions.map do |v|
17
- Chapter.new(v).story
25
+ if primary?(v)
26
+ Chapter
27
+ else
28
+ SecondaryChapter
29
+ end.new(v).story
18
30
  end.compact.join("\n\n")
19
31
  end
20
32
 
21
33
  private
22
34
 
23
- attr_reader :versions
35
+ def primary?(version)
36
+ version.item_type.eql?(object.class.name) &&
37
+ version.item_id.equal?(object.id)
38
+ end
39
+
40
+ attr_reader :object, :versions
24
41
  end
25
42
  end
@@ -0,0 +1,12 @@
1
+ module PaperTrailScrapbook
2
+ # Class SecondaryChapter provides single version history analysis for data
3
+ # related to the main subject
4
+ #
5
+ class SecondaryChapter < Chapter
6
+ private
7
+
8
+ def item_id
9
+ "[#{model_id}]"
10
+ end
11
+ end
12
+ end
@@ -1,4 +1,4 @@
1
1
  module PaperTrailScrapbook
2
2
  # Current version
3
- VERSION = '0.1.8'.freeze
3
+ VERSION = '0.1.9'.freeze
4
4
  end
@@ -16,6 +16,10 @@ module PaperTrailScrapbook
16
16
  event.eql?('create')
17
17
  end
18
18
 
19
+ def destroy?
20
+ event.eql?('destroy')
21
+ end
22
+
19
23
  def changes
20
24
  Changes.new(version).change_log
21
25
  end
@@ -8,6 +8,7 @@ require 'paper_trail_scrapbook/chapter'
8
8
  require 'paper_trail_scrapbook/changes'
9
9
  require 'paper_trail_scrapbook/journal_entry'
10
10
  require 'paper_trail_scrapbook/life_history'
11
+ require 'paper_trail_scrapbook/secondary_chapter'
11
12
  require 'paper_trail_scrapbook/user_journal'
12
13
  require 'paper_trail_scrapbook/version'
13
14
  require 'paper_trail_scrapbook/version_helpers'
@@ -50,7 +50,14 @@ module PaperTrailScrapbook
50
50
 
51
51
  describe '#story' do
52
52
  it 'provides a whole story' do
53
+ expect(subject).to match(/updated the following Widget info/)
54
+ expect(subject).to match(/email: tim@redbox.com added/)
55
+ expect(subject).to match(/name: Tim Chambers added/)
56
+ expect(subject).to match(/sent: false -> true/)
57
+ expect(subject).to match(/created by: \d+ added/)
58
+ expect(subject).to match(/amount: 29612.0 added/)
53
59
  expect(subject).to match(/discounted amount: 29612.0 added/)
60
+ expect(subject).to match(/status: active -> issued/)
54
61
  end
55
62
  end
56
63
  end
@@ -87,12 +87,37 @@ module PaperTrailScrapbook
87
87
  end
88
88
 
89
89
  context 'no papertrail' do
90
- let(:target) {Elephant.create!}
90
+ let(:target) { Elephant.create! }
91
+
91
92
  it 'has none' do
92
93
  target
93
94
  expect(subject).to eql ''
94
95
  end
95
96
  end
97
+
98
+ context 'with related data' do
99
+ before do
100
+ author
101
+ book
102
+ target
103
+
104
+ def target.trailed_related_content
105
+ [book, author]
106
+ end
107
+ end
108
+
109
+ it 'includes related content history' do
110
+ expect(subject).to match(/created the following Person\[\d+\] info/)
111
+ expect(subject).to match(/name: Dr\. Seuss/)
112
+
113
+ expect(subject).to match(/created the following Book\[\d+\] info/)
114
+ expect(subject).to match(/title: How the Grinch stole Xmas/)
115
+
116
+ expect(subject).to match(/created the following Authorship info/)
117
+ expect(subject).to match(/book: How the Grinch stole Xmas\[\d+\]/)
118
+ expect(subject).to match(/author: Dr\. Seuss\[\d+\]/)
119
+ end
120
+ end
96
121
  end
97
122
  end
98
123
  end
@@ -0,0 +1,64 @@
1
+ require 'spec_helper'
2
+
3
+ module PaperTrailScrapbook
4
+ ::RSpec.describe SecondaryChapter do
5
+ let(:version) do
6
+ OpenStruct.new(id: 2_674_798,
7
+ item_type: 'Widget',
8
+ item_id: 4804,
9
+ event: 'update',
10
+ whodunnit: '1742',
11
+ object: ['---',
12
+ 'id: ',
13
+ 'discounted_amount: '].join("\n"),
14
+ created_at: Time.current,
15
+ object_changes: ['---',
16
+ 'email:',
17
+ '- ',
18
+ '- tim@redbox.com',
19
+ 'name:',
20
+ '- ',
21
+ '- Tim Chambers',
22
+ 'sent:',
23
+ '- false',
24
+ '- true',
25
+ 'created_by:',
26
+ '- ',
27
+ '- 1742',
28
+ 'amount:',
29
+ '- ',
30
+ '- 29612.0',
31
+ 'discounted_amount:',
32
+ '- ',
33
+ '- !ruby/object:BigDecimal 36:0.29612E5',
34
+ 'created_at:',
35
+ '- ',
36
+ '- &1 2017-06-07 21:37:02.188657104 Z',
37
+ 'updated_at:',
38
+ '- ',
39
+ '- *1',
40
+ 'id:',
41
+ '- ',
42
+ '- 4806',
43
+ 'status:',
44
+ '- active',
45
+ '- issued'].join("\n"))
46
+ end
47
+
48
+ let(:object) { described_class.new(version) }
49
+ let(:subject) { object.story }
50
+
51
+ describe '#story' do
52
+ it 'provides a whole story' do
53
+ expect(subject).to match(/updated the following Widget\[\d+\] info/)
54
+ expect(subject).to match(/email: tim@redbox.com added/)
55
+ expect(subject).to match(/name: Tim Chambers added/)
56
+ expect(subject).to match(/sent: false -> true/)
57
+ expect(subject).to match(/created by: \d+ added/)
58
+ expect(subject).to match(/amount: 29612.0 added/)
59
+ expect(subject).to match(/discounted amount: 29612.0 added/)
60
+ expect(subject).to match(/status: active -> issued/)
61
+ end
62
+ end
63
+ end
64
+ 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.8
4
+ version: 0.1.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Timothy Chambers
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-04-13 00:00:00.000000000 Z
11
+ date: 2018-07-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -299,6 +299,7 @@ files:
299
299
  - lib/paper_trail_scrapbook/config.rb
300
300
  - lib/paper_trail_scrapbook/journal_entry.rb
301
301
  - lib/paper_trail_scrapbook/life_history.rb
302
+ - lib/paper_trail_scrapbook/secondary_chapter.rb
302
303
  - lib/paper_trail_scrapbook/user_journal.rb
303
304
  - lib/paper_trail_scrapbook/version.rb
304
305
  - lib/paper_trail_scrapbook/version_helpers.rb
@@ -382,6 +383,7 @@ files:
382
383
  - spec/paper_trail_scrapbook/chapter_spec.rb
383
384
  - spec/paper_trail_scrapbook/config_spec.rb
384
385
  - spec/paper_trail_scrapbook/life_history_spec.rb
386
+ - spec/paper_trail_scrapbook/secondary_chapter_spec.rb
385
387
  - spec/paper_trail_scrapbook/user_journal_spec.rb
386
388
  - spec/paper_trail_scrapbook/version_helpers_spec.rb
387
389
  - spec/paper_trail_scrapbook/version_spec.rb
@@ -407,7 +409,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
407
409
  version: 1.3.6
408
410
  requirements: []
409
411
  rubyforge_project:
410
- rubygems_version: 2.5.1
412
+ rubygems_version: 2.7.6
411
413
  signing_key:
412
414
  specification_version: 4
413
415
  summary: Paper Trail Scrapbook