Created
August 25, 2011 13:31
-
-
Save d11wtq/1170661 to your computer and use it in GitHub Desktop.
Example of wrapping methods using mixins (more complicated than it should be)
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 VerboseJob | |
module ClassMethods | |
def wrap_perform! | |
class << self | |
def perform_with_verbose(*args) | |
JobLogger.verbose { perform_without_verbose(*args) } | |
end | |
alias_method_chain :perform, :verbose \ | |
unless instance_method(:perform) == instance_method(:perform_with_verbose) | |
end | |
end | |
def singleton_method_added(name) | |
wrap_perform! if name == :perform | |
end | |
end | |
def self.included(job_class) | |
job_class.extend ClassMethods | |
job_class.wrap_perform! if job_class.respond_to?(:perform) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment