Class: Recorder::Tape
- Inherits:
-
Object
- Object
- Recorder::Tape
- Defined in:
- lib/recorder/tape.rb
Instance Attribute Summary collapse
-
#item ⇒ Object
readonly
Returns the value of attribute item.
Instance Method Summary collapse
- #changes_for(event) ⇒ Object
-
#initialize(item) ⇒ Tape
constructor
A new instance of Tape.
- #record_create ⇒ Object
- #record_destroy ⇒ Object
- #record_update ⇒ Object
Constructor Details
#initialize(item) ⇒ Tape
Returns a new instance of Tape.
5 6 7 8 9 |
# File 'lib/recorder/tape.rb', line 5 def initialize(item) @item = item; self.item.instance_variable_set(:@recorder_dirty, true) end |
Instance Attribute Details
#item ⇒ Object (readonly)
Returns the value of attribute item.
3 4 5 |
# File 'lib/recorder/tape.rb', line 3 def item @item end |
Instance Method Details
#changes_for(event) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/recorder/tape.rb', line 11 def changes_for(event) changes = case event.to_sym when :create self.sanitize_attributes(self.item.attributes) when :update self.sanitize_attributes(self.item.changes) when :destroy self.sanitize_attributes(self.item.changes) else raise ArgumentError end changes.any? ? { :changes => changes } : {} end |
#record_create ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/recorder/tape.rb', line 26 def record_create data = self.changes_for(:create) associations_attributes = self.parse_associations_attributes(:create) data.merge!(:associations => associations_attributes) if associations_attributes.present? if data.any? self.record( Recorder.store.merge({ :event => :create, :data => data }) ) end end |
#record_destroy ⇒ Object
58 59 |
# File 'lib/recorder/tape.rb', line 58 def record_destroy end |
#record_update ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/recorder/tape.rb', line 42 def record_update data = self.changes_for(:update) associations_attributes = self.parse_associations_attributes(:update) data.merge!(:associations => associations_attributes) if associations_attributes.present? if data.any? self.record( Recorder.store.merge({ :event => :update, :data => data }) ) end end |