Class: PaperTrailDiff::ActivityBoundary
- Inherits:
-
Object
- Object
- PaperTrailDiff::ActivityBoundary
- Defined in:
- lib/paper_trail_diff/activity_boundary.rb,
sig/generated/paper_trail_diff/activity_boundary.rbs
Overview
Immutable metadata identifying one historical or current activity boundary.
Instance Attribute Summary collapse
- #event ⇒ String? readonly
- #item_id ⇒ Object readonly
- #item_type ⇒ String readonly
- #kind ⇒ Symbol readonly
- #record ⇒ RecordReference readonly
- #recorded_at ⇒ Object readonly
-
#transaction_id ⇒ Object
readonly
The transaction the version was written in, when PaperTrail recorded one.
- #version_id ⇒ Object readonly
- #whodunnit ⇒ Object readonly
Class Method Summary collapse
-
.current(record, captured_at:) ⇒ ActivityBoundary
: (untyped, captured_at: untyped) -> ActivityBoundary.
-
.destroyed(version) ⇒ ActivityBoundary
The state a
destroyversion leaves behind. -
.from_version(version) ⇒ ActivityBoundary
: (untyped) -> ActivityBoundary.
-
.transaction_id(version) ⇒ Object
A custom version class need not carry the column, and PaperTrail leaves it nil outside a transaction.
Instance Method Summary collapse
-
#current? ⇒ Boolean
: () -> bool.
-
#destroyed? ⇒ Boolean
: () -> bool.
-
#initialize(kind:, version_id:, item_type:, item_id:, recorded_at:, event: nil, whodunnit: nil, transaction_id: nil) ⇒ ActivityBoundary
constructor
: (kind: Symbol, version_id: untyped, item_type: untyped, item_id: untyped, recorded_at: untyped, ?event: untyped, ?whodunnit: untyped, ?transaction_id: untyped) -> void.
-
#to_h ⇒ Hash[Symbol, untyped]
: () -> Hash[Symbol, untyped].
-
#version? ⇒ Boolean
: () -> bool.
Constructor Details
#initialize(kind:, version_id:, item_type:, item_id:, recorded_at:, event: nil, whodunnit: nil, transaction_id: nil) ⇒ ActivityBoundary
: (kind: Symbol, version_id: untyped, item_type: untyped, item_id: untyped, recorded_at: untyped, ?event: untyped, ?whodunnit: untyped, ?transaction_id: untyped) -> void
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/paper_trail_diff/activity_boundary.rb', line 73 def initialize( # rubocop:disable Metrics/ParameterLists kind:, version_id:, item_type:, item_id:, recorded_at:, event: nil, whodunnit: nil, transaction_id: nil ) @kind = kind @version_id = Support.immutable_copy(version_id) @item_type = Support.immutable_copy(item_type.to_s) @item_id = Support.immutable_copy(item_id) @recorded_at = Support.immutable_copy(recorded_at) @event = Support.immutable_copy(event&.to_s) @whodunnit = Support.immutable_copy(whodunnit) @transaction_id = Support.immutable_copy(transaction_id) @record = RecordReference.new(type: @item_type, id: @item_id) freeze end |
Instance Attribute Details
#event ⇒ String? (readonly)
12 13 14 |
# File 'lib/paper_trail_diff/activity_boundary.rb', line 12 def event @event end |
#item_id ⇒ Object (readonly)
10 11 12 |
# File 'lib/paper_trail_diff/activity_boundary.rb', line 10 def item_id @item_id end |
#item_type ⇒ String (readonly)
9 10 11 |
# File 'lib/paper_trail_diff/activity_boundary.rb', line 9 def item_type @item_type end |
#kind ⇒ Symbol (readonly)
7 8 9 |
# File 'lib/paper_trail_diff/activity_boundary.rb', line 7 def kind @kind end |
#record ⇒ RecordReference (readonly)
14 15 16 |
# File 'lib/paper_trail_diff/activity_boundary.rb', line 14 def record @record end |
#recorded_at ⇒ Object (readonly)
11 12 13 |
# File 'lib/paper_trail_diff/activity_boundary.rb', line 11 def recorded_at @recorded_at end |
#transaction_id ⇒ Object (readonly)
The transaction the version was written in, when PaperTrail recorded one. Several versions saved together share it, which is what lets a timeline report one save as one step rather than as its parts.
18 19 20 |
# File 'lib/paper_trail_diff/activity_boundary.rb', line 18 def transaction_id @transaction_id end |
#version_id ⇒ Object (readonly)
8 9 10 |
# File 'lib/paper_trail_diff/activity_boundary.rb', line 8 def version_id @version_id end |
#whodunnit ⇒ Object (readonly)
13 14 15 |
# File 'lib/paper_trail_diff/activity_boundary.rb', line 13 def whodunnit @whodunnit end |
Class Method Details
.current(record, captured_at:) ⇒ ActivityBoundary
: (untyped, captured_at: untyped) -> ActivityBoundary
36 37 38 39 40 41 42 43 44 |
# File 'lib/paper_trail_diff/activity_boundary.rb', line 36 def current(record, captured_at:) new( kind: :current, version_id: nil, item_type: record.class.base_class.name, item_id: record.id, recorded_at: captured_at ) end |
.destroyed(version) ⇒ ActivityBoundary
The state a destroy version leaves behind. A version records the state
before its own event, so the boundary built from a destroy version still
holds the record; this one is the absence that follows it.
: (untyped) -> ActivityBoundary
50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/paper_trail_diff/activity_boundary.rb', line 50 def destroyed(version) new( kind: :destroyed, version_id: version.id, item_type: version.item_type, item_id: version.item_id, recorded_at: version.created_at, event: version.event, whodunnit: version.whodunnit, transaction_id: transaction_id(version) ) end |
.from_version(version) ⇒ ActivityBoundary
: (untyped) -> ActivityBoundary
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/paper_trail_diff/activity_boundary.rb', line 22 def from_version(version) new( kind: :version, version_id: version.id, item_type: version.item_type, item_id: version.item_id, recorded_at: version.created_at, event: version.event, whodunnit: version.whodunnit, transaction_id: transaction_id(version) ) end |
.transaction_id(version) ⇒ Object
A custom version class need not carry the column, and PaperTrail leaves it nil outside a transaction. Both read as "no transaction here", which groups with nothing. : (untyped) -> untyped
67 68 69 |
# File 'lib/paper_trail_diff/activity_boundary.rb', line 67 def transaction_id(version) version.transaction_id if version.respond_to?(:transaction_id) end |
Instance Method Details
#current? ⇒ Boolean
: () -> bool
101 102 103 |
# File 'lib/paper_trail_diff/activity_boundary.rb', line 101 def current? kind == :current end |
#destroyed? ⇒ Boolean
: () -> bool
106 107 108 |
# File 'lib/paper_trail_diff/activity_boundary.rb', line 106 def destroyed? kind == :destroyed end |
#to_h ⇒ Hash[Symbol, untyped]
: () -> Hash[Symbol, untyped]
111 112 113 114 115 116 117 118 119 |
# File 'lib/paper_trail_diff/activity_boundary.rb', line 111 def to_h { kind: kind, version_id: version_id, item_type: item_type, item_id: item_id, recorded_at: recorded_at } end |
#version? ⇒ Boolean
: () -> bool
96 97 98 |
# File 'lib/paper_trail_diff/activity_boundary.rb', line 96 def version? kind == :version end |