Skip to content

Commit

Permalink
Experimental beginnings of a FIFO IOMethod.
Browse files Browse the repository at this point in the history
  • Loading branch information
tailor committed Feb 14, 2008
1 parent 351c6c9 commit 4a4ab42
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions 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.