module EffectiveLogging class ActiveRecordLogger attr_accessor :object, :resource, :options BLANK = "''" BLACKLIST = [:updated_at, :created_at, :encrypted_password, :status_steps, :wizard_steps] # Don't log changes or attributes # to, prefix, only, except def initialize(object, args = {}) @object = object @resource = Effective::Resource.new(object) # Validate changes_to value if args[:to].present? && !@resource.belong_tos.map(&:name).include?(args[:to]) raise ArgumentError.new("unable to find existing belongs_to relationship matching #{args[:to]}. Expected a symbol matching a belongs_to.") end @options = { to: args[:to], prefix: args[:prefix], only: args[:only], except: Array(args[:except]) + BLACKLIST }.compact end # Effective::Log.where(message: 'Deleted').where('details ILIKE ?', '%lab_test_id: 263%') def destroyed! log('Deleted', resource_attributes) end def created! log('Created', resource_attributes) end def updated! changes = resource_changes return true if changes.blank? # If you just click save and change nothing, don't log it. message = (['Updated'] + changes.map do |attribute, (before, after)| before = "HTML content (#{before.length})" if before.kind_of?(String) && before.include?('