Permalink
Browse files

fixed typo 💣

  • Loading branch information...
1 parent 6f2e526 commit 65492a39d3f9f85d25792fcb0db52d9518d2b64f @dimko committed Oct 3, 2012
Showing with 26 additions and 25 deletions.
  1. +25 −24 lib/rack/leakin.rb
  2. +1 −1 lib/rack/leakin/version.rb
View
@@ -1,44 +1,45 @@
-require 'rack/leaking/version'
+require 'process_memory'
+require 'rack/leakin/version'
require 'rack'
module Rack
class Leakin
- attr_writer :threshold, :handler, :logger
+ class << self
+ attr_writer :threshold, :handler, :logger
- def initialize(app)
- @app = app
- end
+ def threshold
+ @threshold ||= 131072 # 128 Mb by default
+ end
- def threshold
- @threshold ||= begin
- options[:threshold] || 131072 # 128 Mb by default
+ def handler
+ @handler ||= lambda do |env, beginning, ending|
+ logger.warn "*** [Memory leak detected] #{env['REQUEST_METHOD']} #{env['REQUEST_URI']}, #{beginning}KB --> #{ending}KB"
+ end
end
- end
- def handler
- @handler ||= lambda do |env, beginning, ending|
- logger.warn "*** [Memory leak detected] #{env['REQUEST_METHOD']} #{env['REQUEST_URI']}, #{beginning}KB --> #{ending}KB"
+ def logger
+ @logger ||= begin
+ if defined?(Rails)
+ ::Rails.logger
+ else
+ ::Logger.new('rack-leaker.log')
+ end
+ end
end
end
+ def initialize(app)
+ @app = app
+ end
+
def call(env)
beginning = Process.memory
@app.call(env).tap do
ending = Process.memory
- if ending - beginning > threshold
- handler.call(env, beginning, ending)
- end
- end
- end
-
- def logger
- @logger ||= begin
- if defined?(Rails)
- ::Rails.logger
- else
- ::Logger.new('rack-leaker.log')
+ if ending - beginning > self.class.threshold
+ self.class.handler.call(env, beginning, ending)
end
end
end
@@ -1,5 +1,5 @@
module Rack
- module Leakin
+ class Leakin
VERSION = '0.0.1'
def self.version

0 comments on commit 65492a3

Please sign in to comment.