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
- 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)
-
- (String+) command_arg
The argument to pass to the executable to get current version Defaults to DEFAULT_COMMAND_ARG.
-
- (Regexp) version_pattern
The pattern to match the version in #version_command's output.
Class Method Summary (collapse)
Instance Method Summary (collapse)
-
- (String) detect_version(executable_path)
- should be contain Gem::Version-parsable version number.
-
- (Detector) initialize(*args)
constructor
Forgiving input, allows either argument if only one supplied.
-
- (Proc) to_proc
This is the interface that any detector must have.
- - (Array<String>) version_command(executable_path)
Constructor Details
- (Detector) initialize(*command_args) - (Detector) initialize(version_pattern) - (Detector) initialize(*command_args, version_pattern)
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
- (String+) command_arg
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 |
- (Regexp) version_pattern
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
+ (Object) generate(detector_argument)
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
- (String) detect_version(executable_path)
- 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 |
- (Proc) to_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 |
- (Array<String>) version_command(executable_path)
80 81 82 |
# File 'lib/cliver/detector.rb', line 80 def version_command(executable_path) [executable_path, *Array(command_arg)] end |