Class: Torkify::Reader

Inherits:
Object
  • Object
show all
Defined in:
lib/torkify/reader.rb

Instance Method Summary collapse

Constructor Details

#initialize(command = 'tork-remote tork-engine', run_in_dir = Dir.pwd) ⇒ Reader

Open the tork command and initialize the streams.

STDOUT is kept as the underlying stream, and this class can be used as an IO-like object on STDOUT.

A TorkError is raised if the command fails, and its message is whatever has been written to the command’s STDERR stream.



13
14
15
16
17
18
19
20
21
# File 'lib/torkify/reader.rb', line 13

def initialize(command = 'tork-remote tork-engine', run_in_dir = Dir.pwd)
  Dir.chdir(run_in_dir) do
    self.in, self.out, self.err, self.thread = Open3.popen3 command

    if out.eof?
      raise TorkError, err.read.strip
    end
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &blk) ⇒ Object

Pass all unknown methods straight to the underlying IO object.

This allows this class to be used in an IO like way.



26
27
28
# File 'lib/torkify/reader.rb', line 26

def method_missing(method, *args, &blk)
  out.send method, *args, &blk
end

Instance Method Details

#respond_to?(method, include_private = false) ⇒ Boolean

Allow respond_to? to work with method_missing.

Returns:

  • (Boolean)


31
32
33
# File 'lib/torkify/reader.rb', line 31

def respond_to?(method, include_private = false)
  out.respond_to? method, include_private
end