Class: Launchy::Detect::Runner
- Inherits:
-
Object
- Object
- Launchy::Detect::Runner
- Extended by:
- Launchy::DescendantTracker
- Defined in:
- lib/launchy/detect/runner.rb
Defined Under Namespace
Classes: Forkable, Jruby, NotFoundError, Windows
Class Method Summary collapse
-
.detect ⇒ Object
Detect the current command runner.
Instance Method Summary collapse
- #commandline_normalize(cmdline) ⇒ Object
- #dry_run(cmd, *args) ⇒ Object
- #run(cmd, *args) ⇒ Object
-
#shell_commands(cmd, args) ⇒ Object
cut it down to just the shell commands that will be passed to exec or posix_spawn.
Methods included from Launchy::DescendantTracker
children, find_child, inherited
Class Method Details
.detect ⇒ Object
Detect the current command runner
This will return an instance of the Runner to be used to do the application launching.
If a runner cannot be detected then raise Runner::NotFoundError
The runner rules are, in order:
- If you are on windows, you use the Windows Runner no matter what
- If you are using the jruby engine, use the Jruby Runner. Unless rule (1) took effect
- Use Forkable (barring rules (1) and (2))
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/launchy/detect/runner.rb', line 22 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
46 47 48 49 50 51 |
# File 'lib/launchy/detect/runner.rb', line 46 def commandline_normalize( cmdline ) c = cmdline.flatten! c = c.find_all { |a| (not a.nil?) and ( a.size > 0 ) } Launchy.log "commandline_normalized => #{c.join(' ')}" return c end |
#dry_run(cmd, *args) ⇒ Object
53 54 55 |
# File 'lib/launchy/detect/runner.rb', line 53 def dry_run( cmd, *args ) shell_commands(cmd, args).join(" ") end |
#run(cmd, *args) ⇒ Object
57 58 59 60 61 62 63 |
# File 'lib/launchy/detect/runner.rb', line 57 def run( cmd, *args ) if Launchy.dry_run? then $stdout.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 not escaped because they whole set is passed to system as *args and in that case system shell escaping rules are not done.
40 41 42 43 44 |
# File 'lib/launchy/detect/runner.rb', line 40 def shell_commands( cmd, args ) cmdline = [ cmd.shellsplit ] cmdline << args.flatten.collect{ |a| a.to_s } return commandline_normalize( cmdline ) end |