bahuvrihi-tap 0.10.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History +69 -0
- data/MIT-LICENSE +21 -0
- data/README +119 -0
- data/bin/tap +114 -0
- data/cmd/console.rb +42 -0
- data/cmd/destroy.rb +16 -0
- data/cmd/generate.rb +16 -0
- data/cmd/run.rb +126 -0
- data/doc/Class Reference +362 -0
- data/doc/Command Reference +153 -0
- data/doc/Tutorial +237 -0
- data/lib/tap.rb +32 -0
- data/lib/tap/app.rb +720 -0
- data/lib/tap/constants.rb +8 -0
- data/lib/tap/env.rb +640 -0
- data/lib/tap/file_task.rb +547 -0
- data/lib/tap/generator/base.rb +109 -0
- data/lib/tap/generator/destroy.rb +37 -0
- data/lib/tap/generator/generate.rb +61 -0
- data/lib/tap/generator/generators/command/command_generator.rb +21 -0
- data/lib/tap/generator/generators/command/templates/command.erb +32 -0
- data/lib/tap/generator/generators/config/config_generator.rb +26 -0
- data/lib/tap/generator/generators/config/templates/doc.erb +12 -0
- data/lib/tap/generator/generators/config/templates/nodoc.erb +8 -0
- data/lib/tap/generator/generators/file_task/file_task_generator.rb +27 -0
- data/lib/tap/generator/generators/file_task/templates/file.txt +11 -0
- data/lib/tap/generator/generators/file_task/templates/result.yml +6 -0
- data/lib/tap/generator/generators/file_task/templates/task.erb +33 -0
- data/lib/tap/generator/generators/file_task/templates/test.erb +29 -0
- data/lib/tap/generator/generators/root/root_generator.rb +55 -0
- data/lib/tap/generator/generators/root/templates/Rakefile +86 -0
- data/lib/tap/generator/generators/root/templates/gemspec +27 -0
- data/lib/tap/generator/generators/root/templates/tapfile +8 -0
- data/lib/tap/generator/generators/root/templates/test/tap_test_helper.rb +3 -0
- data/lib/tap/generator/generators/root/templates/test/tap_test_suite.rb +5 -0
- data/lib/tap/generator/generators/root/templates/test/tapfile_test.rb +15 -0
- data/lib/tap/generator/generators/task/task_generator.rb +27 -0
- data/lib/tap/generator/generators/task/templates/task.erb +14 -0
- data/lib/tap/generator/generators/task/templates/test.erb +21 -0
- data/lib/tap/generator/manifest.rb +14 -0
- data/lib/tap/patches/rake/rake_test_loader.rb +8 -0
- data/lib/tap/patches/rake/testtask.rb +55 -0
- data/lib/tap/patches/ruby19/backtrace_filter.rb +51 -0
- data/lib/tap/patches/ruby19/parsedate.rb +16 -0
- data/lib/tap/root.rb +581 -0
- data/lib/tap/support/aggregator.rb +55 -0
- data/lib/tap/support/assignments.rb +172 -0
- data/lib/tap/support/audit.rb +418 -0
- data/lib/tap/support/batchable.rb +47 -0
- data/lib/tap/support/batchable_class.rb +107 -0
- data/lib/tap/support/class_configuration.rb +194 -0
- data/lib/tap/support/command_line.rb +98 -0
- data/lib/tap/support/comment.rb +270 -0
- data/lib/tap/support/configurable.rb +114 -0
- data/lib/tap/support/configurable_class.rb +296 -0
- data/lib/tap/support/configuration.rb +122 -0
- data/lib/tap/support/constant.rb +70 -0
- data/lib/tap/support/constant_utils.rb +127 -0
- data/lib/tap/support/declarations.rb +111 -0
- data/lib/tap/support/executable.rb +111 -0
- data/lib/tap/support/executable_queue.rb +82 -0
- data/lib/tap/support/framework.rb +71 -0
- data/lib/tap/support/framework_class.rb +199 -0
- data/lib/tap/support/instance_configuration.rb +147 -0
- data/lib/tap/support/lazydoc.rb +428 -0
- data/lib/tap/support/manifest.rb +89 -0
- data/lib/tap/support/run_error.rb +39 -0
- data/lib/tap/support/shell_utils.rb +71 -0
- data/lib/tap/support/summary.rb +30 -0
- data/lib/tap/support/tdoc.rb +404 -0
- data/lib/tap/support/tdoc/tdoc_html_generator.rb +38 -0
- data/lib/tap/support/tdoc/tdoc_html_template.rb +42 -0
- data/lib/tap/support/templater.rb +180 -0
- data/lib/tap/support/validation.rb +410 -0
- data/lib/tap/support/versions.rb +97 -0
- data/lib/tap/task.rb +259 -0
- data/lib/tap/tasks/dump.rb +56 -0
- data/lib/tap/tasks/rake.rb +93 -0
- data/lib/tap/test.rb +37 -0
- data/lib/tap/test/env_vars.rb +29 -0
- data/lib/tap/test/file_methods.rb +377 -0
- data/lib/tap/test/script_methods.rb +144 -0
- data/lib/tap/test/subset_methods.rb +420 -0
- data/lib/tap/test/tap_methods.rb +237 -0
- data/lib/tap/workflow.rb +187 -0
- metadata +145 -0
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'tap/support/batchable_class'
|
2
|
+
|
3
|
+
module Tap
|
4
|
+
module Support
|
5
|
+
|
6
|
+
# Batchable encapsulates the methods used to support batching
|
7
|
+
# of tasks. Classes including Batchable should call <tt>super</tt>
|
8
|
+
# during initialization to initialize batch, or they should
|
9
|
+
# initialize batch themselves.
|
10
|
+
#
|
11
|
+
# See the 'Batches' section in the Tap::Task documentation for
|
12
|
+
# details on how Batchable works in practice.
|
13
|
+
module Batchable
|
14
|
+
|
15
|
+
def self.included(mod)
|
16
|
+
mod.extend Support::BatchableClass if mod.kind_of?(Class)
|
17
|
+
end
|
18
|
+
|
19
|
+
# The object batch.
|
20
|
+
attr_reader :batch
|
21
|
+
|
22
|
+
def initialize(batch=[])
|
23
|
+
@batch = batch
|
24
|
+
@batch << self
|
25
|
+
end
|
26
|
+
|
27
|
+
# Returns true if the batch size is greater than one
|
28
|
+
# (the one being self).
|
29
|
+
def batched?
|
30
|
+
batch.length > 1
|
31
|
+
end
|
32
|
+
|
33
|
+
# Returns the index of the self in batch.
|
34
|
+
def batch_index
|
35
|
+
batch.index(self)
|
36
|
+
end
|
37
|
+
|
38
|
+
# Initializes a new batch object and adds the object to batch.
|
39
|
+
# The object will be a duplicate of self.
|
40
|
+
def initialize_batch_obj
|
41
|
+
obj = self.dup
|
42
|
+
batch << obj
|
43
|
+
obj
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,107 @@
|
|
1
|
+
module Tap
|
2
|
+
module Support
|
3
|
+
|
4
|
+
# BatchableClass encapsulates class methods related to Batchable.
|
5
|
+
module BatchableClass
|
6
|
+
|
7
|
+
# Merges the batches for the specified objects. All objects
|
8
|
+
# sharing the individual object batches will be affected, even
|
9
|
+
# if they are not listed explicitly as an input.
|
10
|
+
#
|
11
|
+
# t1 = Tap::Task.new
|
12
|
+
# t2 = Tap::Task.new
|
13
|
+
# t3 = t2.initialize_batch_obj
|
14
|
+
#
|
15
|
+
# Tap::Task.batch(t1, t2)
|
16
|
+
# t3.batch # => [t1,t2,t3]
|
17
|
+
#
|
18
|
+
# Returns the new batch.
|
19
|
+
def batch(*batchables)
|
20
|
+
merged = []
|
21
|
+
batches = batchables.collect {|batchable| batchable.batch }.uniq
|
22
|
+
batches.each do |batch|
|
23
|
+
merged.concat(batch)
|
24
|
+
batch.clear
|
25
|
+
end
|
26
|
+
merged.uniq!
|
27
|
+
batches.each {|batch| batch.concat(merged) }
|
28
|
+
merged
|
29
|
+
end
|
30
|
+
|
31
|
+
protected
|
32
|
+
|
33
|
+
# Redefines the specified method(s) as batched methods. The existing method
|
34
|
+
# is renamed as <tt>unbatched_method</tt> and <tt>method</tt> redefined to
|
35
|
+
# call <tt>unbatched_method</tt> on each object in the batch.
|
36
|
+
#
|
37
|
+
# def process(one, two)
|
38
|
+
# ...
|
39
|
+
# end
|
40
|
+
# batch_function(:process)
|
41
|
+
#
|
42
|
+
# Is equivalent to:
|
43
|
+
#
|
44
|
+
# def unbatched_process(one, two)
|
45
|
+
# ...
|
46
|
+
# end
|
47
|
+
#
|
48
|
+
# def process(one, two)
|
49
|
+
# batch.each do |t|
|
50
|
+
# t.unbatched_process(one, two)
|
51
|
+
# end
|
52
|
+
# self
|
53
|
+
# end
|
54
|
+
#
|
55
|
+
# The batched method will accept/pass as many arguments as are defined for
|
56
|
+
# the unbatched method. Splats are supported, and blocks are supported too
|
57
|
+
# by passing a block to batch_function:
|
58
|
+
#
|
59
|
+
# def process(arg, *args, &block)
|
60
|
+
# ...
|
61
|
+
# end
|
62
|
+
# batch_function(:process) {}
|
63
|
+
#
|
64
|
+
# Is equivalent to:
|
65
|
+
#
|
66
|
+
# def unbatched_process(arg, *args, &block)
|
67
|
+
# ...
|
68
|
+
# end
|
69
|
+
#
|
70
|
+
# def process(*args, &block)
|
71
|
+
# batch.each do |t|
|
72
|
+
# t.unbatched_process(*args, &block)
|
73
|
+
# end
|
74
|
+
# self
|
75
|
+
# end
|
76
|
+
#
|
77
|
+
# Obviously there are limitations to batch_function, most notably batching
|
78
|
+
# functions with default values. In these cases, batch functionality
|
79
|
+
# must be implemented manually.
|
80
|
+
def batch_function(*methods)
|
81
|
+
methods.each do |method_name|
|
82
|
+
unbatched_method = "unbatched_#{method_name}"
|
83
|
+
if method_defined?(unbatched_method)
|
84
|
+
raise "unbatched method already defined: #{unbatched_method}"
|
85
|
+
end
|
86
|
+
|
87
|
+
arity = instance_method(method_name).arity
|
88
|
+
args = case
|
89
|
+
when arity < 0 then "*args"
|
90
|
+
else Array.new(arity) {|index| "arg#{index}" }.join(", ")
|
91
|
+
end
|
92
|
+
args += ", &block" if block_given?
|
93
|
+
|
94
|
+
class_eval %Q{
|
95
|
+
alias #{unbatched_method} #{method_name}
|
96
|
+
def #{method_name}(#{args})
|
97
|
+
batch.each do |t|
|
98
|
+
t.#{unbatched_method}(#{args})
|
99
|
+
end
|
100
|
+
self
|
101
|
+
end
|
102
|
+
}
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
@@ -0,0 +1,194 @@
|
|
1
|
+
require 'tap/support/assignments'
|
2
|
+
require 'tap/support/instance_configuration'
|
3
|
+
require 'tap/support/configuration'
|
4
|
+
|
5
|
+
module Tap
|
6
|
+
module Support
|
7
|
+
|
8
|
+
# ClassConfiguration tracks and handles the class configurations defined in a
|
9
|
+
# Configurable class.
|
10
|
+
class ClassConfiguration
|
11
|
+
include Enumerable
|
12
|
+
|
13
|
+
# The class receiving new configurations
|
14
|
+
attr_reader :receiver
|
15
|
+
|
16
|
+
# Tracks the assignment of the config keys to receivers
|
17
|
+
attr_reader :assignments
|
18
|
+
|
19
|
+
# A map of config keys and instance methods used to set a
|
20
|
+
# config (ie the reader and writer for a config)
|
21
|
+
attr_reader :map
|
22
|
+
|
23
|
+
def initialize(receiver, parent=nil)
|
24
|
+
@receiver = receiver
|
25
|
+
|
26
|
+
if parent != nil
|
27
|
+
@map = parent.map.inject({}) do |hash, (key, config)|
|
28
|
+
hash[key] = config.dup
|
29
|
+
hash
|
30
|
+
end
|
31
|
+
@assignments = Assignments.new(parent.assignments)
|
32
|
+
else
|
33
|
+
@map = {}
|
34
|
+
@assignments = Assignments.new
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
# Initializes a Configuration using the inputs and sets it in self
|
39
|
+
# using name as a key, overriding the current config by that name,
|
40
|
+
# if it exists. Returns the new config.
|
41
|
+
def add(name, default=nil, attributes={})
|
42
|
+
self[name] = Configuration.new(name.to_sym, default, attributes)
|
43
|
+
end
|
44
|
+
|
45
|
+
# Removes the specified configuration.
|
46
|
+
def remove(key)
|
47
|
+
self[key] = nil
|
48
|
+
end
|
49
|
+
|
50
|
+
# Gets the configuration specified by key. The key is symbolized.
|
51
|
+
def [](key)
|
52
|
+
map[key.to_sym]
|
53
|
+
end
|
54
|
+
|
55
|
+
# Assigns the configuration to key. A nil config unassigns the
|
56
|
+
# configuration key. The key is symbolized.
|
57
|
+
def []=(key, config)
|
58
|
+
key = key.to_sym
|
59
|
+
|
60
|
+
if config == nil
|
61
|
+
assignments.unassign(key)
|
62
|
+
map.delete(key)
|
63
|
+
else
|
64
|
+
assignments.assign(receiver, key) unless assignments.assigned?(key)
|
65
|
+
map[key] = config
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
# Returns true if key is a config key.
|
70
|
+
def key?(key)
|
71
|
+
map.has_key?(key)
|
72
|
+
end
|
73
|
+
|
74
|
+
# Returns all config keys.
|
75
|
+
def keys
|
76
|
+
map.keys
|
77
|
+
end
|
78
|
+
|
79
|
+
# Returns config keys in order.
|
80
|
+
def ordered_keys
|
81
|
+
assignments.values
|
82
|
+
end
|
83
|
+
|
84
|
+
# Returns all mapped configs.
|
85
|
+
def values
|
86
|
+
map.values
|
87
|
+
end
|
88
|
+
|
89
|
+
# True if map is empty.
|
90
|
+
def empty?
|
91
|
+
map.empty?
|
92
|
+
end
|
93
|
+
|
94
|
+
# Calls block once for each [receiver, key, config] in self,
|
95
|
+
# passing those elements as parameters, in the order in
|
96
|
+
# which they were assigned.
|
97
|
+
def each
|
98
|
+
assignments.each do |receiver, key|
|
99
|
+
yield(receiver, key, map[key])
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
# Calls block once for each [key, config] pair in self,
|
104
|
+
# passing those elements as parameters, in the order in
|
105
|
+
# which they were assigned.
|
106
|
+
def each_pair
|
107
|
+
assignments.each do |receiver, key|
|
108
|
+
yield(key, map[key])
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
# Initializes and returns a new InstanceConfiguration set to self
|
113
|
+
# and bound to the receiver, if specified.
|
114
|
+
def instance_config(receiver=nil)
|
115
|
+
InstanceConfiguration.new(self, receiver)
|
116
|
+
end
|
117
|
+
|
118
|
+
# Returns a hash of the (key, config.default) values in self.
|
119
|
+
def to_hash
|
120
|
+
hash = {}
|
121
|
+
each_pair {|key, config| hash[key] = config.default }
|
122
|
+
hash
|
123
|
+
end
|
124
|
+
|
125
|
+
def code_comments
|
126
|
+
code_comments = []
|
127
|
+
values.each do |config|
|
128
|
+
code_comments << config.desc if config.desc.kind_of?(Comment)
|
129
|
+
end
|
130
|
+
code_comments
|
131
|
+
end
|
132
|
+
|
133
|
+
# The path to the :doc template (see format_str)
|
134
|
+
DOC_TEMPLATE_PATH = File.expand_path File.dirname(__FILE__) + "/../generator/generators/config/templates/doc.erb"
|
135
|
+
|
136
|
+
# The path to the :nodoc template (see format_str)
|
137
|
+
NODOC_TEMPLATE_PATH = File.expand_path File.dirname(__FILE__) + "/../generator/generators/config/templates/nodoc.erb"
|
138
|
+
|
139
|
+
# Formats the configurations using the specified template. Two default
|
140
|
+
# templates are defined, <tt>:doc</tt> and <tt>:nodoc</tt>. These map
|
141
|
+
# to the contents of DOC_TEMPLATE_PATH and NODOC_TEMPLATE_PATH and
|
142
|
+
# correspond to the documented and undocumented config generator templates.
|
143
|
+
#
|
144
|
+
# == Custom Templates
|
145
|
+
#
|
146
|
+
# format_str initializes a Templater which formats each [receiver, configurations]
|
147
|
+
# pair in turn, and puts the output to the target using <tt><<</tt>. The
|
148
|
+
# templater is assigned the following attributes for use in formatting:
|
149
|
+
#
|
150
|
+
# receiver:: The receiver
|
151
|
+
# class_doc:: The TDoc for the receiver, from Tap::Support::TDoc[receiver]
|
152
|
+
# configurations:: An array of configurations and associated comments
|
153
|
+
#
|
154
|
+
# In the template these can be accessed as any ERB locals, for example:
|
155
|
+
#
|
156
|
+
# <%= receiver.to_s %>
|
157
|
+
# <% configurations.each do |key, config, comment| %>
|
158
|
+
# ...
|
159
|
+
# <% end %>
|
160
|
+
#
|
161
|
+
# The input template may be a String or an ERB; either may be used to
|
162
|
+
# initialize the templater.
|
163
|
+
def format_str(template=:doc, target="")
|
164
|
+
Lazydoc.resolve(code_comments)
|
165
|
+
|
166
|
+
template = case template
|
167
|
+
when :doc then File.read(DOC_TEMPLATE_PATH)
|
168
|
+
when :nodoc then File.read(NODOC_TEMPLATE_PATH)
|
169
|
+
else template
|
170
|
+
end
|
171
|
+
|
172
|
+
templater = Templater.new(template)
|
173
|
+
assignments.each_pair do |receiver, keys|
|
174
|
+
next if keys.empty?
|
175
|
+
|
176
|
+
# set the template attributes
|
177
|
+
templater.receiver = receiver
|
178
|
+
templater.configurations = keys.collect do |key|
|
179
|
+
# duplicate config so that any changes to it
|
180
|
+
# during templation will not propogate back
|
181
|
+
# into self
|
182
|
+
[key, map[key].dup]
|
183
|
+
end.compact
|
184
|
+
|
185
|
+
yield(templater) if block_given?
|
186
|
+
target << templater.build
|
187
|
+
end
|
188
|
+
|
189
|
+
target
|
190
|
+
end
|
191
|
+
end
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
@@ -0,0 +1,98 @@
|
|
1
|
+
require 'optparse'
|
2
|
+
|
3
|
+
module Tap
|
4
|
+
module Support
|
5
|
+
|
6
|
+
# Under Construction
|
7
|
+
module CommandLine
|
8
|
+
module_function
|
9
|
+
|
10
|
+
# Parses the input string as YAML, if the string matches the YAML document
|
11
|
+
# specifier (ie it begins with "---\s*\n"). Otherwise returns the string.
|
12
|
+
#
|
13
|
+
# str = {'key' => 'value'}.to_yaml # => "--- \nkey: value\n"
|
14
|
+
# Tap::Script.parse_yaml(str) # => {'key' => 'value'}
|
15
|
+
# Tap::Script.parse_yaml("str") # => "str"
|
16
|
+
def parse_yaml(str)
|
17
|
+
str =~ /\A---\s*\n/ ? YAML.load(str) : str
|
18
|
+
end
|
19
|
+
|
20
|
+
SPLIT_ARGV_REGEXP = /\A-{2}(\+*)\z/
|
21
|
+
|
22
|
+
def split(argv)
|
23
|
+
current = []
|
24
|
+
current_split = []
|
25
|
+
splits = [current_split]
|
26
|
+
|
27
|
+
argv.each do |arg|
|
28
|
+
if arg =~ SPLIT_ARGV_REGEXP
|
29
|
+
current_split << current unless current.empty?
|
30
|
+
current = []
|
31
|
+
current_split = (splits[$1.length] ||= [])
|
32
|
+
else
|
33
|
+
current << arg
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
current_split << current unless current.empty?
|
38
|
+
splits.delete_if {|split| split.nil? || split.empty? }
|
39
|
+
splits
|
40
|
+
end
|
41
|
+
|
42
|
+
def shift(argv)
|
43
|
+
index = nil
|
44
|
+
argv.each_with_index do |arg, i|
|
45
|
+
if arg !~ /\A-/
|
46
|
+
index = i
|
47
|
+
break
|
48
|
+
end
|
49
|
+
end
|
50
|
+
index == nil ? nil : argv.delete_at(index)
|
51
|
+
end
|
52
|
+
|
53
|
+
def usage(path, cols=80)
|
54
|
+
parse_usage(File.read(path), cols)
|
55
|
+
end
|
56
|
+
|
57
|
+
def parse_usage(str, cols=80)
|
58
|
+
scanner = StringScanner.new(str)
|
59
|
+
scanner.scan(/^#!.*?$/)
|
60
|
+
Comment.parse(scanner, false).wrap(cols, 2).strip
|
61
|
+
end
|
62
|
+
|
63
|
+
def configv(config)
|
64
|
+
desc = config.desc
|
65
|
+
desc.extend(OptParseComment) if desc.kind_of?(Comment)
|
66
|
+
|
67
|
+
[config.short, argtype(config), desc].compact
|
68
|
+
end
|
69
|
+
|
70
|
+
def argtype(config)
|
71
|
+
case config.arg_type
|
72
|
+
when :optional
|
73
|
+
"#{config.long} [#{config.arg_name}]"
|
74
|
+
when :switch
|
75
|
+
config.long(true)
|
76
|
+
when :flag
|
77
|
+
config.long
|
78
|
+
when :list
|
79
|
+
"#{config.long} a,b,c"
|
80
|
+
when :mandatory, nil
|
81
|
+
"#{config.long} #{config.arg_name}"
|
82
|
+
else
|
83
|
+
raise "unknown arg_type: #{config.arg_type}"
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
module OptParseComment
|
88
|
+
def empty?
|
89
|
+
to_str.empty?
|
90
|
+
end
|
91
|
+
|
92
|
+
def to_str
|
93
|
+
subject.to_s =~ /#(.*)$/ ? $1.strip : ""
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|