Module: Cliver::Detector

Included in:
Default
Defined in:
lib/cliver/detector.rb

Overview

The interface for Cliver::Detector classes.

Defined Under Namespace

Classes: Default

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

#initialize(command_arg) ⇒ Default #initialize(version_pattern) ⇒ Default #initialize(command_arg, version_pattern) ⇒ Default

Forward to default implementation

Parameters:

  • command_arg (String)

    (‘–version’)

  • version_pattern (Regexp)

    (/(?<=version )[0-9]+/i)

Returns:

  • (Default)

    a new instance of Default

See Also:



14
15
16
# File 'lib/cliver/detector.rb', line 14

def self.new(*args, &block)
  Default.new(*args, &block)
end

Instance Method Details

#detect_version(executable_path) ⇒ String

Returns - should be Gem::Version-parsable.

Parameters:

  • executable_path (String)
    • the path to the executable to test

Returns:

  • (String)
    • should be Gem::Version-parsable.



34
35
36
37
38
# File 'lib/cliver/detector.rb', line 34

def detect_version(executable_path)
  output = `#{version_command(executable_path).shelljoin} 2>&1`
  ver = output.scan(version_pattern)
  ver && ver.first
end

#to_procProc

This is the interface that any detector must have. If not overridden, returns a proc that wraps #detect_version

Returns:

See Also:



44
45
46
# File 'lib/cliver/detector.rb', line 44

def to_proc
  method(:detect_version).to_proc
end

#version_command(executable_path) ⇒ Array<String>

Parameters:

  • executable_path (String)

    the executable to test

Returns:

  • (Array<String>)

Raises:

  • (NotImplementedError)


20
21
22
# File 'lib/cliver/detector.rb', line 20

def version_command(executable_path)
  raise NotImplementedError
end

#version_patternRegexp

Returns - the pattern used against the output of the #version_command, which should typically be Gem::Version-parsable.

Returns:

  • (Regexp)
    • the pattern used against the output

    of the #version_command, which should typically be Gem::Version-parsable.

Raises:

  • (NotImplementedError)


27
28
29
30
# File 'lib/cliver/detector.rb', line 27

def version_pattern
  raise NotImplementedError unless defined? super
  super
end