Class: FluentCommandBuilder::StandardVersionDetector

Inherits:
Object
  • Object
show all
Defined in:
lib/fluent_command_builder/version_detectors/standard_version_detector.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(command_name, command_arg = nil) ⇒ StandardVersionDetector

Returns a new instance of StandardVersionDetector.



11
12
13
14
15
16
# File 'lib/fluent_command_builder/version_detectors/standard_version_detector.rb', line 11

def initialize(command_name, command_arg=nil)
  @command_name = command_name
  @command_arg = command_arg
  @path_finder = FluentCommandBuilder.path_finder
  @backticks_executor = BackticksExecutor.new
end

Instance Attribute Details

#backticks_executorObject

Returns the value of attribute backticks_executor.



9
10
11
# File 'lib/fluent_command_builder/version_detectors/standard_version_detector.rb', line 9

def backticks_executor
  @backticks_executor
end

#path_finderObject

Returns the value of attribute path_finder.



9
10
11
# File 'lib/fluent_command_builder/version_detectors/standard_version_detector.rb', line 9

def path_finder
  @path_finder
end

Instance Method Details

#version(path = nil) ⇒ Object



18
19
20
21
22
23
24
25
26
27
# File 'lib/fluent_command_builder/version_detectors/standard_version_detector.rb', line 18

def version(path=nil)
  path ||= @path_finder.find_path @command_name
  return unless path && File.exist?(path)
  path = nil if path == '.'
  executable = path ? Path.new(path, @command_name).evaluated_path : @command_name
  command = %Q["#{executable}" #{@command_arg} 2>&1]
  output = @backticks_executor.execute(command).to_s
  v = Version.match(output)
  v ? v.version : nil
end