Class: Torkify::Reader
- Inherits:
-
Object
- Object
- Torkify::Reader
- Defined in:
- lib/torkify/reader.rb
Instance Method Summary collapse
-
#initialize(command = 'tork-remote tork-engine', run_in_dir = Dir.pwd) ⇒ Reader
constructor
Open the tork command and initialize the streams.
-
#method_missing(method, *args, &blk) ⇒ Object
Pass all unknown methods straight to the underlying IO object.
-
#respond_to?(method, include_private = false) ⇒ Boolean
Allow respond_to? to work with method_missing.
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 _, @io, stderr, _ = Open3.popen3 command if @io.eof? raise TorkError, stderr.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) @io.send method, *args, &blk end |
Instance Method Details
#respond_to?(method, include_private = false) ⇒ Boolean
Allow respond_to? to work with method_missing.
31 32 33 |
# File 'lib/torkify/reader.rb', line 31 def respond_to?(method, include_private = false) @io.respond_to? method, include_private end |