Module: CmdExecutable

Included in:
Runner
Defined in:
lib/cmd_executable.rb,
lib/cmd_executable/parser.rb,
lib/cmd_executable/runner.rb,
lib/cmd_executable/version.rb

Overview

Command Executable

Usage:

require 'cmd_executable'

class Klass
  include CmdExecutable

  def instance_method
    executable?('ls')
  end
end

Defined Under Namespace

Classes: CmdExecutableError, Parser, ParserError, Runner

Constant Summary collapse

VERSION =
'1.2.3'

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.executable?(command) ⇒ Boolean

Returns:

  • (Boolean)

Raises:



49
50
51
52
53
54
55
56
# File 'lib/cmd_executable.rb', line 49

def self.executable?(command)
  parsed = CmdExecutable::Parser.new(command)
  raise CmdExecutable::ParserError, parsed.raw unless parsed.validate?

  `type "#{parsed.command}" > /dev/null 2>&1`.yield_self do
    $CHILD_STATUS.success?
  end
end

Instance Method Details

#executable?(command) ⇒ Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/cmd_executable.rb', line 45

def executable?(command)
  CmdExecutable.executable?(command)
end