tap 0.12.3 → 0.12.4

Sign up to get free protection for your applications and to get access to all the features.
data/History CHANGED
@@ -1,3 +1,14 @@
1
+ == 0.12.4 / 2009-03-23
2
+
3
+ * fixed bug in App#inspect
4
+ * documentation updates
5
+ * changed the default load/dump configs to load and
6
+ dump data without serialization
7
+ * made stdin the default input to load
8
+ * updated run syntax to allow arguments to be passed
9
+ to saved workflows
10
+ * updates to RootGenerator
11
+
1
12
  == 0.12.3 / 2009-03-05
2
13
 
3
14
  * Updates to allow Tap to use the latest Configurable.
data/README CHANGED
@@ -52,7 +52,6 @@ Tap pulls documentation out of task classes to generate manifests:
52
52
  sample:
53
53
  goodnight # your basic goodnight moon task
54
54
  tap:
55
- core_dump # dumps the application
56
55
  dump # the default dump task
57
56
  load # the default load task
58
57
 
data/bin/tap CHANGED
@@ -1,5 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
- # usage: tap <command> {options} [args]
2
+ # usage: tap <command> {options} [args] [-d-]
3
+ #
4
+ # Launches a tap command. To enable debugging, append the -d- superflag.
3
5
  #
4
6
  # examples:
5
7
  # tap generate root . # generates a root dir
@@ -14,11 +16,7 @@ require "#{File.dirname(__FILE__)}/../lib/tap.rb"
14
16
 
15
17
  # setup the environment
16
18
  begin
17
-
18
- # handle super options
19
- $DEBUG = true if ARGV.delete('-d-')
20
- env = Tap::Exe.instantiate
21
-
19
+ env = Tap::Exe.setup(ARGV)
22
20
  rescue(Tap::Env::ConfigError)
23
21
  # catch errors and exit gracefully
24
22
  # (errors usu from gem loading errors)
data/cmd/run.rb CHANGED
@@ -1,8 +1,13 @@
1
- # usage: tap run FILEPATHS... [options] -- [SCHEMA]
1
+ # usage: tap run [args] [options] -- [SCHEMA]
2
2
  #
3
3
  # examples:
4
4
  # tap run --help Prints this help
5
+ # tap run -w workflow.yml Build and run a workflow
6
+ # tap run -w workflow.yml a b c Same with [a, b, c] ARGV
7
+ #
8
+ # schema:
5
9
  # tap run -- task --help Prints help for task
10
+ # tap run -- load hello --: dump Say hello
6
11
  #
7
12
 
8
13
  env = Tap::Env.instance
@@ -12,10 +17,10 @@ app = Tap::App.instance
12
17
  # divide argv
13
18
  #
14
19
 
15
- run_argv = []
20
+ argv = []
16
21
  break_regexp = Tap::Support::Parser::BREAK
17
22
  while !ARGV.empty? && ARGV[0] !~ break_regexp
18
- run_argv << ARGV.shift
23
+ argv << ARGV.shift
19
24
  end
20
25
 
21
26
  #
@@ -35,7 +40,7 @@ ConfigParser.new do |opts|
35
40
 
36
41
  opts.separator ""
37
42
  opts.separator "options:"
38
-
43
+
39
44
  opts.on("-h", "--help", "Show this message") do
40
45
  Tap::App.lazydoc.resolve
41
46
  puts Lazydoc.usage(__FILE__)
@@ -48,29 +53,32 @@ ConfigParser.new do |opts|
48
53
  exit
49
54
  end
50
55
 
51
- end.parse!(run_argv, app.config)
56
+ opts.on("-w", "--workflow FILE", "Build the workflow file") do |path|
57
+ unless File.exists?(path)
58
+ puts "No such file or directory - #{path}"
59
+ puts "(did you mean 'tap run -- #{path}'?)"
60
+ exit
61
+ end
62
+
63
+ schema = Tap::Support::Schema.load_file(path)
64
+ env.build(schema, app)
65
+ end
66
+
67
+ end.parse!(argv, app.config)
52
68
 
53
69
  #
54
70
  # build and run the argv
55
71
  #
56
72
 
57
- run_argv.each do |path|
58
- unless File.exists?(path)
59
- puts "No such file or directory - #{path}"
60
- puts "(did you mean 'tap run -- #{path}'?)"
61
- exit
62
- end
63
-
64
- schema = Tap::Support::Schema.load_file(path)
65
- env.build(schema, app)
66
- end
67
-
68
73
  schema = Tap::Support::Schema.parse(ARGV)
69
- ARGV.clear
70
74
  env.build(schema, app)
75
+ ARGV.replace(argv)
71
76
 
72
77
  if app.queue.empty?
73
78
  puts "no task specified"
79
+ unless ARGV.empty?
80
+ puts "(did you mean 'tap run -- #{ARGV.join(' ')}'?)"
81
+ end
74
82
  exit
75
83
  end
76
84
 
data/lib/tap/app.rb CHANGED
@@ -197,8 +197,8 @@ module Tap
197
197
  self.logger = logger
198
198
  end
199
199
 
200
- # The default App logger writes to $stdout at level INFO.
201
- DEFAULT_LOGGER = Logger.new($stdout)
200
+ # The default App logger writes to $stderr at level INFO.
201
+ DEFAULT_LOGGER = Logger.new($stderr)
202
202
  DEFAULT_LOGGER.level = Logger::INFO
203
203
  DEFAULT_LOGGER.formatter = lambda do |severity, time, progname, msg|
204
204
  " %s[%s] %18s %s\n" % [severity[0,1], time.strftime('%H:%M:%S') , progname || '--' , msg]
@@ -356,11 +356,6 @@ module Tap
356
356
  self
357
357
  end
358
358
 
359
- # Returns a string like: "#<Tap::App:#{object_id} root: #{root} >"
360
- def inspect
361
- "#<#{self.class.to_s}:#{object_id} root: #{root} >"
362
- end
363
-
364
359
  # TerminateErrors are raised to kill executing tasks when terminate is
365
360
  # called on an running App. They are handled by the run rescue code.
366
361
  class TerminateError < RuntimeError
data/lib/tap/constants.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  module Tap
2
2
  MAJOR = 0
3
3
  MINOR = 12
4
- TINY = 3
4
+ TINY = 4
5
5
 
6
6
  VERSION="#{MAJOR}.#{MINOR}.#{TINY}"
7
7
  WEBSITE="http://tap.rubyforge.org"
data/lib/tap/dump.rb ADDED
@@ -0,0 +1,142 @@
1
+ module Tap
2
+
3
+ # :startdoc::manifest the default dump task
4
+ #
5
+ # A dump task to output results. Unlike most tasks, dump does not enque
6
+ # arguments from the command line; instead command line arguments are only
7
+ # used to setup the dump. Specifically dump accepts a filepath.
8
+ #
9
+ # % tap run -- [task] --: dump FILEPATH
10
+ #
11
+ # Results that come to dump are appended to the file. Dump only accepts
12
+ # one object at a time, so joins that produce an array need to iterate
13
+ # outputs to dump:
14
+ #
15
+ # % tap run -- load hello -- load world "--2(0,1)i" dump
16
+ #
17
+ # Note that dump uses $stdout by default so you can pipe or redirect dumps
18
+ # as normal.
19
+ #
20
+ # % tap run -- load hello --: dump | cat
21
+ # hello
22
+ #
23
+ # % tap run -- load hello --: dump 1> results.txt
24
+ # % cat results.txt
25
+ # hello
26
+ #
27
+ # :startdoc::manifest-
28
+ #
29
+ # Dump serves as a baseclass for more complicated dump tasks. A YAML dump
30
+ # task (see {tap-tasks}[http://tap.rubyforge.org/tap-tasks]) looks like this:
31
+ #
32
+ # class Yaml < Tap::Dump
33
+ # def dump(obj, io)
34
+ # YAML.dump(obj, io)
35
+ # end
36
+ # end
37
+ #
38
+ # === Implementation Notes
39
+ #
40
+ # Dump passes on the command line arguments to setup rather than process.
41
+ # Moreover, process will always receive the audits passed to _execute, rather
42
+ # than the audit values. This allows a user to provide setup arguments (such
43
+ # as a dump path) on the command line, and provides dump the opportunity to
44
+ # inspect audit trails within process.
45
+ #
46
+ class Dump < Tap::Task
47
+ class << self
48
+
49
+ # Same as an ordinary parse!, except the arguments normally reserved for
50
+ # executing the task are used to call setup. The return will always be
51
+ # an instance and an empty array.
52
+ def parse!(argv=ARGV, app=Tap::App.instance)
53
+ instance, args = super
54
+ instance.setup(*args)
55
+ [instance, []]
56
+ end
57
+ end
58
+
59
+ lazy_attr :args, :setup
60
+ lazy_register :setup, Lazydoc::Arguments
61
+
62
+ config :date_format, '%Y-%m-%d %H:%M:%S' # The date format
63
+ config :audit, false, &c.switch # Include the audit trails
64
+ config :date, false, &c.switch # Include a date
65
+
66
+ # The dump target, by default $stdout. Target may be a filepath,
67
+ # in which case dumps append the file.
68
+ attr_accessor :target
69
+
70
+ def initialize(config={}, name=nil, app=App.instance)
71
+ super(config, name, app)
72
+ @target = $stdout
73
+ end
74
+
75
+ # Setup self with the input target. Setup receives arguments passed from
76
+ # the command line, via parse!
77
+ def setup(output=$stdout)
78
+ @target = output
79
+ self
80
+ end
81
+
82
+ # Overrides the standard _execute to send process the audits and not
83
+ # the audit values. This allows process to inspect audit trails.
84
+ def _execute(input)
85
+ resolve_dependencies
86
+
87
+ previous = input.kind_of?(Support::Audit) ? input : Support::Audit.new(nil, input)
88
+ input = previous.value
89
+
90
+ # this is the overridden part
91
+ audit = Support::Audit.new(self, input, app.audit ? previous : nil)
92
+ send(method_name, audit)
93
+
94
+ if complete_block = on_complete_block || app.on_complete_block
95
+ complete_block.call(audit)
96
+ else
97
+ app.aggregator.store(audit)
98
+ end
99
+
100
+ audit
101
+ end
102
+
103
+ # The default process prints dump headers as specified in the config,
104
+ # then append the audit value to io.
105
+ def process(_audit)
106
+ open_io(target) do |io|
107
+ if date
108
+ io.puts "# date: #{Time.now.strftime(date_format)}"
109
+ end
110
+
111
+ if audit
112
+ io.puts "# audit:"
113
+ io.puts "# #{_audit.dump.gsub("\n", "\n# ")}"
114
+ end
115
+
116
+ dump(_audit.value, io)
117
+ end
118
+ end
119
+
120
+ # Dumps the object to io, by default dump puts (not prints) obj.to_s.
121
+ def dump(obj, io)
122
+ io.puts obj.to_s
123
+ end
124
+
125
+ protected
126
+
127
+ # helper to open and yield the io specified by target. open_io
128
+ # ensures file targets are closed when the block returns.
129
+ def open_io(io) # :nodoc:
130
+ case io
131
+ when IO, StringIO
132
+ yield(io)
133
+ when String
134
+ dir = File.dirname(io)
135
+ FileUtils.mkdir_p(dir) unless File.directory?(dir)
136
+ File.open(io, 'a') {|file| yield(file) }
137
+ else
138
+ raise "cannot open io: #{target.inspect}"
139
+ end
140
+ end
141
+ end
142
+ end
data/lib/tap/env.rb CHANGED
@@ -103,7 +103,7 @@ module Tap
103
103
  attr_reader :envs
104
104
 
105
105
  # The Root directory structure for self.
106
- nest(:root, Tap::Root, :initializer => false)
106
+ nest(:root, Tap::Root, :set_default => false)
107
107
 
108
108
  # Specify gems to load as nested Envs. Gems may be specified
109
109
  # by name and/or version, like 'gemname >= 1.2'; by default the
@@ -213,10 +213,16 @@ module Tap
213
213
  @gems = []
214
214
  @env_paths = []
215
215
 
216
- initialize_config case path_root_or_config
217
- when String, Root then {:root => path_root_or_config}
218
- else path_root_or_config
216
+ @root = case path_root_or_config
217
+ when Root then path_root_or_config
218
+ when String then Root.new(path_root_or_config)
219
+ else Root.new
219
220
  end
221
+
222
+ unless path_root_or_config.kind_of?(Hash)
223
+ path_root_or_config = {}
224
+ end
225
+ initialize_config(path_root_or_config)
220
226
  end
221
227
 
222
228
  # Clears manifests so they may be regenerated.
@@ -476,14 +482,6 @@ module Tap
476
482
  # A hash of the manifests for self.
477
483
  attr_reader :manifests
478
484
 
479
- def initialize_root(config)
480
- case config
481
- when Root then config
482
- when String then Root.new(config)
483
- else Root.new.reconfigure(config)
484
- end
485
- end
486
-
487
485
  def minikey(env)
488
486
  env.root.root
489
487
  end
data/lib/tap/exe.rb CHANGED
@@ -5,6 +5,15 @@ require 'tap/support/schema'
5
5
  module Tap
6
6
  class Exe < Env
7
7
  class << self
8
+ def setup(argv=ARGV)
9
+ if argv[-1] == '-d-'
10
+ argv.pop
11
+ $DEBUG = true
12
+ end
13
+
14
+ instantiate
15
+ end
16
+
8
17
  def instantiate(path_or_root=Dir.pwd)
9
18
  exe = super
10
19
 
@@ -121,7 +130,7 @@ module Tap
121
130
  end
122
131
  end
123
132
 
124
- def set_signals
133
+ def set_signals(app=Tap::App.instance)
125
134
  # info signal -- Note: some systems do
126
135
  # not support the INFO signal
127
136
  # (windows, fedora, at least)
data/lib/tap/file_task.rb CHANGED
@@ -34,11 +34,11 @@ module Tap
34
34
  include Tap::Support::ShellUtils
35
35
 
36
36
  # The backup directory
37
- config_attr :backup_dir, 'backup' # the backup directory
37
+ config_attr :backup_dir, 'backup' # The backup directory
38
38
 
39
39
  # A flag indicating whether or track changes
40
40
  # for rollback on execution error
41
- config :rollback_on_error, true, &c.switch # rollback changes on error
41
+ config :rollback_on_error, true, &c.switch # Rollback changes on error
42
42
 
43
43
  def initialize(config={}, name=nil, app=App.instance)
44
44
  super
@@ -19,8 +19,9 @@ module Tap::Generator::Generators
19
19
  #
20
20
  class RootGenerator < Tap::Generator::Base
21
21
 
22
- config :config_file, true, &c.switch # Create a tap.yml file
22
+ config :config_file, false, &c.switch # Create a full tap.yml file
23
23
  config :license, true, &c.switch # Create an MIT-LICENSE
24
+ config :history, true, &c.switch # Create History file
24
25
  config :rapfile, false, &c.switch # Create a Rapfile
25
26
 
26
27
  # ::args ROOT, PROJECT_NAME=basename(ROOT)
@@ -38,7 +39,12 @@ module Tap::Generator::Generators
38
39
  m.directory r[target]
39
40
  next
40
41
  when source =~ /gemspec$/
41
- m.template r[project_name + '.gemspec'], source, :project_name => project_name, :config_file => config_file, :license => license
42
+ m.template r[project_name + '.gemspec'], source, {
43
+ :project_name => project_name,
44
+ :config_file => config_file,
45
+ :license => license,
46
+ :history => history
47
+ }
42
48
  next
43
49
  when source =~ /Rapfile$/
44
50
  next unless rapfile
@@ -49,6 +55,7 @@ module Tap::Generator::Generators
49
55
  m.template r[target], source, :project_name => project_name, :license => license
50
56
  end
51
57
 
58
+ m.file(r['History']) if history
52
59
  m.file(r['tap.yml']) do |file|
53
60
  Configurable::Utils.dump(Tap::Env.configurations, file) do |key, delegate|
54
61
  default = delegate.default(false)
@@ -69,8 +76,8 @@ module Tap::Generator::Generators
69
76
  leader = key == 'root' || default == nil ? '# ' : ''
70
77
  config = YAML.dump({key => default})[5..-1].strip.gsub(/\n+/, "\n#{leader}")
71
78
  "#{lines.join("\n")}#{leader}#{config}\n\n"
72
- end
73
- end if config_file
79
+ end if config_file
80
+ end
74
81
  end
75
82
 
76
83
  end
@@ -14,13 +14,14 @@ Gem::Specification.new do |s|
14
14
 
15
15
  # list extra rdoc files here.
16
16
  s.extra_rdoc_files = %W{
17
+ <%= history ? " History\n" : '' %>
17
18
  README
18
19
  <%= license ? " MIT-LICENSE\n" : '' %>
19
20
  }
20
21
 
21
22
  # list the files you want to include here. you can
22
- # check this manifest using 'rake :print_manifest'
23
+ # check this manifest using 'rap print_manifest'
23
24
  s.files = %W{
24
- <%= config_file ? " tap.yml\n" : '' %>
25
+ tap.yml
25
26
  }
26
27
  end
data/lib/tap/load.rb ADDED
@@ -0,0 +1,64 @@
1
+ require 'stringio'
2
+
3
+ module Tap
4
+ # :startdoc::manifest the default load task
5
+ #
6
+ # Loads data from the input IO; string data is simply passed through. Load
7
+ # is typically used as a gateway to other tasks.
8
+ #
9
+ # % tap run -- load string --: [task]
10
+ #
11
+ # Note that load takes $stdin by default, so you can pipe or redirect data
12
+ # into to a workflow like so:
13
+ #
14
+ # % echo 'hello' | tap run -- load --: dump --audit
15
+ # # audit:
16
+ # # o-[tap/load] "hello\n"
17
+ # # o-[tap/dump] ["hello\n"]
18
+ # #
19
+ # hello
20
+ #
21
+ # % tap run -- load --: dump --audit < 'somefile.txt'
22
+ # # audit:
23
+ # # o-[tap/load] "contents of somefile\n"
24
+ # # o-[tap/dump] ["contents of somefile\n"]
25
+ # #
26
+ # contents of somefile
27
+ #
28
+ # ::manifest-
29
+ #
30
+ # Load serves as a baseclass for more complicated load tasks. A YAML load
31
+ # task (see {tap-tasks}[http://tap.rubyforge.org/tap-tasks]) looks like this:
32
+ #
33
+ # class Yaml < Tap::Load
34
+ # def load(io)
35
+ # YAML.load(io)
36
+ # end
37
+ # end
38
+ #
39
+ class Load < Tap::Task
40
+
41
+ # The default process simply reads the input data and returns it.
42
+ # See load.
43
+ def process(input=$stdin)
44
+ # read on an empty stdin ties up the command line;
45
+ # this facilitates the intended behavior
46
+ if input == $stdin && input.stat.size == 0
47
+ input = ''
48
+ end
49
+
50
+ case input
51
+ when StringIO, IO
52
+ load(input)
53
+ else
54
+ load(StringIO.new(input))
55
+ end
56
+ end
57
+
58
+ # Loads data from the io; the return of load is the return of process. By
59
+ # default load simply reads data from io.
60
+ def load(io)
61
+ io.read
62
+ end
63
+ end
64
+ end
@@ -72,9 +72,8 @@ module Tap
72
72
  # The path to load to initialize a missing constant
73
73
  attr_reader :require_path
74
74
 
75
- # Initializes a new Constant with the specified constant
76
- # name and require_path. The name should be a valid
77
- # constant name.
75
+ # Initializes a new Constant with the specified constant name and
76
+ # require_path. The name should be a valid constant name.
78
77
  def initialize(name, require_path=nil)
79
78
  @name = name
80
79
  @require_path = require_path
@@ -100,7 +99,7 @@ module Tap
100
99
  @const_name ||= (name =~ /.*::(.*)$/ ? $1 : name)
101
100
  end
102
101
 
103
- # Returns an array of the nesting constants of name.
102
+ # Returns the nesting constants of name.
104
103
  def nesting
105
104
  @nesting ||= (name =~ /(.*)::.*$/ ? $1 : '')
106
105
  end
@@ -123,9 +122,8 @@ module Tap
123
122
  another.require_path == self.require_path
124
123
  end
125
124
 
126
- # Looks up and returns the constant indicated by name.
127
- # If the constant cannot be found, the constantize
128
- # requires require_path and tries again.
125
+ # Looks up and returns the constant indicated by name. If the constant
126
+ # cannot be found, constantize requires require_path and tries again.
129
127
  #
130
128
  # Raises a NameError if the constant cannot be found.
131
129
  def constantize
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tap
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.12.3
4
+ version: 0.12.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Simon Chiang
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-03-05 00:00:00 -07:00
12
+ date: 2009-03-23 00:00:00 -06:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -20,7 +20,7 @@ dependencies:
20
20
  requirements:
21
21
  - - ">="
22
22
  - !ruby/object:Gem::Version
23
- version: 0.4.0
23
+ version: 0.4.1
24
24
  version:
25
25
  description:
26
26
  email: simon.a.chiang@gmail.com
@@ -97,9 +97,8 @@ files:
97
97
  - lib/tap/support/templater.rb
98
98
  - lib/tap/support/versions.rb
99
99
  - lib/tap/task.rb
100
- - lib/tap/tasks/core_dump.rb
101
- - lib/tap/tasks/dump.rb
102
- - lib/tap/tasks/load.rb
100
+ - lib/tap/dump.rb
101
+ - lib/tap/load.rb
103
102
  - lib/tap/test.rb
104
103
  - lib/tap/test/assertions.rb
105
104
  - lib/tap/test/env_vars.rb
@@ -1,57 +0,0 @@
1
- module Tap
2
- module Tasks
3
- # :startdoc::manifest dumps the application
4
- #
5
- # A dump task to print the application data to a file or IO. Currently the
6
- # dump result is only useful for viewing results. In the future the core
7
- # dump will be reloadable so a terminated app may restart execution.
8
- #
9
- # A core dump may be used in a terminal round to capture all the unhandled
10
- # results from previous rounds; if no filepath is specified, the results
11
- # are printed to stdout.
12
- #
13
- # % tap run -- [tasks] --+ core_dump FILEPATH
14
- #
15
- class CoreDump < Tap::FileTask
16
-
17
- config :date, true, &c.switch # include a date
18
- config :date_format, '%Y-%m-%d %H:%M:%S' # the date format
19
- config :info, true, &c.switch # dump the app state information
20
- config :aggregator, true, &c.switch # dump aggregator results
21
- config :audit, true, &c.switch # include the audit trails with results
22
-
23
- def process(target=$stdout)
24
- case target
25
- when IO then dump_to(target)
26
- when String
27
- log_basename(:dump, target)
28
- prepare(target)
29
- File.open(target, "wb") {|file| dump_to(file) }
30
- else
31
- raise "cannot dump to: #{target.inspect}"
32
- end
33
- end
34
-
35
- def dump_to(io)
36
- io.puts "# date: #{Time.now.strftime(date_format)}" if date
37
- io.puts "# info: #{app.info}" if info
38
-
39
- if aggregator
40
- trails = []
41
- results = {}
42
- app.aggregator.to_hash.each_pair do |src, _results|
43
- results["#{src} (#{src.object_id})"] = _results.collect {|_audit| _audit.value }
44
- _results.each {|_audit| trails << _audit.dump }
45
- end
46
-
47
- if audit
48
- io.puts "# audit:"
49
- trails.each {|trail| io.puts "# #{trail.gsub("\n", "\n# ")}"}
50
- end
51
-
52
- YAML::dump(results, io)
53
- end
54
- end
55
- end
56
- end
57
- end
@@ -1,125 +0,0 @@
1
- module Tap
2
- module Tasks
3
- # :startdoc::manifest the default dump task
4
- #
5
- # A dump task to print results as YAML. Unlike most tasks, dump arguments
6
- # do not enque to the task; instead the arguments are used to setup a
7
- # dump and the dump uses whatever results come to them in a workflow.
8
- #
9
- # Multiple dumps to the same file append rather than overwrite. If no file
10
- # is specified, the dump goes to $stdout.
11
- #
12
- # % tap run -- [task] --: dump FILEPATH
13
- #
14
- # Results may be printed directly, without conversion to YAML by using the
15
- # --no-yaml option.
16
- #
17
- # :startdoc::manifest-
18
- #
19
- # Dumps are organized so that arguments passed on the command line are
20
- # directed at setup rather than process. Moreover, process will always
21
- # receive the audits passed to _execute, rather than the audit values.
22
- # This allows a user to provide setup arguments (such as a dump path)
23
- # on the command line, and provides dump the opportunity to inspect
24
- # audit trails.
25
- #
26
- class Dump < Tap::FileTask
27
- class << self
28
-
29
- # Same as an ordinary parse!, except the arguments normally reserved for
30
- # executing the task are used to call setup. The return will always be
31
- # an instance and an empty array.
32
- def parse!(argv=ARGV, app=Tap::App.instance)
33
- instance, args = super
34
- instance.setup(*args)
35
- [instance, []]
36
- end
37
- end
38
-
39
- lazy_attr :args, :setup
40
- lazy_register :setup, Lazydoc::Arguments
41
-
42
- config :date_format, '%Y-%m-%d %H:%M:%S' # the date format
43
- config :audit, true, &c.switch # include the audit trails
44
- config :date, true, &c.switch # include a date
45
- config :yaml, true, &c.switch # dump as yaml (vs string)
46
-
47
- # The dump target, by default $stdout. Target may be a filepath,
48
- # in which case dumps append the file.
49
- attr_accessor :target
50
-
51
- def initialize(config={}, name=nil, app=App.instance, target=$stdout)
52
- super(config, name, app)
53
- @target = target
54
- end
55
-
56
- # Setup self with the input target. Setup is typically called from
57
- # parse! and receives arguments passed from the command line.
58
- def setup(path=target)
59
- @target = path
60
- end
61
-
62
- # Overrides the standard _execute to send process the audits and not
63
- # the audit values. This allows process to inspect audit trails.
64
- def _execute(*inputs)
65
- resolve_dependencies
66
-
67
- previous = []
68
- inputs.collect! do |input|
69
- if input.kind_of?(Support::Audit)
70
- previous << input
71
- input.value
72
- else
73
- previous << Support::Audit.new(nil, input)
74
- input
75
- end
76
- end
77
-
78
- # this is the overridden part
79
- audit = Support::Audit.new(self, inputs, app.audit ? previous : nil)
80
- send(method_name, audit)
81
-
82
- if complete_block = on_complete_block || app.on_complete_block
83
- complete_block.call(audit)
84
- else
85
- app.aggregator.store(audit)
86
- end
87
-
88
- audit
89
- end
90
-
91
- # Prints the _audit to the target. The return value of process is
92
- # not recorded in the audit trail.
93
- def process(_audit)
94
- open_io do |io|
95
- if date
96
- io.puts "# date: #{Time.now.strftime(date_format)}"
97
- end
98
-
99
- if audit
100
- io.puts "# audit:"
101
- io.puts "# #{_audit.dump.gsub("\n", "\n# ")}"
102
- end
103
-
104
- if yaml
105
- YAML::dump(_audit.value, io)
106
- else
107
- io << _audit.value.to_s
108
- end
109
- end
110
- end
111
-
112
- protected
113
-
114
- # helper to open and yield the io specified by target. open_io
115
- # ensures file targets are closed when the block returns.
116
- def open_io # :nodoc:
117
- case target
118
- when IO, StringIO then yield(target)
119
- when String then File.open(target, 'a') {|io| yield(io) }
120
- else raise "cannot open target: #{target.inspect}"
121
- end
122
- end
123
- end
124
- end
125
- end
@@ -1,31 +0,0 @@
1
- module Tap
2
- module Tasks
3
- # :startdoc::manifest the default load task
4
- #
5
- # Loads YAML-formatted data and makes the result available for other tasks.
6
- # Use the --no-yaml configuration to read the data without loading as YAML.
7
- #
8
- # Load is typically used as a gateway task to other tasks.
9
- #
10
- # % tap run -- load FILEPATH --: [task]
11
- #
12
- class Load < Tap::Task
13
-
14
- config :yaml, true, &c.switch # load as yaml (vs string)
15
-
16
- # Loads the input as YAML. Input may be an IO, StringIO, or a filepath.
17
- # The loaded object is returned directly.
18
- def process(input)
19
- str = case input
20
- when StringIO, IO
21
- input.read
22
- else
23
- log :load, input
24
- File.read(input)
25
- end
26
-
27
- yaml ? YAML.load(str) : str
28
- end
29
- end
30
- end
31
- end