Class: Diffit::Record

Inherits:
Object
  • Object
show all
Defined in:
lib/diffit/record.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#changesObject (readonly)

Returns the value of attribute changes.



4
5
6
# File 'lib/diffit/record.rb', line 4

def changes
  @changes
end

#modelObject (readonly)

Returns the value of attribute model.



4
5
6
# File 'lib/diffit/record.rb', line 4

def model
  @model
end

#record_idObject (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_atTime

Timestamp of the latest change.

Returns:

  • (Time)

    latest change timestamp.



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_hHash

A Hash representation of self.

Returns:

  • (Hash)

    the object converted to hash.



22
23
24
# File 'lib/diffit/record.rb', line 22

def to_h
  {model: model, record_id: record_id, changes: changes}
end