Class Tap::Tasks::Stream
In: lib/tap/tasks/stream.rb
Parent: Load

Stream recurrently loads data from $stdin by requeing self until an end-of-file is reached. This behavior is useful for creating tasks that load a bit of data from an IO, send it into a workflow, and then repeat.

The eof cutoff can be modified using complete? method. Streaming will stop when complete? returns true. For instance, this is a prompt task:

  class Prompt < Tap::Tasks::Stream
    config :exit_seq, "\n"

    def load(io)
      if io.eof?
        nil
      else
        io.readline
      end
    end

    def complete?(io, line)
      line == nil || line == exit_seq
    end
  end

Methods

complete?   process   reque  

Public Instance methods

Returns true by default. Override in subclasses to allow recurrent loading (see process).

[Source]

    # File lib/tap/tasks/stream.rb, line 54
54:       def complete?(io, last)
55:         io.eof?
56:       end

Loads data from io. Process will open the input io object, load a result, then check to see if the loading is complete (using the complete? method). Unless loading is complete, process will enque io to self. Process will close io when loading is complete, provided use_close or file is specified.

[Source]

    # File lib/tap/tasks/stream.rb, line 37
37:       def process(io=$stdin)
38:         io = open(io)
39:         result = load(io)
40:         
41:         if complete?(io, result)
42:           if use_close || file
43:             close(io)
44:           end
45:         else
46:           reque(io)
47:         end
48:         
49:         result
50:       end

Reques self with io to the top of the queue.

[Source]

    # File lib/tap/tasks/stream.rb, line 59
59:       def reque(io)
60:         app.pq(self, [io])
61:       end

[Validate]