Class: Nand::Launcher::RbFileLauncher
- Defined in:
- lib/nand/launcher/rb_file_launcher.rb
Direct Known Subclasses
Instance Attribute Summary
Attributes inherited from Base
Class Method Summary collapse
- .launchable?(target, io, opts) ⇒ Boolean
- .load(target, opts, *argv) ⇒ Object
- .rb_file(target) ⇒ Object
- .require_rb(target) ⇒ Object
Instance Method Summary collapse
-
#initialize(target, executor, opts, *argv) ⇒ RbFileLauncher
constructor
A new instance of RbFileLauncher.
- #launch ⇒ Object
Methods inherited from Base
Constructor Details
#initialize(target, executor, opts, *argv) ⇒ RbFileLauncher
Returns a new instance of RbFileLauncher.
35 36 37 38 |
# File 'lib/nand/launcher/rb_file_launcher.rb', line 35 def initialize(target, executor, opts, *argv) super(target, opts, *argv) @executor = executor end |
Class Method Details
.launchable?(target, io, opts) ⇒ Boolean
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/nand/launcher/rb_file_launcher.rb', line 9 def self.launchable?( target, io, opts ) return false unless target.to_s =~/\.rb$/ require_rb(target) and true rescue LoadError => e io.puts "\t- " + e. false rescue => e io.puts "\t- " + e. false end |
.load(target, opts, *argv) ⇒ Object
20 21 22 23 24 25 26 27 28 |
# File 'lib/nand/launcher/rb_file_launcher.rb', line 20 def self.load( target, opts, *argv ) plugin = opts[:plugin] || File.basename(target, ".rb").split(/_/).map{|s| s.capitalize}.join #raise "Option --plugin is Required for #{target}" if plugin.nil? executor = Plugin.plugin!(plugin, *argv) raise "Executor #{plugin} is Not Emplemented exec Method" unless executor.respond_to?(:exec) RbFileLauncher.new(target, executor, opts, *argv) rescue LoadError => e raise "Not Found Plugin #{target}" end |
.rb_file(target) ⇒ Object
32 33 34 |
# File 'lib/nand/launcher/rb_file_launcher.rb', line 32 def self.rb_file(target) Pathname.new(target). end |
.require_rb(target) ⇒ Object
29 30 31 |
# File 'lib/nand/launcher/rb_file_launcher.rb', line 29 def self.require_rb(target) require "#{RbFileLauncher.rb_file(target).to_s}" end |
Instance Method Details
#launch ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/nand/launcher/rb_file_launcher.rb', line 39 def launch if child = Process.fork child else begin STDIN.reopen(@exec_stdin) STDOUT.reopen(@exec_stdout) STDERR.reopen(@exec_stderr) Signal.trap(:INT) {exit 0} Signal.trap(:TERM) {exit 0} Process.setpgrp @executor.exec rescue LoadError => e STDERR.puts e. rescue => e STDERR.puts e. ensure end end end |