Class: FSEvent::ProcessDevice::Spawner

Inherits:
Object
  • Object
show all
Defined in:
lib/fsevent/processdevice.rb

Instance Method Summary collapse

Constructor Details

#initialize(defs) ⇒ Spawner

Returns a new instance of Spawner.



24
25
26
# File 'lib/fsevent/processdevice.rb', line 24

def initialize(defs)
  @defs = defs
end

Instance Method Details

#assemble_code(device_name, *args) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/fsevent/processdevice.rb', line 28

def assemble_code(device_name, *args)
  code = ''

  libpath = File.dirname(File.dirname(__FILE__))
  code << "$:.unshift #{libpath.dump}\n"

  code << <<-'End'
    require 'fsevent'
    def ep(arg) STDERR.puts arg.inspect end
  End

  code << "class FSEvent::ProcessDevice_#{device_name} < FSEvent::ProcessDeviceC\n#{@defs}\nend\n"
  marshaled_args = Marshal.dump(args)
  code << "FSEvent::ProcessDeviceC.main(FSEvent::ProcessDevice_#{device_name}.new(#{device_name.dump}, *(Marshal.load(#{marshaled_args.dump}))))\n"
end

#new(device_name, *args) ⇒ Object



44
45
46
47
48
49
50
51
# File 'lib/fsevent/processdevice.rb', line 44

def new(device_name, *args)
  code = assemble_code(device_name, *args)
  io = IO.popen([RbConfig.ruby], "r+")
  io.sync = true
  io.write code
  io.write "__END__\n"
  FSEvent::ProcessDevice.send(:new, device_name, io)
end