Class: Tap::Tasks::Dump
- Defined in:
- lib/tap/tasks/dump.rb
Overview
:startdoc::task dump data
Dumps data to $stdout or a file output.
% tap dump content --output FILEPATH
Dump faciliates normal redirection:
% tap load 'goodnight moon' -: dump | more
goodnight moon
% tap load 'goodnight moon' -: dump 1> results.txt
% more results.txt
goodnight moon
Dump converts objects to strings using to_s:
% tap load goodnight -- load moon - dump - sync 0,1 2
["goodnight", "moon"]
% tap load goodnight -- load moon - dump - sync 0,1 2 -i
goodnight
moon
:startdoc::task-
Dump serves as a baseclass for more complicated dumps. A YAML dump (see tap-tasks) looks like this:
class Yaml < Tap::Tasks::Dump
def dump(obj, io)
YAML.dump(obj, io)
end
end
Direct Known Subclasses
Instance Attribute Summary
Attributes inherited from Tap::Task
Attributes inherited from App::Api
Instance Method Summary collapse
- #call(input) ⇒ Object
-
#dump(input, io) ⇒ Object
Dumps the object to io, by default dump puts (not prints) obj.to_s.
-
#process(input) ⇒ Object
The default process prints dump headers as specified in the config, then append the audit value to io.
- #to_spec ⇒ Object
Methods inherited from Tap::Task
#associations, #enq, #exe, #initialize, #log, #on_complete, parser
Methods inherited from App::Api
#associations, build, help, inherited, #initialize, #inspect, parse, parse!, parser
Methods included from Signals
#sig, #signal, #signal?, #signals
Methods included from Signals::ModuleMethods
Constructor Details
This class inherits a constructor from Tap::Task
Instance Method Details
#call(input) ⇒ Object
44 45 46 |
# File 'lib/tap/tasks/dump.rb', line 44 def call(input) process(input) end |
#dump(input, io) ⇒ Object
Dumps the object to io, by default dump puts (not prints) obj.to_s.
58 59 60 |
# File 'lib/tap/tasks/dump.rb', line 58 def dump(input, io) io.puts input.to_s end |
#process(input) ⇒ Object
The default process prints dump headers as specified in the config, then append the audit value to io.
50 51 52 53 54 55 |
# File 'lib/tap/tasks/dump.rb', line 50 def process(input) open_io(output, overwrite ? 'w' : 'a') do |io| dump(input, io) end input end |
#to_spec ⇒ Object
62 63 64 65 66 |
# File 'lib/tap/tasks/dump.rb', line 62 def to_spec spec = super spec['config'].delete('output') if output == $stdout spec end |