Class: Launchy::Spawnable::Application
- Inherits:
-
Object
- Object
- Launchy::Spawnable::Application
- Defined in:
- lib/launchy/spawnable/application.rb
Direct Known Subclasses
Constant Summary collapse
- KNOWN_OS_FAMILIES =
[ :windows, :darwin, :nix ]
Class Method Summary collapse
- .application_classes ⇒ Object
- .find_application_class_for(*args) ⇒ Object
- .inherited(sub_class) ⇒ Object
Instance Method Summary collapse
-
#find_executable(bin, *paths) ⇒ Object
find an executable in the available paths mkrf did such a good job on this I had to borrow it.
-
#my_os ⇒ Object
return the current ‘host_os’ string from ruby’s configuration.
-
#my_os_family(test_os = my_os) ⇒ Object
detect what the current os is and return :windows, :darwin, :nix or :java.
-
#run(cmd, *args) ⇒ Object
run the command.
Class Method Details
.application_classes ⇒ Object
14 15 16 |
# File 'lib/launchy/spawnable/application.rb', line 14 def application_classes @application_classes ||= [] end |
.find_application_class_for(*args) ⇒ Object
18 19 20 |
# File 'lib/launchy/spawnable/application.rb', line 18 def find_application_class_for(*args) application_classes.find { |klass| klass.handle?(*args) } end |
.inherited(sub_class) ⇒ Object
11 12 13 |
# File 'lib/launchy/spawnable/application.rb', line 11 def inherited(sub_class) application_classes << sub_class end |
Instance Method Details
#find_executable(bin, *paths) ⇒ Object
find an executable in the available paths mkrf did such a good job on this I had to borrow it.
25 26 27 28 29 30 31 32 |
# File 'lib/launchy/spawnable/application.rb', line 25 def find_executable(bin,*paths) paths = ENV['PATH'].split(File::PATH_SEPARATOR) if paths.empty? paths.each do |path| file = File.join(path,bin) return file if File.executable?(file) end return nil end |
#my_os ⇒ Object
return the current ‘host_os’ string from ruby’s configuration
35 36 37 |
# File 'lib/launchy/spawnable/application.rb', line 35 def my_os ::Config::CONFIG['host_os'] end |
#my_os_family(test_os = my_os) ⇒ Object
detect what the current os is and return :windows, :darwin, :nix or :java
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/launchy/spawnable/application.rb', line 40 def my_os_family(test_os = my_os) case test_os when /mswin/i family = :windows when /windows/i family = :windows when /darwin/i family = :darwin when /mac os/i family = :darwin when /solaris/i family = :nix when /bsd/i family = :nix when /linux/i family = :nix when /cygwin/i family = :nix else $stderr.puts "Unknown OS familiy for '#{test_os}'. Please report this bug." family = :unknown end end |
#run(cmd, *args) ⇒ Object
run the command
65 66 67 68 69 70 71 72 |
# File 'lib/launchy/spawnable/application.rb', line 65 def run(cmd,*args) args.unshift(cmd) if my_os_family == :windows then require 'win32/process' end child_pid = fork { system args.join(' ') } Process.detach(child_pid) end |