From 25251bbe55177a003744d0381e0a627a3f8da859 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Wed, 25 May 2011 08:21:57 -0400 Subject: [PATCH 1/2] better support for block filters and method names with ! or ? --- lib/controller_filter_logging.rb | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/controller_filter_logging.rb b/lib/controller_filter_logging.rb index c0861f9..0236c1b 100644 --- a/lib/controller_filter_logging.rb +++ b/lib/controller_filter_logging.rb @@ -1,11 +1,12 @@ module AbstractController::Callbacks::ClassMethods - def before_filter_with_logging(filter_name, *args, &block) + def before_filter_with_logging(*args, &block) + filter_name = args.first.kind_of?(::Symbol) ? args.first : '<< anonymous >>' + 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 + before_filter_without_logging *args, &block else - create_logging_filter(filter_name) - before_filter_without_logging "#{filter_name}_with_logging".to_sym, *args + before_filter_without_logging create_logging_filter(filter_name), *args end end alias_method_chain :before_filter, :logging @@ -27,7 +28,8 @@ module AbstractController::Callbacks::ClassMethods alias_method_chain :prepend_before_filter, :logging def create_logging_filter(filter_name) - define_method("#{filter_name}_with_logging") do + name = "#{filter_name.to_s.gsub(%r{[?!]}, '')}_with_logging" + define_method(name) do Rails.logger.debug("Entering before_filter: #{filter_name}") send(filter_name).tap do |result| begin @@ -37,5 +39,6 @@ module AbstractController::Callbacks::ClassMethods end end end + name.to_sym end end From 0ea172d5e3bdbc90d30e2e2d66fe1e4f9f4b326a Mon Sep 17 00:00:00 2001 From: John Bintz Date: Wed, 25 May 2011 08:23:42 -0400 Subject: [PATCH 2/2] remove a redundant thing --- lib/controller_filter_logging.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/controller_filter_logging.rb b/lib/controller_filter_logging.rb index 0236c1b..0beab4c 100644 --- a/lib/controller_filter_logging.rb +++ b/lib/controller_filter_logging.rb @@ -1,11 +1,10 @@ module AbstractController::Callbacks::ClassMethods def before_filter_with_logging(*args, &block) - filter_name = args.first.kind_of?(::Symbol) ? args.first : '<< anonymous >>' - if block_given? Rails.logger.debug("Can't log filters with blocks: #{caller[0..3].join("\n")}") before_filter_without_logging *args, &block else + filter_name = args.shift before_filter_without_logging create_logging_filter(filter_name), *args end end