Class: PaperTrailDiff::RecordReference
- Inherits:
-
Object
- Object
- PaperTrailDiff::RecordReference
- Defined in:
- lib/paper_trail_diff/snapshot.rb,
sig/generated/paper_trail_diff/snapshot.rbs
Overview
Immutable identity shared by snapshots and stable-record changes.
Instance Attribute Summary collapse
- #id ⇒ Object readonly
- #type ⇒ String readonly
Instance Method Summary collapse
-
#[](key) ⇒ Object
: (reference_key) -> untyped.
-
#fetch(key) ⇒ Object
: (reference_key) -> untyped.
-
#initialize(type:, id:) ⇒ RecordReference
constructor
: (type: String, id: untyped) -> void.
-
#to_h ⇒ Hash[Symbol, untyped]
: () -> Hash[Symbol, untyped].
Constructor Details
#initialize(type:, id:) ⇒ RecordReference
: (type: String, id: untyped) -> void
11 12 13 14 15 |
# File 'lib/paper_trail_diff/snapshot.rb', line 11 def initialize(type:, id:) @type = Support.immutable_copy(type.to_s) @id = Support.immutable_copy(id) freeze end |
Instance Attribute Details
#id ⇒ Object (readonly)
8 9 10 |
# File 'lib/paper_trail_diff/snapshot.rb', line 8 def id @id end |
#type ⇒ String (readonly)
7 8 9 |
# File 'lib/paper_trail_diff/snapshot.rb', line 7 def type @type end |
Instance Method Details
#[](key) ⇒ Object
: (reference_key) -> untyped
18 19 20 21 22 23 |
# File 'lib/paper_trail_diff/snapshot.rb', line 18 def [](key) case key.to_s when 'type' then type when 'id' then id end end |
#fetch(key) ⇒ Object
: (reference_key) -> untyped
26 27 28 29 30 31 |
# File 'lib/paper_trail_diff/snapshot.rb', line 26 def fetch(key) value = self[key] return value if %w[type id].include?(key.to_s) raise KeyError, "key not found: #{key.inspect}" end |
#to_h ⇒ Hash[Symbol, untyped]
: () -> Hash[Symbol, untyped]
34 35 36 |
# File 'lib/paper_trail_diff/snapshot.rb', line 34 def to_h { type: type, id: id } end |