module Tracer::Changes::ClassMethods

Public Instance Methods

log_record_changes(options = {}) click to toggle source
# File lib/tracer_client/changes.rb, line 12
def log_record_changes(options = {})
  send :include, InstanceMethods

  class_attribute :changes_logging_options
  self.changes_logging_options = options.dup

  %i(ignore skip only).each do |k|
    changes_logging_options[k] =
        [changes_logging_options[k]].flatten.compact.map { |attr| attr.is_a?(Hash) ? attr.stringify_keys : attr.to_s }
  end

  options_on = Array.wrap(options[:on]) # so that a single symbol can be passed in without wrapping it in an `Array`

  after_create  :log_create, :if => :log_changes? if options_on.empty? || options_on.include?(:create)

  if options_on.empty? || options_on.include?(:update)
    before_update :log_update, :if => :log_changes?
  end

  after_destroy :log_destroy, :if => :log_changes? if options_on.empty? || options_on.include?(:destroy)
end