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
  string

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)
      YAML.load(io)
    end
  end

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

Methods

close   load   open   open_file   process  

Configurations

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

Public Instance methods

Closes io.

[Source]

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

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

[Source]

    # File lib/tap/tasks/load.rb, line 81
81:       def load(io)
82:         io.read
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

[Source]

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

Opens io as a File.

[Source]

    # File lib/tap/tasks/load.rb, line 75
75:       def open_file(io)
76:         io.kind_of?(File) ? io : File.open(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.

[Source]

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

[Validate]