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.
Class Method Summary collapse
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_args) ⇒ Detector #initialize(version_pattern) ⇒ Detector #initialize(*command_args, version_pattern) ⇒ Detector
Forgiving input, allows either argument if only one supplied.
32 33 34 35 36 37 |
# File 'lib/cliver/detector.rb', line 32 def initialize(*args) version_pattern = args.pop if args.last.kind_of?(Regexp) command_args = args unless args.empty? super(command_args, 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 |
Class Method Details
.generate(detector_argument) ⇒ Object
11 12 13 14 |
# File 'lib/cliver/detector.rb', line 11 def self.generate(detector_argument) return detector_argument if detector_argument.respond_to?(:call) new(*Array(detector_argument)) end |
Instance Method Details
#detect_version(executable_path) ⇒ String
Returns - should be contain Gem::Version-parsable version number.
42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/cliver/detector.rb', line 42 def detect_version(executable_path) output = shell_out_and_capture version_command(executable_path).shelljoin if $?.exitstatus == 127 raise Cliver::Dependency::NotFound.new( "Could not find an executable at given path '#{executable_path}'." + "If this path was not specified explicitly, it is probably a " + "bug in [Cliver](https://github.com/yaauie/cliver/issues)." ) end 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
58 59 60 |
# File 'lib/cliver/detector.rb', line 58 def to_proc method(:detect_version).to_proc end |
#version_command(executable_path) ⇒ Array<String>
80 81 82 |
# File 'lib/cliver/detector.rb', line 80 def version_command(executable_path) [executable_path, *Array(command_arg)] end |