Class: LibraryDetection::Dependent

Inherits:
Object
  • Object
show all
Defined in:
lib/one_apm/support/library_detection.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeDependent

Returns a new instance of Dependent.



58
59
60
61
62
# File 'lib/one_apm/support/library_detection.rb', line 58

def initialize
  @dependencies = []
  @executes = []
  @name = nil
end

Instance Attribute Details

#dependenciesObject (readonly)

Returns the value of attribute dependencies.



56
57
58
# File 'lib/one_apm/support/library_detection.rb', line 56

def dependencies
  @dependencies
end

#executedObject (readonly)

Returns the value of attribute executed.



50
51
52
# File 'lib/one_apm/support/library_detection.rb', line 50

def executed
  @executed
end

#nameObject

Returns the value of attribute name.



51
52
53
# File 'lib/one_apm/support/library_detection.rb', line 51

def name
  @name
end

Instance Method Details

#allowed_by_config?Boolean

Returns:

  • (Boolean)


98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/one_apm/support/library_detection.rb', line 98

def allowed_by_config?
  # If we don't have a name, can't check config so allow it
  return true if self.name.nil?

  key = "disable_#{self.name}".to_sym
  if (OneApm::Manager.config[key] == true)
    OneApm::Manager.logger.debug("Not installing #{self.name} instrumentation because of configuration #{key}")
    false
  else
    true
  end
end

#check_dependenciesObject



81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/one_apm/support/library_detection.rb', line 81

def check_dependencies
  return false unless allowed_by_config? && dependencies

  dependencies.all? do |dep|
    begin
      dep.call
    rescue => err
      OneApm::Manager.logger.error( "Error while detecting #{self.name}:", err )
      false
    end
  end
end

#dependencies_satisfied?Boolean

Returns:

  • (Boolean)


64
65
66
# File 'lib/one_apm/support/library_detection.rb', line 64

def dependencies_satisfied?
  !executed and check_dependencies
end

#depends_onObject



94
95
96
# File 'lib/one_apm/support/library_detection.rb', line 94

def depends_on
  @dependencies << Proc.new
end

#executeObject



68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/one_apm/support/library_detection.rb', line 68

def execute
  @executes.each do |x|
    begin
      x.call
    rescue => err
      OneApm::Manager.logger.error( "Error while installing #{self.name} instrumentation:", err )
      break
    end
  end
ensure
  executed!
end

#executed!Object



52
53
54
# File 'lib/one_apm/support/library_detection.rb', line 52

def executed!
  @executed = true
end

#executesObject



115
116
117
# File 'lib/one_apm/support/library_detection.rb', line 115

def executes
  @executes << Proc.new
end

#named(new_name) ⇒ Object



111
112
113
# File 'lib/one_apm/support/library_detection.rb', line 111

def named(new_name)
  self.name = new_name
end