From 096baed9f4109eedf19f85740e8f63affa7a8332 Mon Sep 17 00:00:00 2001 From: Jon Moses Date: Tue, 24 May 2011 13:44:24 -0400 Subject: [PATCH] Handle before filters with blocks. Sorta. --- lib/controller_filter_logging.rb | 22 ++++++++++++++++------ lib/controller_filter_logging/version.rb | 2 +- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/lib/controller_filter_logging.rb b/lib/controller_filter_logging.rb index 3002984..c0861f9 100644 --- a/lib/controller_filter_logging.rb +++ b/lib/controller_filter_logging.rb @@ -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 diff --git a/lib/controller_filter_logging/version.rb b/lib/controller_filter_logging/version.rb index ce4a541..78082c8 100644 --- a/lib/controller_filter_logging/version.rb +++ b/lib/controller_filter_logging/version.rb @@ -1,3 +1,3 @@ module ControllerFilterLogging - VERSION = "0.0.3" + VERSION = "0.0.4" end