module Thoth::Rails::Model

Public Class Methods

included(base) click to toggle source
# File lib/thoth/rails/model.rb, line 4
def self.included(base)
  base.send :extend, ClassMethods
end

Public Instance Methods

changes_to_log() click to toggle source
# File lib/thoth/rails/model.rb, line 54
def changes_to_log
  has_changes_to_save? ? changes_to_save : saved_changes
end
thoth_log_create() click to toggle source
# File lib/thoth/rails/model.rb, line 25
def thoth_log_create
  return unless self.class.thoth_options[:on].include?(:create)
  thoth_log_model(:create)
end
thoth_log_destroy() click to toggle source
# File lib/thoth/rails/model.rb, line 45
def thoth_log_destroy
  return unless self.class.thoth_options[:on].include?(:destroy)
  thoth_log_model(:destroy)
end
thoth_log_model(action) click to toggle source
# File lib/thoth/rails/model.rb, line 50
def thoth_log_model(action)
  Thoth.logger.log("#{self.class.name} #{action}", changes: changes_to_log, attributes: attributes)
end
thoth_log_update() click to toggle source
# File lib/thoth/rails/model.rb, line 30
def thoth_log_update
  return unless self.class.thoth_options[:on].include?(:update)

  except_options = self.class.thoth_options[:except]
  only_options = if except_options.present?
    self.class.columns.map(&:name) - except_options.map(&:to_s)
  else
    self.class.thoth_options[:only]
  end

  if only_options.empty? || !(only_options.map(&:to_s) & changed_attribute_names_to_save).empty?
    thoth_log_model(:update)
  end
end