Class: Tap::Tasks::Dump

Inherits:
FileTask show all
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 Tap::Task

#name

Attributes included from Support::Executable

#app, #batch, #dependencies, #method_name, #on_complete_block

Instance Method Summary collapse

Methods inherited from FileTask

#backup, #backup_filepath, #basename, #basepath, #cleanup, #cleanup_dir, #cp, #cp_r, #filepath, #initialize, #initialize_copy, #log_basename, #mkdir, #mkdir_p, #mv, #prepare, #rm, #rm_r, #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, load, #log, parse, parse!, #to_s, use

Methods included from Support::Executable

#_execute, #batch_index, #batch_with, #batched?, #check_terminate, #depends_on, #enq, #execute, #fork, initialize, #initialize_batch_obj, #merge, #on_complete, #reset_dependencies, #resolve_dependencies, #sequence, #switch, #sync_merge, #unbatched_depends_on, #unbatched_enq, #unbatched_on_complete

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.value }
    _results.each {|_audit| trails << _audit.dump }
  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