module Rockt

Main Rockt API.

It defines only on public method: launch.

Constants

ApplicationLauncherFailed

Raised when the launcher helper fails.

ApplicationLauncherNotFound

Raised when no launcher helper is found.

VERSION

Public Class Methods

detect_environment() click to toggle source

Returns the module representing the current environment.

# File lib/rockt.rb, line 42
def self.detect_environment
  Environment.detect
end
launch(uri, options = {}) click to toggle source

This is the method for launching applications.

Valid options are:

  • dry_run: doesn’t launch the application.

# File lib/rockt.rb, line 26
def self.launch(uri, options = {})
  command = detect_environment.commands.find { |cmd| which cmd } or
    fail ApplicationLauncherNotFound

  unless options[:dry_run]
    _spawn command, uri

    fail ApplicationLauncherError unless $CHILD_STATUS.success?
  end

  command
end

Private Class Methods

_spawn(command, *params) click to toggle source
# File lib/rockt.rb, line 48
def self._spawn(command, *params)
  Process.wait spawn(command, *uri)
end
which(cmd) click to toggle source

Locate an executable file in the path

# File lib/rockt.rb, line 55
def self.which(cmd)
  exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']

  ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
    exts.each do |ext|
      exe = File.join(path, "#{cmd}#{ext}")
      exe if File.executable? exe
    end
  end
end