Class: RailsConsolePro::Commands::ProfileCommand

Inherits:
BaseCommand
  • Object
show all
Defined in:
lib/rails_console_pro/commands/profile_command.rb

Overview

Command for profiling arbitrary blocks, callables, or ActiveRecord relations

Instance Method Summary collapse

Methods included from RailsConsolePro::ColorHelper

#bold_color, #color, #method_missing, #pastel, #respond_to_missing?

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class RailsConsolePro::ColorHelper

Instance Method Details

#execute(target = nil, *args, label: nil, &block) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/rails_console_pro/commands/profile_command.rb', line 7

def execute(target = nil, *args, label: nil, &block)
  return disabled_message unless enabled?

  label, target, block = normalize_arguments(label, target, block)
  execution = build_execution(target, args, block)
  return execution if execution.nil? || execution.is_a?(String)

  collector = Services::ProfileCollector.new(config)
  collector.profile(label: label || execution[:label]) do
    execution[:callable].call
  end
rescue => e
  RailsConsolePro::ErrorHandler.handle(e, context: :profile)
end