Module: Footprintable::InstanceMethods

Defined in:
lib/footprintable/instance_methods.rb

Instance Method Summary collapse

Instance Method Details

#create_footprint(action) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/footprintable/instance_methods.rb', line 4

def create_footprint action
  attrs_changed = previous_changes
  return if attrs_changed.empty?
  attrs_changed = attrs_changed.except *self.class.footprint_options[:except]
  attrs_changed = attrs_changed.extract! *self.class.footprint_options[:extract] if self.class.footprint_options[:extract].present?

  attrs_before  = {}
  attrs_after = {}

  attrs_changed.each do |k, v|
    attrs_before.store(k, v.first) unless v.first.nil?
    attrs_after.store(k, v.last)  unless v.last.nil?
  end
  self.footprints.model.new(before: attrs_before, after: attrs_after, action: action, trackable: self, actorable: Current.actor).save(validate: false)
end