Class: Cliver::Detector
- Inherits:
-
Struct
- Object
- Struct
- Cliver::Detector
- Defined in:
- lib/cliver/detector.rb
Overview
Default implementation of the detector needed by Cliver::Assertion, which will take anything that #respond_to?(:to_proc)
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
-
#command_arg ⇒ String
The argument to pass to the executable to get current version Defaults to DEFAULT_COMMAND_ARG.
-
#version_pattern ⇒ Regexp
The pattern to match the version in #version_command‘s output.
Instance Method Summary collapse
-
#detect_version(executable_path) ⇒ String
-
should be contain Gem::Version-parsable version number.
-
-
#initialize(*args) ⇒ Detector
constructor
Forgiving input, allows either argument if only one supplied.
-
#to_proc ⇒ Proc
This is the interface that any detector must have.
- #version_command(executable_path) ⇒ Array<String>
Constructor Details
#initialize(command_arg) ⇒ Detector #initialize(version_pattern) ⇒ Detector #initialize(command_arg, version_pattern) ⇒ Detector
Forgiving input, allows either argument if only one supplied.
23 24 25 26 27 |
# File 'lib/cliver/detector.rb', line 23 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_arg ⇒ String
The argument to pass to the executable to get current version Defaults to DEFAULT_COMMAND_ARG
7 8 9 |
# File 'lib/cliver/detector.rb', line 7 def command_arg @command_arg end |
#version_pattern ⇒ Regexp
The pattern to match the version in #version_command‘s output. Defaults to DEFAULT_VERSION_PATTERN
7 8 9 |
# File 'lib/cliver/detector.rb', line 7 def version_pattern @version_pattern end |
Instance Method Details
#detect_version(executable_path) ⇒ String
Returns - should be contain Gem::Version-parsable version number.
32 33 34 35 |
# File 'lib/cliver/detector.rb', line 32 def detect_version(executable_path) output = `#{version_command(executable_path).shelljoin} 2>&1` output[version_pattern] end |
#to_proc ⇒ Proc
This is the interface that any detector must have. If not overridden, returns a proc that wraps #detect_version
41 42 43 |
# File 'lib/cliver/detector.rb', line 41 def to_proc method(:detect_version).to_proc end |
#version_command(executable_path) ⇒ Array<String>
63 64 65 |
# File 'lib/cliver/detector.rb', line 63 def version_command(executable_path) [executable_path, command_arg] end |