tap 0.11.0 → 0.11.1

Sign up to get free protection for your applications and to get access to all the features.
data/bin/rap CHANGED
@@ -12,10 +12,11 @@ begin
12
12
  env = Tap::Exe.instantiate
13
13
  env.unshift(Tap::Declarations.env)
14
14
 
15
- task_file = File.expand_path('Tapfile')
16
- if File.exists?(task_file)
15
+ Dir.glob('[TtRr]apfile{,.rb}').each do |task_file|
16
+ task_file = File.expand_path(task_file)
17
+ next unless File.file?(task_file)
18
+
17
19
  env.loads.unshift(task_file)
18
- env.tasks.register(Dir.pwd, 'Tapfile')
19
20
  end
20
21
 
21
22
  rescue(Tap::Env::ConfigError)
@@ -71,12 +72,13 @@ begin
71
72
  <% end %>
72
73
  <% entries.each do |name, const| %>
73
74
  <% desc = if const.require_path == nil # should be a declaration %>
74
- <% manifest = const.constantize.lazydoc[const.name]['manifest'] %>
75
- <% next if manifest == nil || manifest.subject.empty? %>
76
- <% manifest.subject %>
75
+ <% manifest = const.constantize.manifest %>
76
+ <% next if manifest == nil || manifest.subject.to_s.empty? %>
77
+ <% manifest %>
77
78
  <% else %>
78
79
  <% const.document[const.name]['manifest'] %>
79
80
  <% end %>
81
+ <% desc = desc.subject.to_s if desc.kind_of?(Tap::Support::Lazydoc::Comment) %>
80
82
  <%= name.ljust(width) %><%= desc.empty? ? '' : ' # ' %><%= desc %>
81
83
  <% end %>}
82
84
 
data/cgi/run.rb CHANGED
@@ -14,9 +14,19 @@ module Tap
14
14
  module Server
15
15
  module_function
16
16
 
17
+ def parse_schema(params)
18
+ argh = pair_parse(params)
19
+
20
+ parser = Parser.new
21
+ parser.parse(argh['nodes'] || [])
22
+ parser.parse(argh['joins'] || [])
23
+ parser.schema
24
+ end
25
+
17
26
  def pair_parse(params)
18
27
  pairs = {}
19
28
  params.each_pair do |key, values|
29
+ next if key == nil
20
30
  key = key.chomp("%w") if key =~ /%w$/
21
31
 
22
32
  slot = pairs[key] ||= []
@@ -40,28 +50,48 @@ cgi = CGI.new("html3") # add HTML generation methods
40
50
  cgi.out() do
41
51
  case cgi.request_method
42
52
  when /GET/i
43
- env.render('run.erb', :env => env, :tascs => [] )
44
-
53
+ schema = Tap::Support::Server.parse_schema(cgi.params).compact
54
+ env.render('run.erb', :env => env, :schema => schema)
55
+
45
56
  when /POST/i
46
57
  action = cgi.params['action'][0]
47
58
  case action
48
59
  when 'add'
49
60
  index = cgi.params['index'][0].to_i - 1
50
- cgi.params['selected_tasks'].collect do |task|
61
+ sources = cgi.params['sources'].flatten.collect {|source| source.to_i }
62
+ targets = cgi.params['targets'].flatten.collect {|target| target.to_i }
63
+
64
+ lines = []
65
+ cgi.params['tasc'].select do |name|
66
+ name && !name.empty?
67
+ end.each do |name|
51
68
  index += 1
52
- tasc = env.tasks.search(task).constantize
53
- env.render('run/task.erb', :tasc => tasc, :index => index )
54
- end.join("\n")
69
+ targets << index
70
+ lines << env.render('run/node.erb', :env => env, :node => Tap::Support::Node.new([name]), :index => index )
71
+ end
55
72
 
73
+ join = case
74
+ when sources.length > 1 && targets.length == 1
75
+ Tap::Support::Schema::Utils.format_merge(sources, targets, {})
76
+ when sources.length == 1 && targets.length > 0
77
+ Tap::Support::Schema::Utils.format_fork(sources, targets, {})
78
+ else nil
79
+ end
80
+
81
+ lines << env.render('run/join.erb', :env => env, :join => join) if join
82
+ lines.join("\n")
83
+
56
84
  when 'remove'
57
- when 'update'
85
+
58
86
  else
87
+ # run
59
88
  cgi.pre do
60
- argh = Tap::Support::Server.pair_parse(cgi.params)
61
- Tap::Support::Schema.parse(argh['schema']).dump.to_yaml
89
+ schema = Tap::Support::Server.parse_schema(cgi.params)
90
+ schema.compact.dump.to_yaml
91
+ #env.build(schema)
62
92
  end
63
93
  end
64
94
  else
65
95
  raise ArgumentError, "unhandled request method: #{cgi.request_method}"
66
96
  end
67
- end
97
+ end
data/cmd/manifest.rb CHANGED
@@ -27,8 +27,8 @@ end.parse!(ARGV)
27
27
 
28
28
  env = Tap::Env.instance
29
29
  env_names = {}
30
- env.manifest(:envs, true).minimize.each do |name, environment|
31
- env_names[environment] = name
30
+ env.minimap.each do |env_name, environment|
31
+ env_names[environment] = env_name
32
32
  end
33
33
 
34
34
  filter = case
@@ -57,15 +57,13 @@ width = 10
57
57
  summary = env.inspect(template) do |templater, share|
58
58
  current = templater.env
59
59
  next unless filter.include?(current)
60
-
61
- manifest_keys = (Tap::Env.manifests.keys + current.manifests.keys).uniq
62
- manifests = manifest_keys.collect do |name|
63
- next if name == :envs
64
-
65
- manifest = current.manifest(name, true)
66
- next if manifest.empty?
60
+
61
+ manifests = []
62
+ [:commands, :generators, :tasks].each do |name|
63
+ manifest = current.send(name)
64
+ next if manifest.build.empty?
67
65
 
68
- entries = manifest.minimize.collect do |(entry, path)|
66
+ entries = manifest.minimap.collect do |(entry, path)|
69
67
  path = case path
70
68
  when Tap::Support::Constant then path.require_path
71
69
  else path
@@ -75,7 +73,7 @@ summary = env.inspect(template) do |templater, share|
75
73
  [entry, current.root.relative_filepath(:root, path) || path]
76
74
  end
77
75
 
78
- [name, entries]
76
+ manifests << [name, entries]
79
77
  end
80
78
  templater.manifests = manifests.compact
81
79
  templater.env_name = env_names[current]
data/doc/Tutorial CHANGED
@@ -27,7 +27,7 @@ Now from the command line:
27
27
  --------------------------------------------------------------------------------
28
28
  Says goodnight with a configurable message.
29
29
  --------------------------------------------------------------------------------
30
- usage: tap run -- goodnight obj
30
+ usage: rap goodnight OBJ
31
31
 
32
32
  configurations:
33
33
  --message MESSAGE
@@ -45,7 +45,7 @@ The declaration syntax is obviously similar to rake; configurations are new but
45
45
 
46
46
  # make the declarations available everywhere
47
47
  # (normally they're accessed via Tap, as above)
48
- extend Tap::Declarations
48
+ include Tap::Declarations
49
49
 
50
50
  namespace :example do
51
51
  task(:say, :message) do |task, args|
@@ -110,7 +110,7 @@ Simple enough; the name corresponds to the class, configurations (and dependenci
110
110
 
111
111
  Totally straightforward. Goodnight stores the default configurations, each instance has accessors to the configurations, and the defaults may be overridden during initialization, or later. Class definitions allow validation/transformation blocks to be specified for configurations. These blocks process inputs (ex the string inputs from the command line), quite literally defining the writer for a configuration accessor. A set of standard blocks are available through +c+, an alias for the Tap::Support::Validation module.
112
112
 
113
- [Tapfile]
113
+ [lib/goodnight.rb]
114
114
 
115
115
  # Goodnight::manifest a fancy goodnight moon task
116
116
  # Says goodnight with a configurable message.
@@ -154,7 +154,7 @@ Now from the command line:
154
154
  --------------------------------------------------------------------------------
155
155
  Says goodnight with a configurable message.
156
156
  --------------------------------------------------------------------------------
157
- usage: tap run -- goodnight OBJECTS...
157
+ usage: rap goodnight OBJECTS...
158
158
 
159
159
  configurations:
160
160
  --message MESSAGE a goodnight message
data/lib/tap/constants.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  module Tap
2
2
  MAJOR = 0
3
3
  MINOR = 11
4
- TINY = 0
4
+ TINY = 1
5
5
 
6
6
  VERSION="#{MAJOR}.#{MINOR}.#{TINY}"
7
7
  WEBSITE="http://tap.rubyforge.org"
@@ -2,16 +2,25 @@ require File.dirname(__FILE__) + "/../tap"
2
2
  autoload(:OpenStruct, 'ostruct')
3
3
 
4
4
  module Tap
5
+ #--
6
+ # more thought needs to go into extending Tap with Declarations
7
+ # and there should be some discussion on why include works at
8
+ # the top level (for main/Object) while extend should be used
9
+ # in all other cases.
5
10
  module Declarations
6
11
  Lazydoc = Tap::Support::Lazydoc
12
+ include Tap::Support::ShellUtils
7
13
 
8
14
  module Lazydoc
9
15
  class Declaration < Comment
16
+ attr_accessor :desc
17
+
10
18
  def resolve(lines)
11
19
  super
12
20
 
13
21
  @subject = case
14
- when content.empty? || content[0][0].to_s !~ /^::desc(.*)/ then ""
22
+ when content.empty? || content[0][0].to_s !~ /^::desc(.*)/
23
+ desc.to_s
15
24
  else
16
25
  content[0].shift
17
26
  $1.strip
@@ -42,16 +51,24 @@ module Tap
42
51
  end
43
52
 
44
53
  def self.env
45
- @env ||= Tap::Env.new(:load_paths => [], :command_paths => [], :generator_paths => [])
54
+ @env ||= Tap::Env.instance_for(Dir.pwd)
55
+ end
56
+
57
+ def declaration_env
58
+ @declaration_env ||= Declarations.env
46
59
  end
47
60
 
48
- def env
49
- @env ||= Declarations.env
61
+ attr_writer :declaration_base
62
+
63
+ def declaration_base
64
+ @declaration_base ||= ''
50
65
  end
51
66
 
52
- attr_accessor :declaration_base
67
+ attr_writer :current_desc
53
68
 
54
- attr_accessor :current_desc
69
+ def current_desc
70
+ @current_desc ||= nil
71
+ end
55
72
 
56
73
  def task(*args, &block)
57
74
  const_name, configs, dependencies, arg_names = resolve_args(args)
@@ -93,8 +110,7 @@ module Tap
93
110
  end
94
111
 
95
112
  def desc(str)
96
- self.current_desc = Lazydoc::Comment.new
97
- current_desc.subject = str
113
+ self.current_desc = str
98
114
  end
99
115
 
100
116
  protected
@@ -179,12 +195,12 @@ module Tap
179
195
  end
180
196
 
181
197
  # register the subclass in the manifest
182
- manifest = env.tasks
198
+ manifest = declaration_env.tasks
183
199
  const_name = subclass.to_s
184
- unless manifest.find {|const| const.name == const_name }
200
+ unless manifest.entries.any? {|const| const.name == const_name }
185
201
  manifest.entries << Tap::Support::Constant.new(const_name)
186
202
  end
187
-
203
+
188
204
  subclass
189
205
  end
190
206
 
@@ -193,16 +209,18 @@ module Tap
193
209
  # register documentation
194
210
  caller[1] =~ Lazydoc::CALLER_REGEXP
195
211
  task_class.source_file = File.expand_path($1)
196
- lazydoc = task_class.lazydoc(false)
197
- lazydoc[task_class.to_s]['manifest'] = current_desc || lazydoc.register($3.to_i - 1, Lazydoc::Declaration)
212
+ manifest = task_class.lazydoc(false).register($3.to_i - 1, Lazydoc::Declaration)
213
+ manifest.desc = current_desc
214
+ task_class.manifest = manifest
215
+
216
+ self.current_desc = nil
198
217
 
199
218
  if arg_names
200
219
  comment = Lazydoc::Comment.new
201
- comment.subject = arg_names.join(' ')
202
- lazydoc[task_class.to_s]['args'] = comment
220
+ comment.subject = arg_names.collect {|name| name.to_s.upcase }.join(' ')
221
+ task_class.args = comment
203
222
  end
204
-
205
- self.current_desc = nil
223
+
206
224
  task_class
207
225
  end
208
226
  end
data/lib/tap/exe.rb CHANGED
@@ -74,7 +74,8 @@ module Tap
74
74
  end
75
75
 
76
76
  def build(argv=ARGV)
77
- Support::Schema.parse(argv).compact.build(app) do |args|
77
+ schema = argv.kind_of?(Support::Schema) ? argv : Support::Schema.parse(argv)
78
+ schema.compact.build(app) do |args|
78
79
  task = args.shift
79
80
  const = tasks.search(task)
80
81
 
@@ -71,7 +71,7 @@ module Tap
71
71
 
72
72
  search_paths[search_path_index, search_paths.length - search_path_index].each do |(path_root, paths)|
73
73
  paths[path_index, paths.length - path_index].each do |path|
74
- new_entries = resolve(path_root, path) - entries
74
+ new_entries = resolve(path_root, path)
75
75
  entries.concat(new_entries)
76
76
 
77
77
  @path_index += 1
@@ -95,17 +95,24 @@ module Tap
95
95
  # filepath from path_root to path.
96
96
  def resolve(path_root, path)
97
97
  entries = []
98
- if document = Lazydoc.scan_doc(path, const_attr)
99
- if document.default_const_name.empty?
100
- relative_path = Root.relative_filepath(path_root, path).chomp(File.extname(path))
101
- document.default_const_name = relative_path.camelize
98
+ lazydoc = nil
99
+
100
+ Lazydoc.scan(File.read(path), const_attr) do |const_name, attr_key, comment|
101
+ if lazydoc == nil
102
+ lazydoc = Lazydoc[path]
103
+
104
+ if lazydoc.default_const_name.empty?
105
+ relative_path = Root.relative_filepath(path_root, path).chomp(File.extname(path))
106
+ lazydoc.default_const_name = relative_path.camelize
107
+ end
102
108
  end
103
109
 
104
- document.const_attrs.each_pair do |const_name, attrs|
105
- if attrs.has_key?(const_attr)
106
- entries << Constant.new(const_name, path)
107
- end
110
+ if const_name.empty?
111
+ const_name = lazydoc.default_const_name
108
112
  end
113
+
114
+ lazydoc[const_name][attr_key] = comment
115
+ entries << Constant.new(const_name, path)
109
116
  end
110
117
 
111
118
  entries
@@ -204,19 +204,22 @@ module Tap
204
204
  # Adds the dependency to each member in batch (and implicitly self).
205
205
  # The dependency will be resolved with the input arguments during
206
206
  # _execute, using resolve_dependencies.
207
- def depends_on(dependency)
207
+ def depends_on(*dependencies)
208
208
  batch.each do |e|
209
- e.unbatched_depends_on(dependency)
209
+ e.unbatched_depends_on(*dependencies)
210
210
  end
211
211
  self
212
212
  end
213
213
 
214
214
  # Like depends_on, but only adds the dependency to self.
215
- def unbatched_depends_on(dependency)
216
- raise ArgumentError, "cannot depend on self" if dependency == self
215
+ def unbatched_depends_on(*dependencies)
216
+ raise ArgumentError, "cannot depend on self" if dependencies.include?(self)
217
+
218
+ dependencies.each do |dependency|
219
+ app.dependencies.register(dependency)
220
+ self.dependencies << dependency unless self.dependencies.include?(dependency)
221
+ end
217
222
 
218
- app.dependencies.register(dependency)
219
- dependencies << dependency unless dependencies.include?(dependency)
220
223
  self
221
224
  end
222
225
 
@@ -29,17 +29,17 @@ module Tap
29
29
  lazydoc
30
30
  end
31
31
 
32
- # Creates a lazy attribute reader for the specified attribute.
32
+ # Creates a lazy attribute accessor for the specified attribute.
33
33
  def lazy_attr(key, attribute=key)
34
- instance_eval %Q{def #{key}; @#{key} ||= get_lazy_attr('#{attribute}'); end}
35
- end
36
-
37
- private
38
-
39
- def get_lazy_attr(attribute) # :nodoc:
40
- lazydoc[self.to_s][attribute] ||= Lazydoc::Comment.new
34
+ instance_eval %Q{
35
+ def #{key}
36
+ lazydoc[to_s]['#{attribute}'] ||= Lazydoc::Comment.new
37
+ end
38
+
39
+ def #{key}=(comment)
40
+ Lazydoc[source_file][to_s]['#{attribute}'] = comment
41
+ end}
41
42
  end
42
-
43
43
  end
44
44
  end
45
45
  end
@@ -15,7 +15,7 @@ module Tap
15
15
  end
16
16
  end
17
17
 
18
- @subject = args.join(', ')
18
+ @subject = args.join(' ')
19
19
  self
20
20
  end
21
21
  end
@@ -259,7 +259,7 @@ module Tap
259
259
 
260
260
  # build the workflow
261
261
  joins.each_pair do |join, (source_node, target_nodes)|
262
- raise "unassigned join: #{join}" if source_node == nil
262
+ raise "unassigned join: #{join}" if source_node == nil || target_nodes.empty?
263
263
 
264
264
  targets = target_nodes.collect do |target_node|
265
265
  tasks[target_node][0]
@@ -15,9 +15,7 @@ module Tap
15
15
  # Commands longer than these limits fail, usually with something like: 'the input
16
16
  # line is too long'
17
17
  module ShellUtils
18
-
19
- module_function
20
-
18
+
21
19
  # Run the system command +cmd+, passing the result to the block, if given.
22
20
  # Raises an error if the command fails. Uses the same semantics as
23
21
  # Kernel::exec and Kernel::system.
data/lib/tap/task.rb CHANGED
@@ -196,7 +196,12 @@ module Tap
196
196
  opts.separator "options:"
197
197
 
198
198
  opts.on_tail("-h", "--help", "Print this help") do
199
- opts.banner = "#{help}usage: tap run -- #{to_s.underscore} #{args.subject}"
199
+ prg = case $0
200
+ when /rap$/ then 'rap'
201
+ else 'tap run --'
202
+ end
203
+
204
+ opts.banner = "#{help}usage: #{prg} #{to_s.underscore} #{args.subject}"
200
205
  if block_given?
201
206
  yield(opts.to_s)
202
207
  else
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.11.0
4
+ version: 0.11.1
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: 2008-10-20 00:00:00 -06:00
12
+ date: 2008-11-02 01:00:00 -06:00
13
13
  default_executable: tap
14
14
  dependencies: []
15
15
 
@@ -166,7 +166,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
166
166
  requirements: []
167
167
 
168
168
  rubyforge_project: tap
169
- rubygems_version: 1.2.0
169
+ rubygems_version: 1.3.0
170
170
  signing_key:
171
171
  specification_version: 2
172
172
  summary: A framework for creating configurable, distributable tasks and workflows.