Skip to content

Instantly share code, notes, and snippets.

@svs
Last active December 10, 2015 14:58
Show Gist options
  • Save svs/4450851 to your computer and use it in GitHub Desktop.
Save svs/4450851 to your computer and use it in GitHub Desktop.
module ActivityLogger
include ActiveSupport
def self.included(base)
base.extend ClassMethods
end
module ClassMethods
def log_with(model_name, options = {})
@@activity_logger_options = {
:save_method => :save_with_log,
:update_method => :update_with_log,
:validate_method => :valid?,
:exclude_attributes => []
}.merge(options)
@@activity_logger = model_name.to_s.camelize.constantize
end
def activity_logger
@@activity_logger
end
def activity_logger_options
@@activity_logger_options
end
end
def save_with_log(doer, options = {})
self.class.activity_logger.send(self.class.activity_logger_options[:save_method], self, doer, self.class.activity_logger_options.merge(options))
end
def update_with_log(attributes,doer,options = {})
self.class.activity_logger.send(self.class.activity_logger_options[:update_method], self, attributes, doer, self.class.activity_logger_options.merge(options))
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment