Last active
November 17, 2015 11:15
-
-
Save baphled/52cb494a06e70e885493 to your computer and use it in GitHub Desktop.
This file contains 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 Loggable | |
include ActiveSupport::Callbacks | |
define_callbacks :before_process, :after_process | |
protected | |
# Need to consider how to access in the method params | |
def before_process | |
@logger.info "Method name before message with: #{@params}" | |
end | |
def after_process | |
@logger.info "Method name after message with: #{@params}" | |
end | |
end | |
module Processable | |
module ClassMethods | |
public_methods.each do |method| | |
set_callback :before_process, :before, method.to_sym | |
set_callback :after_process, :after, method.to_sym | |
end | |
end | |
def self.included(receiver) | |
receiver.extend ClassMethods | |
receiver.send :include, InstanceMethods | |
end | |
end | |
class Importer | |
include Processable | |
def self.import | |
puts "Import some stuff" | |
end | |
end | |
# importer = Importer.import | |
#=> "Method name before message with: nil" | |
#=> "Import some stuff" | |
#=> "Method name after message with: nil" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment