Sha256: 7a7d569a4aec450178ec34b773e290ad14b1b37bedb14664f33db8a9bc1d499e

Contents?: true

Size: 1.59 KB

Versions: 1

Compression:

Stored size: 1.59 KB

Contents

# encoding: utf-8
require 'shellwords'

module Cliver
  # The interface for Cliver::Detector classes.
  # @see Cliver::Detector::Default for reference implementation
  module Detector
    # Forward to default implementation
    # @see Cliver::Detector::Default
    # @overload (see Cliver::Detector::Default#initialize)
    # @param (see Cliver::Detector::Default#initialize)
    # @raise (see Cliver::Detector::Default#initialize)
    # @return (see Cliver::Detector::Default#initialize)
    def self.new(*args, &block)
      Default.new(*args, &block)
    end

    # @param executable_path [String] the executable to test
    # @return [Array<String>]
    def version_command(executable_path)
      raise NotImplementedError
    end

    # @return [Regexp] - the pattern used against the output
    #                    of the #version_command, which should
    #                    typically be Gem::Version-parsable.
    def version_pattern
      raise NotImplementedError unless defined? super
      super
    end

    # @param executable_path [String] - the path to the executable to test
    # @return [String] - should be Gem::Version-parsable.
    def detect_version(executable_path)
      output = `#{version_command(executable_path).shelljoin} 2>&1`
      ver = output.scan(version_pattern)
      ver && ver.first
    end

    # This is the interface that any detector must have.
    # If not overridden, returns a proc that wraps #detect_version
    # @see #detect_version
    # @return [Proc] following method signature of {#detect_version}
    def to_proc
      method(:detect_version).to_proc
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
cliver-0.1.3 lib/cliver/detector.rb