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
- #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.
Instance Method Summary collapse
-
#current? ⇒ Boolean
: () -> bool.
-
#destroyed? ⇒ Boolean
: () -> bool.
-
#initialize(kind:, version_id:, item_type:, item_id:, recorded_at:, event: nil, whodunnit: nil) ⇒ ActivityBoundary
constructor
: (kind: Symbol, version_id: untyped, item_type: untyped, item_id: untyped, recorded_at: untyped, ?event: untyped, ?whodunnit: 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) ⇒ ActivityBoundary
: (kind: Symbol, version_id: untyped, item_type: untyped, item_id: untyped, recorded_at: untyped, ?event: untyped, ?whodunnit: untyped) -> void
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/paper_trail_diff/activity_boundary.rb', line 59 def initialize( # rubocop:disable Metrics/ParameterLists kind:, version_id:, item_type:, item_id:, recorded_at:, event: nil, whodunnit: 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) @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 |
#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
31 32 33 34 35 36 37 38 39 |
# File 'lib/paper_trail_diff/activity_boundary.rb', line 31 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
45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/paper_trail_diff/activity_boundary.rb', line 45 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 ) end |
.from_version(version) ⇒ ActivityBoundary
: (untyped) -> ActivityBoundary
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/paper_trail_diff/activity_boundary.rb', line 18 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 ) end |
Instance Method Details
#current? ⇒ Boolean
: () -> bool
85 86 87 |
# File 'lib/paper_trail_diff/activity_boundary.rb', line 85 def current? kind == :current end |
#destroyed? ⇒ Boolean
: () -> bool
90 91 92 |
# File 'lib/paper_trail_diff/activity_boundary.rb', line 90 def destroyed? kind == :destroyed end |
#to_h ⇒ Hash[Symbol, untyped]
: () -> Hash[Symbol, untyped]
95 96 97 98 99 100 101 102 103 |
# File 'lib/paper_trail_diff/activity_boundary.rb', line 95 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
80 81 82 |
# File 'lib/paper_trail_diff/activity_boundary.rb', line 80 def version? kind == :version end |