Class: Diffit::Record
- Inherits:
-
Object
- Object
- Diffit::Record
- Defined in:
- lib/diffit/record.rb
Instance Attribute Summary collapse
-
#changes ⇒ Object
readonly
Returns the value of attribute changes.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#record_id ⇒ Object
readonly
Returns the value of attribute record_id.
Instance Method Summary collapse
-
#initialize(model, record_id, changes) ⇒ Record
constructor
A new instance of Record.
-
#last_changed_at ⇒ Time
Timestamp of the latest change.
-
#to_h ⇒ Hash
A
Hashrepresentation ofself.
Constructor Details
#initialize(model, record_id, changes) ⇒ Record
Returns a new instance of Record.
6 7 8 9 10 |
# File 'lib/diffit/record.rb', line 6 def initialize(model, record_id, changes) @model = model @record_id = record_id @changes = changes end |
Instance Attribute Details
#changes ⇒ Object (readonly)
Returns the value of attribute changes.
4 5 6 |
# File 'lib/diffit/record.rb', line 4 def changes @changes end |
#model ⇒ Object (readonly)
Returns the value of attribute model.
4 5 6 |
# File 'lib/diffit/record.rb', line 4 def model @model end |
#record_id ⇒ Object (readonly)
Returns the value of attribute record_id.
4 5 6 |
# File 'lib/diffit/record.rb', line 4 def record_id @record_id end |
Instance Method Details
#last_changed_at ⇒ Time
Timestamp of the latest change.
15 16 17 |
# File 'lib/diffit/record.rb', line 15 def last_changed_at @last_changed_at ||= @changes.map { |c| c[:changed_at] }.max end |
#to_h ⇒ Hash
A Hash representation of self.
22 23 24 |
# File 'lib/diffit/record.rb', line 22 def to_h {model: model, record_id: record_id, changes: changes} end |