Class: Cliver::Detector::Default

Inherits:
Struct
  • Object
show all
Includes:
Cliver::Detector
Defined in:
lib/cliver/detector/default.rb

Overview

Default implementation of Cliver::Detector Requires a command argument (default ‘–version’) and a pattern-matcher Regexp with sensible default.

Constant Summary collapse

DEFAULT_VERSION_PATTERN =

Default pattern to use when searching #version_command output

/(?<=version )[0-9][.0-9a-z]+/i.freeze
DEFAULT_COMMAND_ARG =

Default command argument to use against the executable to get version output

'--version'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Cliver::Detector

#detect_version, new, #to_proc

Constructor Details

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

Forgiving input, allows either argument if only one supplied.

Parameters:

  • command_arg (String)

    (‘–version’)

  • version_pattern (Regexp)

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



25
26
27
28
29
# File 'lib/cliver/detector/default.rb', line 25

def initialize(*args)
  command_arg = args.shift if args.first.kind_of?(String)
  version_pattern = args.shift
  super(command_arg, version_pattern)
end

Instance Attribute Details

#command_argString

The argument to pass to the executable to get current version Defaults to DEFAULT_COMMAND_ARG

Returns:

  • (String)


8
9
10
# File 'lib/cliver/detector/default.rb', line 8

def command_arg
  @command_arg
end

#version_patternRegexp

The pattern to match the version in #version_command‘s output. Defaults to DEFAULT_VERSION_PATTERN

Returns:

  • (Regexp)
    • the pattern used against the output

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



8
9
10
# File 'lib/cliver/detector/default.rb', line 8

def version_pattern
  @version_pattern
end

Instance Method Details

#version_command(executable_path) ⇒ Array<String>

Returns:

  • (Array<String>)


48
49
50
# File 'lib/cliver/detector/default.rb', line 48

def version_command(executable_path)
  [executable_path, command_arg]
end