Sha256: 6022b3a329bd08755e61fb027fad8e5ea33d7f3287cc2e4f3630a73aa52eba49
Contents?: true
Size: 1.58 KB
Versions: 1
Compression:
Stored size: 1.58 KB
Contents
require 'tap/task' require 'stringio' module Tap module Tasks # :startdoc::task the default load task # # Loads data from $stdin. String data may be passed directly. Load # is typically used as a gateway to other tasks. # # % tap run -- load string --: dump # string # # Load facilitates normal redirection: # # % echo goodnight moon | tap run -- load --: dump # goodnight moon # # % tap run -- load --: dump < somefile.txt # contents of somefile # # :startdoc::task- # # Load serves as a baseclass for more complicated loads. A YAML load # (see {tap-tasks}[http://tap.rubyforge.org/tap-tasks]) looks like this: # # class Yaml < Tap::Load # def load(io) # YAML.load(io) # end # end # class Load < Tap::Task config :file, false, &c.flag # opens the input as a file # The default process simply reads the input data and returns it. # See load. def process(io=$stdin) # read on an empty stdin ties up the command line; # this facilitates the intended behavior if io.kind_of?(IO) && io.stat.size == 0 io = '' end if io.kind_of?(String) io = StringIO.new(io) end unless file open_io(io) do |data| load(data) end end # Loads data from the io; the return of load is the return of process. By # default load simply reads data from io. def load(io) io.read end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
tap-0.17.0 | lib/tap/tasks/load.rb |