Last active
December 10, 2015 14:58
-
-
Save svs/4450851 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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