Class: Xezat::DetectorManager

Inherits:
Object
  • Object
show all
Defined in:
lib/xezat/detectors.rb

Instance Method Summary collapse

Constructor Details

#initialize(detector_dir = File.expand_path(File.join(File.dirname(__FILE__), 'detector'))) ⇒ DetectorManager

Returns a new instance of DetectorManager.



8
9
10
11
12
13
14
15
# File 'lib/xezat/detectors.rb', line 8

def initialize(detector_dir = File.expand_path(File.join(File.dirname(__FILE__), 'detector')))
  Xezat.logger.debug('  Load detectors')
  @detectors = {}
  Dir.glob(File.join(detector_dir, '*.rb')).each do |rb|
    require rb
    @detectors[File.basename(rb, '.rb').intern] = Object.const_get("Xezat::Detector::#{File.basename(rb, '.rb').camelize}").new
  end
end

Instance Method Details

#detect(variables) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/xezat/detectors.rb', line 17

def detect(variables)
  Xezat.logger.debug('    Detect tools')
  tools = []
  @detectors.each do |name, detector|
    if variables[:PN].intern == name
      Xezat.logger.debug("      #{name} ... no (self)")
    elsif detector.detect(variables)
      tools << name
      Xezat.logger.debug("      #{name} ... yes")
    else
      Xezat.logger.debug("      #{name} ... no")
    end
  end
  if tools.include?(:python27) && (tools.include?(:python36) || tools.include?(:python37))
    Xezat.logger.debug('    Remove python27 because of detecting python3x')
    tools.delete(:python27)
  end
  tools
end