tap 0.18.0 → 0.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,40 @@
1
+ require 'tap/signals'
2
+
3
+ module Tap
4
+ module Signals
5
+ class Help < Signal
6
+
7
+ def call(args)
8
+ argv = convert_to_array(args, ['sig'])
9
+ argv.empty? ? list : desc(*argv)
10
+ end
11
+
12
+ def list
13
+ signals = obj.class.signals
14
+ width = signals.keys.collect {|key| key.length }.max
15
+
16
+ lines = []
17
+ signals.each_pair do |key, signal|
18
+ next if key.empty?
19
+
20
+ desc = signal.desc.to_s
21
+ desc = " # #{desc}" unless desc.empty?
22
+ lines << " /#{key.ljust(width)}#{desc}"
23
+ end
24
+
25
+ "signals: (#{obj.class})\n#{lines.join("\n")}"
26
+ end
27
+
28
+ def desc(sig)
29
+ clas = obj.signal(sig).class
30
+
31
+ if clas.respond_to?(:desc)
32
+ desc = clas.desc
33
+ "#{clas} -- #{desc.to_s}\n#{desc.wrap}"
34
+ else
35
+ "#{clas} -- no help available"
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,20 @@
1
+ require 'tap/signals/class_methods'
2
+
3
+ module Tap
4
+ module Signals
5
+ module ModuleMethods
6
+ module_function
7
+
8
+ # Extends including classes with Configurable::ClassMethods
9
+ def included(base)
10
+ base.extend ClassMethods
11
+ base.extend ModuleMethods unless base.kind_of?(Class)
12
+
13
+ # initialize any class variables
14
+ ClassMethods.initialize(base)
15
+ end
16
+ end
17
+
18
+ extend ModuleMethods
19
+ end
20
+ end
@@ -0,0 +1,68 @@
1
+ module Tap
2
+ module Signals
3
+
4
+ # Signal attaches an object and allows a specific method to be triggered
5
+ # through a standard interface.
6
+ class Signal
7
+ class << self
8
+ # A description of self
9
+ attr_accessor :desc
10
+ end
11
+
12
+ # The object receiving signals through self.
13
+ attr_reader :obj
14
+
15
+ attr_reader :block
16
+
17
+ def initialize(obj, &block)
18
+ @obj = obj
19
+ @block = block
20
+ end
21
+
22
+ # Calls process with the input args and returns the result. This method
23
+ # is a hook for subclasses.
24
+ def call(args)
25
+ process(args)
26
+ end
27
+
28
+ # Simply returns the input args. This method is a hook for subclasses.
29
+ def process(args)
30
+ args
31
+ end
32
+
33
+ protected
34
+
35
+ def convert_to_array(obj, signature=[], options=false)
36
+ return obj if obj.kind_of?(Array)
37
+
38
+ argv = signature.collect {|key| obj[key] }
39
+
40
+ if options
41
+ opts = {}
42
+ (obj.keys - signature).each do |key|
43
+ opts[key] = obj[key]
44
+ end
45
+
46
+ argv << opts
47
+ end
48
+
49
+ argv
50
+ end
51
+
52
+ def convert_to_hash(obj, signature=[], remainder=nil)
53
+ return obj if obj.kind_of?(Hash)
54
+
55
+ args, argh = obj, {}
56
+ signature.each do |key|
57
+ argh[key] = args.shift
58
+ end
59
+
60
+ if remainder
61
+ argh[remainder] = args
62
+ end
63
+
64
+ argh
65
+ end
66
+ end
67
+ end
68
+ end
@@ -1,6 +1,5 @@
1
1
  require 'tap/joins'
2
2
  require 'tap/root'
3
- require 'tap/env/string_ext'
4
3
 
5
4
  module Tap
6
5
  class App
@@ -121,48 +120,16 @@ module Tap
121
120
  # end
122
121
  # end
123
122
  #
124
- class Task
123
+ class Task < App::Api
125
124
  include App::Node
126
- include Configurable
127
125
 
128
126
  class << self
129
- def inherited(child) # :nodoc:
130
- unless child.instance_variable_defined?(:@source_file)
131
- caller[0] =~ Lazydoc::CALLER_REGEXP
132
- child.instance_variable_set(:@source_file, File.expand_path($1))
133
- end
134
- super
135
- end
136
-
137
- # Parses the argv into an instance of self. By default parse
138
- # parses an argh then calls instantiate, but there is no requirement
139
- # that this occurs in subclasses.
140
- #
141
- # ==== Block Overrides
142
- #
143
- # For convenience, parse will yield the internal ConfigParser to the
144
- # block, if given. This functionality was added to Task so they are
145
- # more flexible in executable files but it is not a part of the API
146
- # requirements for parse/parse!.
147
- #
148
- def parse(argv=ARGV, app=Tap::App.instance, &block) # :yields: opts
149
- parse!(argv.dup, app, &block)
150
- end
151
127
 
152
- # Same as parse, but removes arguments destructively.
153
- def parse!(argv=ARGV, app=Tap::App.instance) # :yields: opts
154
- opts = ConfigParser.new
155
-
156
- unless configurations.empty?
157
- opts.separator "configurations:"
158
- opts.add(configurations)
159
- opts.separator ""
160
- end
161
-
162
- opts.separator "options:"
128
+ def parser
129
+ opts = super
163
130
 
164
131
  # add option to print help
165
- opts.on("--help", "Print this help") do
132
+ opts.on!("--help", "Print this help") do
166
133
  lines = desc.kind_of?(Lazydoc::Comment) ? desc.wrap(77, 2, nil) : []
167
134
  lines.collect! {|line| " #{line}"}
168
135
  unless lines.empty?
@@ -172,30 +139,37 @@ module Tap
172
139
  end
173
140
 
174
141
  puts "#{self}#{desc.empty? ? '' : ' -- '}#{desc.to_s}"
175
- puts lines.join("\n")
142
+ puts help
176
143
  puts "usage: tap run -- #{to_s.underscore} #{args}"
177
144
  puts
178
145
  puts opts
179
146
  exit
180
147
  end
181
148
 
149
+ opts.on('--enque', 'Manually enques self') do
150
+ opts['enque'] = true
151
+ end
152
+
182
153
  # add option to specify a config file
183
154
  opts.on('--config FILE', 'Specifies a config file') do |config_file|
184
155
  opts.config.merge!(load_config(config_file))
185
156
  end
186
157
 
187
- yield(opts) if block_given?
158
+ opts
159
+ end
160
+
161
+ # Same as parse, but removes arguments destructively.
162
+ def parse!(argv=ARGV, app=Tap::App.instance)
163
+ parser = self.parser
188
164
 
189
165
  # (note defaults are not added so they will not
190
166
  # conflict with string keys from a config file)
191
- argv = opts.parse!(argv, :add_defaults => false)
167
+ argv = parser.parse!(argv, :add_defaults => false)
168
+ enque = parser.config.delete('enque')
169
+ instance = build({'config' => parser.nested_config}, app)
192
170
 
193
- instantiate({:config => opts.nested_config}, app)
194
- end
195
-
196
- # Instantiates an instance of self and returns an instance of self.
197
- def instantiate(argh={}, app=Tap::App.instance)
198
- new(argh[:config] || {}, app)
171
+ instance.enq(*argv) if enque
172
+ [instance, argv]
199
173
  end
200
174
 
201
175
  # Recursively loads path into a nested configuration file.
@@ -301,37 +275,19 @@ module Tap
301
275
  end
302
276
  end
303
277
 
304
- instance_variable_set(:@source_file, __FILE__)
305
-
306
- lazy_attr :desc, 'task'
307
278
  lazy_attr :args, :process
308
279
  lazy_register :process, Lazydoc::Arguments
309
280
 
310
- ###############################################################
311
- # [depreciated] manifest will be removed at 1.0
312
- lazy_attr :manifest
313
- def self.desc(resolve=true)
314
- comment = const_attrs['task'] ||= self.manifest
315
- resolve && comment.kind_of?(Lazydoc::Comment) ? comment.resolve : comment
316
- end
317
- def self.manifest
318
- # :::-
319
- #"warn manifest is depreciated, use ::task instead"
320
- # :::+
321
- const_attrs['manifest'] ||= Lazydoc::Subject.new(nil, lazydoc)
322
- end
323
- ###############################################################
281
+ signal :enq
324
282
 
325
- # The App receiving self during enq
326
- attr_reader :app
327
-
328
283
  # Initializes a new Task.
329
284
  def initialize(config={}, app=Tap::App.instance)
330
- @app = app
331
285
  @joins = []
332
-
333
- # initialize configs
334
- initialize_config(config)
286
+ super
287
+ end
288
+
289
+ def associations
290
+ [nil, joins]
335
291
  end
336
292
 
337
293
  # Auditing method call. Resolves dependencies, executes method_name,
@@ -425,8 +381,8 @@ module Tap
425
381
  end
426
382
 
427
383
  # Logs the inputs to the application logger (via app.log)
428
- def log(action, msg="", level=Logger::INFO)
429
- app.log(action, msg, level)
384
+ def log(action, msg=nil, level=Logger::INFO)
385
+ app.log(action, msg, level) { yield }
430
386
  end
431
387
 
432
388
  # Provides an abbreviated version of the default inspect, with only
@@ -434,12 +390,5 @@ module Tap
434
390
  def inspect
435
391
  "#<#{self.class.to_s}:#{object_id} #{config.to_hash.inspect} >"
436
392
  end
437
-
438
- def to_hash
439
- {
440
- :class => self.class,
441
- :config => config.to_hash
442
- }
443
- end
444
393
  end
445
394
  end
@@ -53,6 +53,12 @@ module Tap
53
53
  def dump(input, io)
54
54
  io.puts input.to_s
55
55
  end
56
+
57
+ def to_spec
58
+ spec = super
59
+ spec['config'].delete('output') if output == $stdout
60
+ spec
61
+ end
56
62
  end
57
63
  end
58
64
  end
@@ -30,26 +30,6 @@ module Tap
30
30
  # end
31
31
  # end
32
32
  #
33
- # Load subclasses may be constructed to reque itself in cases where objects
34
- # are sequentially loaded from the same io. Load will reque until the
35
- # complete? method returns true. An example is a prompt task:
36
- #
37
- # class Prompt < Tap::Tasks::Load
38
- # config :exit_seq, "\n"
39
- #
40
- # def load(io)
41
- # if io.eof?
42
- # nil
43
- # else
44
- # io.readline
45
- # end
46
- # end
47
- #
48
- # def complete?(io, line)
49
- # line == nil || line == exit_seq
50
- # end
51
- # end
52
- #
53
33
  # If the use_close configuration is specified, load will close io upon
54
34
  # completion. Files opened by load are always closed upon completion.
55
35
  #
@@ -59,20 +39,14 @@ module Tap
59
39
  config :use_close, false, :long => :close, &c.flag # Close the input when complete
60
40
 
61
41
  # Loads data from io. Process will open the input io object, load
62
- # a result, then check to see if the loading is complete (using the
63
- # complete? method). Unless loading is complete, process will enque
64
- # io to self. Process will close io when loading is complete, provided
42
+ # a result. Process will close io when loading is complete, provided
65
43
  # use_close or file is specified.
66
44
  def process(io=$stdin)
67
45
  io = open(io)
68
46
  result = load(io)
69
47
 
70
- if complete?(io, result)
71
- if use_close || file
72
- close(io)
73
- end
74
- else
75
- enq(io)
48
+ if use_close || file
49
+ close(io)
76
50
  end
77
51
 
78
52
  result
@@ -80,13 +54,12 @@ module Tap
80
54
 
81
55
  # Opens the io; specifically this means:
82
56
  #
83
- # * Opening a File (file true)
84
57
  # * Creating a StringIO for String inputs
85
58
  # * Opening an IO for integer file descriptors
86
59
  # * Returning all other objects
87
60
  #
88
61
  def open(io)
89
- return(io.kind_of?(File) ? io : File.open(io)) if file
62
+ return open_file(io) if file
90
63
 
91
64
  case io
92
65
  when String
@@ -98,6 +71,11 @@ module Tap
98
71
  end
99
72
  end
100
73
 
74
+ # Opens io as a File.
75
+ def open_file(io)
76
+ io.kind_of?(File) ? io : File.open(io)
77
+ end
78
+
101
79
  # Loads data from io using io.read. Load is intended as a hook
102
80
  # for subclasses.
103
81
  def load(io)
@@ -108,12 +86,6 @@ module Tap
108
86
  def close(io)
109
87
  io.close
110
88
  end
111
-
112
- # Returns true by default. Override in subclasses to allow recurrent
113
- # loading (see process).
114
- def complete?(io, last)
115
- true
116
- end
117
89
  end
118
90
  end
119
91
  end
@@ -116,13 +116,24 @@ module Tap
116
116
 
117
117
  nest(nesting, indent, line_sep) { yield }
118
118
  end
119
+
120
+ def indent(indent, str)
121
+ lines = str.kind_of?(Array) ? str : str.split("\n")
122
+ lines.collect! {|line| "#{indent}#{line}" }
123
+ lines.join("\n")
124
+ end
119
125
  end
120
126
 
121
127
  class << self
122
128
 
123
129
  # Builds the erb template with the specified attributes.
124
130
  def build(template, attributes={}, filename=nil)
125
- new(template, attributes, filename).build
131
+ new(template).build(attributes, filename)
132
+ end
133
+
134
+ # Builds the erb template file with the specified attributes.
135
+ def build_file(path, attributes={})
136
+ self.build(File.read(path), attributes, path)
126
137
  end
127
138
  end
128
139
 
@@ -1,6 +1,6 @@
1
1
  module Tap
2
2
  MAJOR = 0
3
- MINOR = 18
3
+ MINOR = 19
4
4
  TINY = 0
5
5
 
6
6
  VERSION="#{MAJOR}.#{MINOR}.#{TINY}"
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.18.0
4
+ version: 0.19.0
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-06-17 00:00:00 -06:00
12
+ date: 2009-12-05 00:00:00 -07: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.5.0
23
+ version: 0.6.0
24
24
  version:
25
25
  description:
26
26
  email: simon.a.chiang@gmail.com
@@ -33,7 +33,6 @@ extra_rdoc_files:
33
33
  - MIT-LICENSE
34
34
  - History
35
35
  - doc/API
36
- - doc/Class Reference
37
36
  - doc/Examples/Command Line
38
37
  - doc/Examples/Workflow
39
38
  files:
@@ -42,43 +41,50 @@ files:
42
41
  - cmd/run.rb
43
42
  - lib/tap.rb
44
43
  - lib/tap/app.rb
44
+ - lib/tap/app/api.rb
45
45
  - lib/tap/app/node.rb
46
46
  - lib/tap/app/queue.rb
47
47
  - lib/tap/app/stack.rb
48
48
  - lib/tap/app/state.rb
49
- - lib/tap/version.rb
50
- - lib/tap/tasks/dump.rb
51
49
  - lib/tap/env.rb
52
50
  - lib/tap/env/constant.rb
51
+ - lib/tap/env/context.rb
53
52
  - lib/tap/env/gems.rb
54
53
  - lib/tap/env/manifest.rb
55
54
  - lib/tap/env/minimap.rb
56
55
  - lib/tap/env/string_ext.rb
57
- - lib/tap/exe.rb
56
+ - lib/tap/intern.rb
58
57
  - lib/tap/join.rb
59
58
  - lib/tap/joins.rb
60
59
  - lib/tap/joins/switch.rb
61
60
  - lib/tap/joins/sync.rb
62
61
  - lib/tap/middleware.rb
63
- - lib/tap/tasks/load.rb
62
+ - lib/tap/middlewares/debugger.rb
63
+ - lib/tap/parser.rb
64
+ - lib/tap/prompt.rb
64
65
  - lib/tap/root.rb
65
66
  - lib/tap/root/utils.rb
66
67
  - lib/tap/root/versions.rb
67
- - lib/tap/schema.rb
68
- - lib/tap/schema/parser.rb
69
- - lib/tap/schema/utils.rb
70
- - lib/tap/intern.rb
71
- - lib/tap/templater.rb
68
+ - lib/tap/signals.rb
69
+ - lib/tap/signals/class_methods.rb
70
+ - lib/tap/signals/help.rb
71
+ - lib/tap/signals/module_methods.rb
72
+ - lib/tap/signals/signal.rb
72
73
  - lib/tap/task.rb
74
+ - lib/tap/tasks/dump.rb
75
+ - lib/tap/tasks/load.rb
76
+ - lib/tap/templater.rb
77
+ - lib/tap/version.rb
73
78
  - README
74
79
  - MIT-LICENSE
75
80
  - History
76
81
  - doc/API
77
- - doc/Class Reference
78
82
  - doc/Examples/Command Line
79
83
  - doc/Examples/Workflow
80
84
  has_rdoc: true
81
85
  homepage: http://tap.rubyforge.org
86
+ licenses: []
87
+
82
88
  post_install_message:
83
89
  rdoc_options:
84
90
  - --main
@@ -104,9 +110,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
104
110
  requirements: []
105
111
 
106
112
  rubyforge_project: tap
107
- rubygems_version: 1.3.1
113
+ rubygems_version: 1.3.5
108
114
  signing_key:
109
- specification_version: 2
115
+ specification_version: 3
110
116
  summary: A configurable, distributable workflow framework.
111
117
  test_files: []
112
118