Class Tap::Tasks::Load
In: lib/tap/tasks/load.rb
Parent: Tap::Task

Loads data from $stdin. String data may be passed directly. Load is typically used as a gateway to other tasks.

  % tap load string -: dump

Load facilitates normal redirection:

  % echo goodnight moon | tap load -: dump
  goodnight moon

  % tap load -: dump < somefile.txt
  contents of somefile

Load serves as a baseclass for more complicated loads. A YAML load could look like this:

  class Yaml < Tap::Tasks::Load
    def load(io)

If the use_close configuration is specified, load will close io upon completion. Files opened by load are always closed upon completion.


close   load   open   open_file   process  


file  [RW]  Opens the input as a file (false)
use_close  [RW]  Close the input when complete (false)

Public Instance methods

Closes io.


    # File lib/tap/tasks/load.rb, line 86
86:       def close(io)
87:         io.close
88:       end

Loads data from io using Load is intended as a hook for subclasses.


    # File lib/tap/tasks/load.rb, line 81
81:       def load(io)
83:       end

Opens the io; specifically this means:

  • Creating a StringIO for String inputs
  • Opening an IO for integer file descriptors
  • Returning all other objects


    # File lib/tap/tasks/load.rb, line 61
61:       def open(io)
62:         return open_file(io) if file
64:         case io
65:         when String
67:         when Integer
69:         else 
70:           io
71:         end
72:       end

Opens io as a File.


    # File lib/tap/tasks/load.rb, line 75
75:       def open_file(io)
76:         io.kind_of?(File) ? io :
77:       end

Loads data from io. Process will open the input io object, load a result. Process will close io when loading is complete, provided use_close or file is specified.


    # File lib/tap/tasks/load.rb, line 44
44:       def process(io=$stdin)
45:         io = open(io)
46:         result = load(io)
48:         if use_close || file
49:           close(io)
50:         end
52:         result
53:       end