Class: Dizby::Spawned
- Inherits:
-
Object
- Object
- Dizby::Spawned
- Defined in:
- lib/dizby/tunnel/spawned.rb
Class Method Summary collapse
- .dynamic(uri, config, &block)
- .handle_spawned(uri, config, origin)
- .obtain_object(&origin)
- .static(uri, config, &block)
Class Method Details
.dynamic(uri, config, &block)
18 19 20 21 22 |
# File 'lib/dizby/tunnel/spawned.rb', line 18 def self.dynamic(uri, config, &block) handle_spawned(uri, config, block) do |service| $stdout.puts "Running on port #{service.server.port}." end end |
.handle_spawned(uri, config, origin)
24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/dizby/tunnel/spawned.rb', line 24 def self.handle_spawned(uri, config, origin) service = nil obj = obtain_object(&origin) obj.define_singleton_method :__dizby_exit__ do service.close if service end service = Service.new(uri, obj, Marshal.load(config)) yield service if block_given? ensure service.wait if service end |
.obtain_object(&origin)
39 40 41 42 43 44 45 46 47 |
# File 'lib/dizby/tunnel/spawned.rb', line 39 def self.obtain_object(&origin) = [$stdout, $stdin, $stderr].map { |io| IOBarrier.new(io) } .each(&:block) origin.call ensure .each(&:allow) end |
.static(uri, config, &block)
14 15 16 |
# File 'lib/dizby/tunnel/spawned.rb', line 14 def self.static(uri, config, &block) handle_spawned(uri, config, block) end |