Class: Recorder::Tape

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#itemObject (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_createObject



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_destroyObject



58
59
# File 'lib/recorder/tape.rb', line 58

def record_destroy
end

#record_updateObject



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