Sha256: 9c56bba5fe09ce7815b7d2d1f11ec203e4ec2bcb5fd9fa0a90c04cf2d920c29c

Contents?: true

Size: 942 Bytes

Versions: 27

Compression:

Stored size: 942 Bytes

Contents

# encoding: utf-8
require 'fedux_org_stdlib/core_ext/file/which'

module FeduxOrgStdlib
  class CommandFinder
    private

    attr_reader :search_paths, :alternatives

    public

    # Finds path to command
    #
    # It also considers other executables for one command
    #
    # @param [String, Array] alternatives
    #   The executables to be used
    #
    # @param [String, Array] search_paths
    #   The search path as multiple paths as array or string where single
    #   search paths are concatenated via ':'
    def initialize(alternatives:, search_paths:)
      @alternatives = Array(alternatives)
      @search_paths = Array(search_paths)
    end

    # Find path to command
    def path
      alternatives.each do |e|
        next unless path = File.which(e, search_paths.join(':'))

        return path
      end

      nil
    end

    # Return known commands
    def known_commands
      @alternatives
    end
  end
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
fedux_org-stdlib-0.11.18 lib/fedux_org_stdlib/command_finder.rb
fedux_org-stdlib-0.11.17 lib/fedux_org_stdlib/command_finder.rb
fedux_org-stdlib-0.11.16 lib/fedux_org_stdlib/command_finder.rb
fedux_org-stdlib-0.11.15 lib/fedux_org_stdlib/command_finder.rb
fedux_org-stdlib-0.11.14 lib/fedux_org_stdlib/command_finder.rb
fedux_org-stdlib-0.11.12 lib/fedux_org_stdlib/command_finder.rb
fedux_org-stdlib-0.11.11 lib/fedux_org_stdlib/command_finder.rb
fedux_org-stdlib-0.11.9 lib/fedux_org_stdlib/command_finder.rb
fedux_org-stdlib-0.11.8 lib/fedux_org_stdlib/command_finder.rb
fedux_org-stdlib-0.11.7 lib/fedux_org_stdlib/command_finder.rb
fedux_org-stdlib-0.11.6 lib/fedux_org_stdlib/command_finder.rb
fedux_org-stdlib-0.11.5 lib/fedux_org_stdlib/command_finder.rb
fedux_org-stdlib-0.11.4 lib/fedux_org_stdlib/command_finder.rb
fedux_org-stdlib-0.11.3 lib/fedux_org_stdlib/command_finder.rb
fedux_org-stdlib-0.11.2 lib/fedux_org_stdlib/command_finder.rb
fedux_org-stdlib-0.11.1 lib/fedux_org_stdlib/command_finder.rb
fedux_org-stdlib-0.11.0 lib/fedux_org_stdlib/command_finder.rb
fedux_org-stdlib-0.10.9 lib/fedux_org_stdlib/command_finder.rb
fedux_org-stdlib-0.10.8 lib/fedux_org_stdlib/command_finder.rb
fedux_org-stdlib-0.10.7 lib/fedux_org_stdlib/command_finder.rb