Permalink
Browse files

use around_filter instead of after_filter

so that we get logging even when the filter chain has been halted. e.g. for redirects/renders triggered by a filter.
  • Loading branch information...
Jordan Brough authored and noahd1 committed Oct 5, 2010
1 parent e30e2c9 commit f22d1ef69e9f1b9263d04d4b841111d21ec5cb0c
Showing with 11 additions and 7 deletions.
  1. +2 −1 lib/oink/rails/memory_usage_logger.rb
  2. +9 −6 spec/rails/memory_usage_logger_spec.rb
@@ -7,7 +7,7 @@ module Oink
module MemoryUsageLogger
def self.included(klass)
klass.class_eval do
- after_filter :log_memory_usage
+ around_filter :log_memory_usage
end
end
@@ -38,6 +38,7 @@ def statm_page_size
end
def log_memory_usage
+ yield
if logger
memory_usage = get_memory_usage
logger.info("Memory usage: #{memory_usage} | PID: #{$$}")
@@ -12,17 +12,17 @@ def info(*args)
end
class << self
- attr_accessor :after_filters
+ attr_accessor :around_filters
- def after_filter method
- (@after_filters ||= []) << method
+ def around_filter method
+ (@around_filters ||= []) << method
end
end
include Oink::MemoryUsageLogger
def index
- run_after_filters
+ run_around_filters
end
def logger
@@ -35,8 +35,11 @@ def `(*args)
end
protected
- def run_after_filters
- self.class.after_filters.each { |filter| self.send(filter) }
+ def run_around_filters
+ self.class.around_filters.each { |filter| self.send(filter) { perform_action } }
+ end
+
+ def perform_action
end
end

0 comments on commit f22d1ef

Please sign in to comment.