Class: Tap::Tasks::Dump
- Defined in:
- lib/tap/tasks/dump.rb
Overview
:startdoc::manifest the default dump task
A dump task to print aggregated application results to a file or IO.
The results are printed as YAML, allowing dumped results to be reloaded and used as inputs to other tasks.
Often dump is used as the final task in a round of tasks; if no filepath is specified, the results are printed to stdout.
% tap run -- [tasks] --+ dump FILEPATH
See Tap::Load for more details.
Constant Summary
Constants inherited from Tap::Task
Tap::Task::DEFAULT_HELP_TEMPLATE
Instance Attribute Summary
Attributes inherited from FileTask
#added_files, #backed_up_files
Attributes inherited from Tap::Task
Attributes included from Support::Executable
#_method_name, #app, #batch, #dependencies, #on_complete_block
Attributes included from Support::Configurable
Instance Method Summary collapse
-
#dump_to(io) ⇒ Object
Dumps the current results in app.aggregator to the io.
-
#process(target = $stdout) ⇒ Object
Calls dump_to with the target.
Methods inherited from FileTask
#backup, #backup_filepath, #basename, #basepath, #cleanup, #dir_empty?, #filepath, #initialize, #initialize_copy, #log_basename, #mkdir, #open, #prepare, #restore, #rm, #rmdir, #rollback, #uptodate?
Methods included from Support::ShellUtils
#capture_sh, #redirect_sh, #sh
Methods inherited from Tap::Task
execute, help, inherited, #initialize, #initialize_batch_obj, #inspect, instance, intern, lazydoc, #log, parse, parse!, #to_s
Methods included from Support::Executable
#_execute, #batch_index, #batch_with, #batched?, #check_terminate, #depends_on, #enq, #execute, #fork, initialize, #initialize_batch_obj, #inspect, #merge, #on_complete, #reset_dependencies, #resolve_dependencies, #sequence, #switch, #sync_merge, #unbatched_depends_on, #unbatched_enq, #unbatched_on_complete
Methods included from Support::Configurable
included, #initialize_copy, #reconfigure
Constructor Details
This class inherits a constructor from Tap::FileTask
Instance Method Details
#dump_to(io) ⇒ Object
Dumps the current results in app.aggregator to the io. The dump will include the result audits and a date, as specified in config.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/tap/tasks/dump.rb', line 38 def dump_to(io) trails = [] results = {} app.aggregator.to_hash.each_pair do |src, _results| next if filter && src.to_s !~ filter results["#{src} (#{src.object_id})"] = _results.collect {|_audit| _audit._current } _results.each {|_audit| trails << _audit._to_s } end if audit io.puts "# audit:" trails.each {|trail| io.puts "# #{trail.gsub("\n", "\n# ")}"} end if date io.puts "# date: #{Time.now.strftime(date_format)}" end YAML::dump(results, io) end |
#process(target = $stdout) ⇒ Object
Calls dump_to with the target. If the target is not an IO, process assumes the target is a filepath. In that case, the file is prepared and the results dumped to it.
25 26 27 28 29 30 31 32 33 |
# File 'lib/tap/tasks/dump.rb', line 25 def process(target=$stdout) case target when IO then dump_to(target) else log_basename(:dump, target) prepare(target) File.open(target, "wb") {|file| dump_to(file) } end end |