commit 47c4efa44c3df8348bb3d961bc4d0f209d2be543 Author: Jon Moses Date: Sun May 8 08:42:24 2011 -0400 First pass diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4040c6c --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +*.gem +.bundle +Gemfile.lock +pkg/* diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..c010d3d --- /dev/null +++ b/Gemfile @@ -0,0 +1,4 @@ +source "http://rubygems.org" + +# Specify your gem's dependencies in controller_filter_logging.gemspec +gemspec diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000..14cfe0b --- /dev/null +++ b/Rakefile @@ -0,0 +1,2 @@ +require 'bundler' +Bundler::GemHelper.install_tasks diff --git a/controller_filter_logging.gemspec b/controller_filter_logging.gemspec new file mode 100644 index 0000000..536f2c6 --- /dev/null +++ b/controller_filter_logging.gemspec @@ -0,0 +1,21 @@ +# -*- encoding: utf-8 -*- +$:.push File.expand_path("../lib", __FILE__) +require "controller_filter_logging/version" + +Gem::Specification.new do |s| + s.name = "controller_filter_logging" + s.version = ControllerFilterLogging::VERSION + s.platform = Gem::Platform::RUBY + s.authors = ["Jon Moses"] + s.email = ["jon@burningbush.us"] + s.homepage = "" + s.summary = %q{Bring back controller filter logging to rails 3} + s.description = %q{Gem to log execution and results of before_filter's for Rails 3} + + s.rubyforge_project = "controller_filter_logging" + + s.files = `git ls-files`.split("\n") + s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n") + s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) } + s.require_paths = ["lib"] +end diff --git a/init.rb b/init.rb new file mode 100644 index 0000000..71e98a9 --- /dev/null +++ b/init.rb @@ -0,0 +1 @@ +require 'lib/controller_filter_logging' unless Rails.env.production? diff --git a/lib/controller_filter_logging.rb b/lib/controller_filter_logging.rb new file mode 100644 index 0000000..27ed87c --- /dev/null +++ b/lib/controller_filter_logging.rb @@ -0,0 +1,27 @@ +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 + end + alias_method_chain :before_filter, :logging + + def skip_before_filter_with_logging(filter_name, *args) + skip_before_filter_without_logging("#{filter_name}_with_logging".to_sym, *args) + 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) + end + alias_method_chain :prepend_before_filter, :logging + + def create_logging_filter(filter_name) + define_method("#{filter_name}_with_logging") do + Rails.logger.debug("Entering before_filter: #{filter_name}") + send(filter_name).tap do |result| + Rails.logger.debug(" result: #{result}") + end + end + end +end diff --git a/lib/controller_filter_logging/version.rb b/lib/controller_filter_logging/version.rb new file mode 100644 index 0000000..522de0a --- /dev/null +++ b/lib/controller_filter_logging/version.rb @@ -0,0 +1,3 @@ +module ControllerFilterLogging + VERSION = "0.0.1" +end