First pass

This commit is contained in:
Jon Moses 2011-05-08 08:42:24 -04:00
commit 47c4efa44c
7 changed files with 62 additions and 0 deletions

4
.gitignore vendored Normal file
View File

@ -0,0 +1,4 @@
*.gem
.bundle
Gemfile.lock
pkg/*

4
Gemfile Normal file
View File

@ -0,0 +1,4 @@
source "http://rubygems.org"
# Specify your gem's dependencies in controller_filter_logging.gemspec
gemspec

2
Rakefile Normal file
View File

@ -0,0 +1,2 @@
require 'bundler'
Bundler::GemHelper.install_tasks

View File

@ -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

1
init.rb Normal file
View File

@ -0,0 +1 @@
require 'lib/controller_filter_logging' unless Rails.env.production?

View File

@ -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

View File

@ -0,0 +1,3 @@
module ControllerFilterLogging
VERSION = "0.0.1"
end