Class: Recorder::Tape::Data

Inherits:
Object
  • Object
show all
Defined in:
lib/recorder/tape/data.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(item) ⇒ Data

Returns a new instance of Data.



8
9
10
# File 'lib/recorder/tape/data.rb', line 8

def initialize(item)
  @item = item
end

Instance Attribute Details

#itemObject (readonly)

Returns the value of attribute item.



6
7
8
# File 'lib/recorder/tape/data.rb', line 6

def item
  @item
end

Instance Method Details

#associations_for(event, options) ⇒ Object



34
35
36
37
38
# File 'lib/recorder/tape/data.rb', line 34

def associations_for(event, options)
  associations = parse_associations_attributes(event, options)

  associations.present? ? {associations: associations} : {}
end

#attributes_for(_event, options) ⇒ Object



20
21
22
# File 'lib/recorder/tape/data.rb', line 20

def attributes_for(_event, options)
  {attributes: sanitize_attributes(item.attributes, options)}
end

#changes_for(event, options) ⇒ Object



24
25
26
27
28
29
30
31
32
# File 'lib/recorder/tape/data.rb', line 24

def changes_for(event, options)
  changes =
    case event.to_sym
    when :update
      sanitize_attributes(item.saved_changes, options)
    end

  changes.present? ? {changes: changes} : {}
end

#data_for(event, options = {}) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/recorder/tape/data.rb', line 12

def data_for(event, options = {})
  {
    **attributes_for(event, options),
    **changes_for(event, options),
    **associations_for(event, options)
  }
end