Handle before filters with blocks. Sorta.

This commit is contained in:
Jon Moses 2011-05-24 13:44:24 -04:00
parent 8a9950bba9
commit 096baed9f4
2 changed files with 17 additions and 7 deletions

View File

@ -1,7 +1,12 @@
module AbstractController::Callbacks::ClassMethods
def before_filter_with_logging(filter_name, *args)
create_logging_filter(filter_name)
before_filter_without_logging "#{filter_name}_with_logging".to_sym, *args
def before_filter_with_logging(filter_name, *args, &block)
if block_given?
Rails.logger.debug("Can't log filters with blocks: #{caller[0..3].join("\n")}")
before_filter_without_logging filter_name, *args, &block
else
create_logging_filter(filter_name)
before_filter_without_logging "#{filter_name}_with_logging".to_sym, *args
end
end
alias_method_chain :before_filter, :logging
@ -10,9 +15,14 @@ module AbstractController::Callbacks::ClassMethods
end
alias_method_chain :skip_before_filter, :logging
def prepend_before_filter_with_logging(filter_name, *args)
create_logging_filter(filter_name)
prepend_before_filter_without_logging("#{filter_name}_with_logging".to_sym, *args)
def prepend_before_filter_with_logging(filter_name, *args, &block)
if block_given?
Rails.logger.debug("Can't log filters with blocks: #{caller[0..3].join("\n")}")
prepend_before_filter_without_logging filter_name, *args, &block
else
create_logging_filter(filter_name)
prepend_before_filter_without_logging("#{filter_name}_with_logging".to_sym, *args)
end
end
alias_method_chain :prepend_before_filter, :logging

View File

@ -1,3 +1,3 @@
module ControllerFilterLogging
VERSION = "0.0.3"
VERSION = "0.0.4"
end