Class: Nodectl::PromisedFile

Inherits:
Object
  • Object
show all
Defined in:
lib/nodectl/promised_file.rb

Overview

Promised file is file which looks like an empty file while it does not exists

Instance Method Summary collapse

Constructor Details

#initialize(path, file_class, options = {}) ⇒ PromisedFile

Returns a new instance of PromisedFile.



3
4
5
6
7
8
# File 'lib/nodectl/promised_file.rb', line 3

def initialize(path, file_class, options = {})
  @path       = path
  @file_class = file_class
  @options    = options
  @fake_file  = Nodectl::Stream::File.new(StringIO.new)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



21
22
23
# File 'lib/nodectl/promised_file.rb', line 21

def method_missing(name, *args, &blk)
  current_file.public_send(name, *args, &blk)
end

Instance Method Details

#closeObject



10
11
12
13
# File 'lib/nodectl/promised_file.rb', line 10

def close
  @closed = true
  current_file.close
end

#onread(&blk) ⇒ Object

Hook Nodectl::Stream::File#onread for call it when real file was created



17
18
19
# File 'lib/nodectl/promised_file.rb', line 17

def onread(&blk)
  @onread = blk
end