Class: Rack::ProfileOnce

Inherits:
Action
  • Object
show all
Includes:
Utils
Defined in:
lib/rack/contrib/perftools_profiler.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Action

for_env

Constructor Details

#initialize(*args) ⇒ ProfileOnce

Returns a new instance of ProfileOnce.



328
329
330
331
332
# File 'lib/rack/contrib/perftools_profiler.rb', line 328

def initialize(*args)
  super
  @times = (Request.new(@env).params.fetch('times') {1}).to_i
  @new_env = delete_custom_params(@env)
end

Class Method Details

.has_special_param?(request) ⇒ Boolean

Returns:

  • (Boolean)


324
325
326
# File 'lib/rack/contrib/perftools_profiler.rb', line 324

def self.has_special_param?(request)
  request.params['profile'] != nil
end

Instance Method Details

#actObject



334
335
336
337
338
# File 'lib/rack/contrib/perftools_profiler.rb', line 334

def act
  @profiler.profile do
    @times.times { @middleware.call_app(@new_env) }
  end
end

#delete_custom_params(env) ⇒ Object



344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
# File 'lib/rack/contrib/perftools_profiler.rb', line 344

def delete_custom_params(env)
  new_env = env.clone
  
  params = Request.new(new_env).params
  params.delete('profile')
  params.delete('times')
  params.delete('printer')
  params.delete('ignore')
  params.delete('focus')

  new_env.delete('rack.request.query_string')
  new_env.delete('rack.request.query_hash')

  new_env['QUERY_STRING'] = build_query(params)
  new_env
end

#responseObject



340
341
342
# File 'lib/rack/contrib/perftools_profiler.rb', line 340

def response
  @middleware.profiler_data_response(@profiler.data(@data_params))
end