Class: Launchy::Detect::Runner

Inherits:
Object
  • Object
show all
Extended by:
Launchy::DescendantTracker
Defined in:
lib/launchy/detect/runner.rb

Direct Known Subclasses

Forkable, Jruby, Windows

Defined Under Namespace

Classes: Forkable, Jruby, NotFoundError, Windows

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Launchy::DescendantTracker

children, find_child, inherited

Class Method Details

.detectObject

Detect the current command runner

If a runner cannot be detected then raise Runner::NotFoundError


12
13
14
15
16
17
18
19
20
21
22
# File 'lib/launchy/detect/runner.rb', line 12

def self.detect
  host_os_family = Launchy::Detect::HostOsFamily.detect
  ruby_engine    = Launchy::Detect::RubyEngine.detect

  return Windows.new if host_os_family.windows?
  if ruby_engine.jruby? then
    require 'spoon'
    return Jruby.new
  end
  return Forkable.new 
end

Instance Method Details

#commandline_normalize(cmdline) ⇒ Object


35
36
37
38
39
40
# File 'lib/launchy/detect/runner.rb', line 35

def commandline_normalize( cmdline )
  c = cmdline.flatten!
  c = c.find_all { |a| (not a.nil?) and ( a.size > 0 ) }
  Launchy.log "ARGV => #{c.inspect}"
  return c
end

#run(cmd, *args) ⇒ Object


42
43
44
45
46
47
48
# File 'lib/launchy/detect/runner.rb', line 42

def run( cmd, *args )
  if Launchy.dry_run? then
    puts dry_run( cmd, *args )
  else
    wet_run( cmd, *args )
  end
end

#shell_commands(cmd, args) ⇒ Object

cut it down to just the shell commands that will be passed to exec or posix_spawn. The cmd argument is split according to shell rules and the args are escaped according to shell rules.


29
30
31
32
33
# File 'lib/launchy/detect/runner.rb', line 29

def shell_commands( cmd, args )
  cmdline = [ cmd.shellsplit ]
  cmdline << args.collect{ |a| a.to_s.shellescape }
  return commanddline_normalize( cmdline )
end