Module: Rails::MiddlewareTimer::Timer

Defined in:
lib/rails/middleware_timer/timer.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.output(class_name, time_taken) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/rails/middleware_timer/timer.rb', line 16

def output(class_name, time_taken)
  if respond_to?(:custom_output)
    custom_output(class_name, time_taken)
  else
    puts "#{class_name}#call took #{time_taken} ms"
  end
end

Instance Method Details

#call(env) ⇒ Object



4
5
6
7
8
9
10
11
12
# File 'lib/rails/middleware_timer/timer.rb', line 4

def call(env)
  start_time = Time.now
  response = super(env)
  end_time = Time.now
  time_taken = (1_000 * (end_time - start_time)).round
  class_name = self.class.name
  Rails::MiddlewareTimer::Timer.output(class_name, time_taken)
  response
end