class Rack::DustbinLorry

Public Class Methods

new(app) click to toggle source
# File lib/rack/dustbin_lorry.rb, line 3
def initialize(app)
  @app = app
end

Public Instance Methods

call(env) click to toggle source
# File lib/rack/dustbin_lorry.rb, line 7
def call(env)
  cache_before = RubyVM.stat
  response = @app.call(env)
  cache_after = RubyVM.stat
  result = delta_cache(cache_before, cache_after)
  logger(env).info "Method cache change: #{result}" if result.select{ |k,v| v != 0 }.any?
  response
end

Private Instance Methods

delta_cache(before, after) click to toggle source
# File lib/rack/dustbin_lorry.rb, line 18
def delta_cache(before, after)
  states.each_with_object({}) do |counter, delta|
    delta[counter] = after[counter] - before[counter]
  end
end
logger(env) click to toggle source
# File lib/rack/dustbin_lorry.rb, line 28
def logger(env)
  @logger ||= if defined?(Rails)
    Rails.logger
  else
    env['rack.logger']
  end
end
states() click to toggle source
# File lib/rack/dustbin_lorry.rb, line 24
def states
  [:global_method_state, :global_constant_state, :class_serial]
end