Class: Recorder::Tape::Data
- Inherits:
-
Object
- Object
- Recorder::Tape::Data
- Defined in:
- lib/recorder/tape/data.rb
Instance Attribute Summary collapse
-
#item ⇒ Object
readonly
Returns the value of attribute item.
Instance Method Summary collapse
- #associations_for(event, options) ⇒ Object
- #attributes_for(_event, options) ⇒ Object
- #changes_for(event, options) ⇒ Object
- #data_for(event, options = {}) ⇒ Object
-
#initialize(item) ⇒ Data
constructor
A new instance of Data.
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
#item ⇒ Object (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, ) associations = parse_associations_attributes(event, ) 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, ) {attributes: sanitize_attributes(item.attributes, )} 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, ) changes = case event.to_sym when :update sanitize_attributes(item.saved_changes, ) 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, = {}) { **attributes_for(event, ), **changes_for(event, ), **associations_for(event, ) } end |