Class: Pipe::Receiver

Inherits:
EM::Connection
  • Object
show all
Defined in:
lib/em-pipe-run.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(callback = nil) ⇒ Receiver

Constructor.

Parameters:

  • callback (Proc) (defaults to: nil)

    callback for giving back the results



42
43
44
45
# File 'lib/em-pipe-run.rb', line 42

def initialize(callback = nil)
    @callback = callback
    @buffer = ""
end

Instance Attribute Details

#bufferObject

Holds pipe output buffer.

Since:

  • 0.3.0



28
29
30
# File 'lib/em-pipe-run.rb', line 28

def buffer
  @buffer
end

Instance Method Details

#receive_data(data) ⇒ Object

Receives data from pipe.

Parameters:

  • data (String)

    output from pipe



52
53
54
# File 'lib/em-pipe-run.rb', line 52

def receive_data(data)
    @buffer << data
end

#unbindObject

Action after terminating the connection. Calls callback.



60
61
62
63
64
# File 'lib/em-pipe-run.rb', line 60

def unbind
    if not @callback.nil?
        @callback.call(@buffer)
    end
end