Permalink
Browse files

Experimental beginnings of a FIFO IOMethod.

  • Loading branch information...
1 parent 351c6c9 commit 4a4ab4265010458e30e674c67a5346c531dd8a2b tailor committed Feb 14, 2008
Showing with 32 additions and 0 deletions.
  1. +32 −0 lib/live_console/io_methods/fifo_io.rb
@@ -0,0 +1,32 @@
+class LiveConsole::IOMethods::FifoIO
+ DefaultOpts = {
+ :remove? => false, # If the file exists, should we remove it?
+ :user => nil, # User to give file ownership to
+ :mode => 0600, # The file's mode
+ }.freeze
+ RequiredOpts = DefaultOpts.keys + [:filename]
+
+ def start
+ maybe_remove!
+ if check_file
+ make_fifo
+ else
+ raise Errno::EEXIST, "File exists; either remove it or pass " \
+ ":remove? => true to LiveConsole.new."
+ end
+ end
+
+ include LiveConsole::IOMethods::IOMethod
+ private
+
+ def maybe_remove!
+ if !check_file && remove?
+ File.unlink(filename)
+ end
+ end
+
+ # Returns true if we can create the file.
+ def check_file
+ !File.exist?(filename)
+ end
+end

0 comments on commit 4a4ab42

Please sign in to comment.