Class: AppPerfRpm::Introspector

Inherits:
Object
  • Object
show all
Defined in:
lib/app_perf_rpm/introspector.rb

Constant Summary collapse

VALID_RUNNERS =
[
  :PhusionPassenger,
  :Puma,
  :Rainbows,
  :Resque,
  :Sidekiq,
  :Sinatra,
  :Unicorn,
  :Webrick
]

Class Method Summary collapse

Class Method Details

.agentable?Boolean

Returns:

  • (Boolean)


18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/app_perf_rpm/introspector.rb', line 18

def agentable?
  if raking? || rspecing?
    AppPerfRpm.logger.info("Detected rake, not initializing agent")
    return false
  end
  AppPerfRpm.logger.info("Detecting runner...")
  VALID_RUNNERS.each do |runner|
    if const_defined?(runner.to_s)
      AppPerfRpm.logger.info("#{runner} detected. You're valid")
      return true
    end
  end
  AppPerfRpm.logger.info("No valid runner detected!")
  false
end

.const_defined?(string_const) ⇒ Boolean

Returns:

  • (Boolean)


42
43
44
45
46
47
48
49
# File 'lib/app_perf_rpm/introspector.rb', line 42

def const_defined?(string_const)
  begin
  Object.const_get(string_const)
    true
  rescue NameError
    false
  end
end

.raking?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/app_perf_rpm/introspector.rb', line 38

def raking?
  (File.basename($0) =~ /\Arake/) == 0
end

.rspecing?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/app_perf_rpm/introspector.rb', line 34

def rspecing?
  (File.basename($0) =~ /\Arspec/) == 0
end