podoy 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE.txt +21 -0
  3. data/README.md +35 -0
  4. data/Rakefile +4 -0
  5. data/lib/podoy/version.rb +5 -0
  6. data/lib/podoy.rb +8 -0
  7. data/sig/podoy.rbs +4 -0
  8. data/vendor/bundle/ruby/3.3.0+0/bin/rake +29 -0
  9. data/vendor/bundle/ruby/3.3.0+0/cache/rake-13.1.0.gem +0 -0
  10. data/vendor/bundle/ruby/3.3.0+0/gems/rake-13.1.0/History.rdoc +2403 -0
  11. data/vendor/bundle/ruby/3.3.0+0/gems/rake-13.1.0/MIT-LICENSE +21 -0
  12. data/vendor/bundle/ruby/3.3.0+0/gems/rake-13.1.0/README.rdoc +155 -0
  13. data/vendor/bundle/ruby/3.3.0+0/gems/rake-13.1.0/doc/command_line_usage.rdoc +158 -0
  14. data/vendor/bundle/ruby/3.3.0+0/gems/rake-13.1.0/doc/example/Rakefile1 +38 -0
  15. data/vendor/bundle/ruby/3.3.0+0/gems/rake-13.1.0/doc/example/Rakefile2 +35 -0
  16. data/vendor/bundle/ruby/3.3.0+0/gems/rake-13.1.0/doc/example/a.c +6 -0
  17. data/vendor/bundle/ruby/3.3.0+0/gems/rake-13.1.0/doc/example/b.c +6 -0
  18. data/vendor/bundle/ruby/3.3.0+0/gems/rake-13.1.0/doc/example/main.c +11 -0
  19. data/vendor/bundle/ruby/3.3.0+0/gems/rake-13.1.0/doc/glossary.rdoc +42 -0
  20. data/vendor/bundle/ruby/3.3.0+0/gems/rake-13.1.0/doc/jamis.rb +592 -0
  21. data/vendor/bundle/ruby/3.3.0+0/gems/rake-13.1.0/doc/proto_rake.rdoc +127 -0
  22. data/vendor/bundle/ruby/3.3.0+0/gems/rake-13.1.0/doc/rake.1 +156 -0
  23. data/vendor/bundle/ruby/3.3.0+0/gems/rake-13.1.0/doc/rakefile.rdoc +622 -0
  24. data/vendor/bundle/ruby/3.3.0+0/gems/rake-13.1.0/doc/rational.rdoc +151 -0
  25. data/vendor/bundle/ruby/3.3.0+0/gems/rake-13.1.0/exe/rake +27 -0
  26. data/vendor/bundle/ruby/3.3.0+0/gems/rake-13.1.0/lib/rake/application.rb +855 -0
  27. data/vendor/bundle/ruby/3.3.0+0/gems/rake-13.1.0/lib/rake/backtrace.rb +24 -0
  28. data/vendor/bundle/ruby/3.3.0+0/gems/rake-13.1.0/lib/rake/clean.rb +78 -0
  29. data/vendor/bundle/ruby/3.3.0+0/gems/rake-13.1.0/lib/rake/cloneable.rb +17 -0
  30. data/vendor/bundle/ruby/3.3.0+0/gems/rake-13.1.0/lib/rake/cpu_counter.rb +107 -0
  31. data/vendor/bundle/ruby/3.3.0+0/gems/rake-13.1.0/lib/rake/default_loader.rb +15 -0
  32. data/vendor/bundle/ruby/3.3.0+0/gems/rake-13.1.0/lib/rake/dsl_definition.rb +195 -0
  33. data/vendor/bundle/ruby/3.3.0+0/gems/rake-13.1.0/lib/rake/early_time.rb +22 -0
  34. data/vendor/bundle/ruby/3.3.0+0/gems/rake-13.1.0/lib/rake/ext/core.rb +26 -0
  35. data/vendor/bundle/ruby/3.3.0+0/gems/rake-13.1.0/lib/rake/ext/string.rb +176 -0
  36. data/vendor/bundle/ruby/3.3.0+0/gems/rake-13.1.0/lib/rake/file_creation_task.rb +25 -0
  37. data/vendor/bundle/ruby/3.3.0+0/gems/rake-13.1.0/lib/rake/file_list.rb +435 -0
  38. data/vendor/bundle/ruby/3.3.0+0/gems/rake-13.1.0/lib/rake/file_task.rb +58 -0
  39. data/vendor/bundle/ruby/3.3.0+0/gems/rake-13.1.0/lib/rake/file_utils.rb +132 -0
  40. data/vendor/bundle/ruby/3.3.0+0/gems/rake-13.1.0/lib/rake/file_utils_ext.rb +134 -0
  41. data/vendor/bundle/ruby/3.3.0+0/gems/rake-13.1.0/lib/rake/invocation_chain.rb +57 -0
  42. data/vendor/bundle/ruby/3.3.0+0/gems/rake-13.1.0/lib/rake/invocation_exception_mixin.rb +17 -0
  43. data/vendor/bundle/ruby/3.3.0+0/gems/rake-13.1.0/lib/rake/late_time.rb +18 -0
  44. data/vendor/bundle/ruby/3.3.0+0/gems/rake-13.1.0/lib/rake/linked_list.rb +112 -0
  45. data/vendor/bundle/ruby/3.3.0+0/gems/rake-13.1.0/lib/rake/loaders/makefile.rb +54 -0
  46. data/vendor/bundle/ruby/3.3.0+0/gems/rake-13.1.0/lib/rake/multi_task.rb +14 -0
  47. data/vendor/bundle/ruby/3.3.0+0/gems/rake-13.1.0/lib/rake/name_space.rb +38 -0
  48. data/vendor/bundle/ruby/3.3.0+0/gems/rake-13.1.0/lib/rake/packagetask.rb +222 -0
  49. data/vendor/bundle/ruby/3.3.0+0/gems/rake-13.1.0/lib/rake/phony.rb +16 -0
  50. data/vendor/bundle/ruby/3.3.0+0/gems/rake-13.1.0/lib/rake/private_reader.rb +21 -0
  51. data/vendor/bundle/ruby/3.3.0+0/gems/rake-13.1.0/lib/rake/promise.rb +100 -0
  52. data/vendor/bundle/ruby/3.3.0+0/gems/rake-13.1.0/lib/rake/pseudo_status.rb +30 -0
  53. data/vendor/bundle/ruby/3.3.0+0/gems/rake-13.1.0/lib/rake/rake_module.rb +67 -0
  54. data/vendor/bundle/ruby/3.3.0+0/gems/rake-13.1.0/lib/rake/rake_test_loader.rb +27 -0
  55. data/vendor/bundle/ruby/3.3.0+0/gems/rake-13.1.0/lib/rake/rule_recursion_overflow_error.rb +20 -0
  56. data/vendor/bundle/ruby/3.3.0+0/gems/rake-13.1.0/lib/rake/scope.rb +43 -0
  57. data/vendor/bundle/ruby/3.3.0+0/gems/rake-13.1.0/lib/rake/task.rb +434 -0
  58. data/vendor/bundle/ruby/3.3.0+0/gems/rake-13.1.0/lib/rake/task_argument_error.rb +8 -0
  59. data/vendor/bundle/ruby/3.3.0+0/gems/rake-13.1.0/lib/rake/task_arguments.rb +109 -0
  60. data/vendor/bundle/ruby/3.3.0+0/gems/rake-13.1.0/lib/rake/task_manager.rb +331 -0
  61. data/vendor/bundle/ruby/3.3.0+0/gems/rake-13.1.0/lib/rake/tasklib.rb +12 -0
  62. data/vendor/bundle/ruby/3.3.0+0/gems/rake-13.1.0/lib/rake/testtask.rb +189 -0
  63. data/vendor/bundle/ruby/3.3.0+0/gems/rake-13.1.0/lib/rake/thread_history_display.rb +49 -0
  64. data/vendor/bundle/ruby/3.3.0+0/gems/rake-13.1.0/lib/rake/thread_pool.rb +163 -0
  65. data/vendor/bundle/ruby/3.3.0+0/gems/rake-13.1.0/lib/rake/trace_output.rb +23 -0
  66. data/vendor/bundle/ruby/3.3.0+0/gems/rake-13.1.0/lib/rake/version.rb +10 -0
  67. data/vendor/bundle/ruby/3.3.0+0/gems/rake-13.1.0/lib/rake/win32.rb +51 -0
  68. data/vendor/bundle/ruby/3.3.0+0/gems/rake-13.1.0/lib/rake.rb +71 -0
  69. data/vendor/bundle/ruby/3.3.0+0/gems/rake-13.1.0/rake.gemspec +101 -0
  70. data/vendor/bundle/ruby/3.3.0+0/specifications/rake-13.1.0.gemspec +26 -0
  71. metadata +117 -0
@@ -0,0 +1,434 @@
1
+ # frozen_string_literal: true
2
+ require "rake/invocation_exception_mixin"
3
+
4
+ module Rake
5
+
6
+ ##
7
+ # A Task is the basic unit of work in a Rakefile. Tasks have associated
8
+ # actions (possibly more than one) and a list of prerequisites. When
9
+ # invoked, a task will first ensure that all of its prerequisites have an
10
+ # opportunity to run and then it will execute its own actions.
11
+ #
12
+ # Tasks are not usually created directly using the new method, but rather
13
+ # use the +file+ and +task+ convenience methods.
14
+ #
15
+ class Task
16
+ # List of prerequisites for a task.
17
+ attr_reader :prerequisites
18
+ alias prereqs prerequisites
19
+
20
+ # List of order only prerequisites for a task.
21
+ attr_reader :order_only_prerequisites
22
+
23
+ # List of actions attached to a task.
24
+ attr_reader :actions
25
+
26
+ # Application owning this task.
27
+ attr_accessor :application
28
+
29
+ # Array of nested namespaces names used for task lookup by this task.
30
+ attr_reader :scope
31
+
32
+ # File/Line locations of each of the task definitions for this
33
+ # task (only valid if the task was defined with the detect
34
+ # location option set).
35
+ attr_reader :locations
36
+
37
+ # Has this task already been invoked? Already invoked tasks
38
+ # will be skipped unless you reenable them.
39
+ attr_reader :already_invoked
40
+
41
+ # Return task name
42
+ def to_s
43
+ name
44
+ end
45
+
46
+ def inspect # :nodoc:
47
+ "<#{self.class} #{name} => [#{prerequisites.join(', ')}]>"
48
+ end
49
+
50
+ # List of sources for task.
51
+ attr_writer :sources
52
+ def sources
53
+ if defined?(@sources)
54
+ @sources
55
+ else
56
+ prerequisites
57
+ end
58
+ end
59
+
60
+ # List of prerequisite tasks
61
+ def prerequisite_tasks
62
+ (prerequisites + order_only_prerequisites).map { |pre| lookup_prerequisite(pre) }
63
+ end
64
+
65
+ def lookup_prerequisite(prerequisite_name) # :nodoc:
66
+ scoped_prerequisite_task = application[prerequisite_name, @scope]
67
+ if scoped_prerequisite_task == self
68
+ unscoped_prerequisite_task = application[prerequisite_name]
69
+ end
70
+ unscoped_prerequisite_task || scoped_prerequisite_task
71
+ end
72
+ private :lookup_prerequisite
73
+
74
+ # List of all unique prerequisite tasks including prerequisite tasks'
75
+ # prerequisites.
76
+ # Includes self when cyclic dependencies are found.
77
+ def all_prerequisite_tasks
78
+ seen = {}
79
+ collect_prerequisites(seen)
80
+ seen.values
81
+ end
82
+
83
+ def collect_prerequisites(seen) # :nodoc:
84
+ prerequisite_tasks.each do |pre|
85
+ next if seen[pre.name]
86
+ seen[pre.name] = pre
87
+ pre.collect_prerequisites(seen)
88
+ end
89
+ end
90
+ protected :collect_prerequisites
91
+
92
+ # First source from a rule (nil if no sources)
93
+ def source
94
+ sources.first
95
+ end
96
+
97
+ # Create a task named +task_name+ with no actions or prerequisites. Use
98
+ # +enhance+ to add actions and prerequisites.
99
+ def initialize(task_name, app)
100
+ @name = task_name.to_s
101
+ @prerequisites = []
102
+ @actions = []
103
+ @already_invoked = false
104
+ @comments = []
105
+ @lock = Monitor.new
106
+ @application = app
107
+ @scope = app.current_scope
108
+ @arg_names = nil
109
+ @locations = []
110
+ @invocation_exception = nil
111
+ @order_only_prerequisites = []
112
+ end
113
+
114
+ # Enhance a task with prerequisites or actions. Returns self.
115
+ def enhance(deps=nil, &block)
116
+ @prerequisites |= deps if deps
117
+ @actions << block if block_given?
118
+ self
119
+ end
120
+
121
+ # Name of the task, including any namespace qualifiers.
122
+ def name
123
+ @name.to_s
124
+ end
125
+
126
+ # Name of task with argument list description.
127
+ def name_with_args # :nodoc:
128
+ if arg_description
129
+ "#{name}#{arg_description}"
130
+ else
131
+ name
132
+ end
133
+ end
134
+
135
+ # Argument description (nil if none).
136
+ def arg_description # :nodoc:
137
+ @arg_names ? "[#{arg_names.join(',')}]" : nil
138
+ end
139
+
140
+ # Name of arguments for this task.
141
+ def arg_names
142
+ @arg_names || []
143
+ end
144
+
145
+ # Reenable the task, allowing its tasks to be executed if the task
146
+ # is invoked again.
147
+ def reenable
148
+ @already_invoked = false
149
+ @invocation_exception = nil
150
+ end
151
+
152
+ # Clear the existing prerequisites, actions, comments, and arguments of a rake task.
153
+ def clear
154
+ clear_prerequisites
155
+ clear_actions
156
+ clear_comments
157
+ clear_args
158
+ self
159
+ end
160
+
161
+ # Clear the existing prerequisites of a rake task.
162
+ def clear_prerequisites
163
+ prerequisites.clear
164
+ self
165
+ end
166
+
167
+ # Clear the existing actions on a rake task.
168
+ def clear_actions
169
+ actions.clear
170
+ self
171
+ end
172
+
173
+ # Clear the existing comments on a rake task.
174
+ def clear_comments
175
+ @comments = []
176
+ self
177
+ end
178
+
179
+ # Clear the existing arguments on a rake task.
180
+ def clear_args
181
+ @arg_names = nil
182
+ self
183
+ end
184
+
185
+ # Invoke the task if it is needed. Prerequisites are invoked first.
186
+ def invoke(*args)
187
+ task_args = TaskArguments.new(arg_names, args)
188
+ invoke_with_call_chain(task_args, InvocationChain::EMPTY)
189
+ end
190
+
191
+ # Same as invoke, but explicitly pass a call chain to detect
192
+ # circular dependencies.
193
+ #
194
+ # If multiple tasks depend on this
195
+ # one in parallel, they will all fail if the first execution of
196
+ # this task fails.
197
+ def invoke_with_call_chain(task_args, invocation_chain)
198
+ new_chain = Rake::InvocationChain.append(self, invocation_chain)
199
+ @lock.synchronize do
200
+ begin
201
+ if application.options.trace
202
+ application.trace "** Invoke #{name} #{format_trace_flags}"
203
+ end
204
+
205
+ if @already_invoked
206
+ if @invocation_exception
207
+ if application.options.trace
208
+ application.trace "** Previous invocation of #{name} failed #{format_trace_flags}"
209
+ end
210
+ raise @invocation_exception
211
+ else
212
+ return
213
+ end
214
+ end
215
+
216
+ @already_invoked = true
217
+
218
+ invoke_prerequisites(task_args, new_chain)
219
+ execute(task_args) if needed?
220
+ rescue Exception => ex
221
+ add_chain_to(ex, new_chain)
222
+ @invocation_exception = ex
223
+ raise ex
224
+ end
225
+ end
226
+ end
227
+ protected :invoke_with_call_chain
228
+
229
+ def add_chain_to(exception, new_chain) # :nodoc:
230
+ exception.extend(InvocationExceptionMixin) unless
231
+ exception.respond_to?(:chain)
232
+ exception.chain = new_chain if exception.chain.nil?
233
+ end
234
+ private :add_chain_to
235
+
236
+ # Invoke all the prerequisites of a task.
237
+ def invoke_prerequisites(task_args, invocation_chain) # :nodoc:
238
+ if application.options.always_multitask
239
+ invoke_prerequisites_concurrently(task_args, invocation_chain)
240
+ else
241
+ prerequisite_tasks.each { |p|
242
+ prereq_args = task_args.new_scope(p.arg_names)
243
+ p.invoke_with_call_chain(prereq_args, invocation_chain)
244
+ }
245
+ end
246
+ end
247
+
248
+ # Invoke all the prerequisites of a task in parallel.
249
+ def invoke_prerequisites_concurrently(task_args, invocation_chain)# :nodoc:
250
+ futures = prerequisite_tasks.map do |p|
251
+ prereq_args = task_args.new_scope(p.arg_names)
252
+ application.thread_pool.future(p) do |r|
253
+ r.invoke_with_call_chain(prereq_args, invocation_chain)
254
+ end
255
+ end
256
+ # Iterate in reverse to improve performance related to thread waiting and switching
257
+ futures.reverse_each(&:value)
258
+ end
259
+
260
+ # Format the trace flags for display.
261
+ def format_trace_flags
262
+ flags = []
263
+ flags << "first_time" unless @already_invoked
264
+ flags << "not_needed" unless needed?
265
+ flags.empty? ? "" : "(" + flags.join(", ") + ")"
266
+ end
267
+ private :format_trace_flags
268
+
269
+ # Execute the actions associated with this task.
270
+ def execute(args=nil)
271
+ args ||= EMPTY_TASK_ARGS
272
+ if application.options.dryrun
273
+ application.trace "** Execute (dry run) #{name}"
274
+ return
275
+ end
276
+ application.trace "** Execute #{name}" if application.options.trace
277
+ application.enhance_with_matching_rule(name) if @actions.empty?
278
+ if opts = Hash.try_convert(args) and !opts.empty?
279
+ @actions.each { |act| act.call(self, args, **opts) }
280
+ else
281
+ @actions.each { |act| act.call(self, args) }
282
+ end
283
+ end
284
+
285
+ # Is this task needed?
286
+ def needed?
287
+ true
288
+ end
289
+
290
+ # Timestamp for this task. Basic tasks return the current time for their
291
+ # time stamp. Other tasks can be more sophisticated.
292
+ def timestamp
293
+ Time.now
294
+ end
295
+
296
+ # Add a description to the task. The description can consist of an option
297
+ # argument list (enclosed brackets) and an optional comment.
298
+ def add_description(description)
299
+ return unless description
300
+ comment = description.strip
301
+ add_comment(comment) if comment && !comment.empty?
302
+ end
303
+
304
+ def comment=(comment) # :nodoc:
305
+ add_comment(comment)
306
+ end
307
+
308
+ def add_comment(comment) # :nodoc:
309
+ return if comment.nil?
310
+ @comments << comment unless @comments.include?(comment)
311
+ end
312
+ private :add_comment
313
+
314
+ # Full collection of comments. Multiple comments are separated by
315
+ # newlines.
316
+ def full_comment
317
+ transform_comments("\n")
318
+ end
319
+
320
+ # First line (or sentence) of all comments. Multiple comments are
321
+ # separated by a "/".
322
+ def comment
323
+ transform_comments(" / ") { |c| first_sentence(c) }
324
+ end
325
+
326
+ # Transform the list of comments as specified by the block and
327
+ # join with the separator.
328
+ def transform_comments(separator, &block)
329
+ if @comments.empty?
330
+ nil
331
+ else
332
+ block ||= lambda { |c| c }
333
+ @comments.map(&block).join(separator)
334
+ end
335
+ end
336
+ private :transform_comments
337
+
338
+ # Get the first sentence in a string. The sentence is terminated
339
+ # by the first period, exclamation mark, or the end of the line.
340
+ # Decimal points do not count as periods.
341
+ def first_sentence(string)
342
+ string.split(/(?<=\w)(\.|!)[ \t]|(\.$|!)|\n/).first
343
+ end
344
+ private :first_sentence
345
+
346
+ # Set the names of the arguments for this task. +args+ should be
347
+ # an array of symbols, one for each argument name.
348
+ def set_arg_names(args)
349
+ @arg_names = args.map(&:to_sym)
350
+ end
351
+
352
+ # Return a string describing the internal state of a task. Useful for
353
+ # debugging.
354
+ def investigation
355
+ result = "------------------------------\n".dup
356
+ result << "Investigating #{name}\n"
357
+ result << "class: #{self.class}\n"
358
+ result << "task needed: #{needed?}\n"
359
+ result << "timestamp: #{timestamp}\n"
360
+ result << "pre-requisites: \n"
361
+ prereqs = prerequisite_tasks
362
+ prereqs.sort! { |a, b| a.timestamp <=> b.timestamp }
363
+ prereqs.each do |p|
364
+ result << "--#{p.name} (#{p.timestamp})\n"
365
+ end
366
+ latest_prereq = prerequisite_tasks.map(&:timestamp).max
367
+ result << "latest-prerequisite time: #{latest_prereq}\n"
368
+ result << "................................\n\n"
369
+ return result
370
+ end
371
+
372
+ # Format dependencies parameter to pass to task.
373
+ def self.format_deps(deps)
374
+ deps = [deps] unless deps.respond_to?(:to_ary)
375
+ deps.map { |d| Rake.from_pathname(d).to_s }
376
+ end
377
+
378
+ # Add order only dependencies.
379
+ def |(deps)
380
+ @order_only_prerequisites |= Task.format_deps(deps) - @prerequisites
381
+ self
382
+ end
383
+
384
+ # ----------------------------------------------------------------
385
+ # Rake Module Methods
386
+ #
387
+ class << self
388
+
389
+ # Clear the task list. This cause rake to immediately forget all the
390
+ # tasks that have been assigned. (Normally used in the unit tests.)
391
+ def clear
392
+ Rake.application.clear
393
+ end
394
+
395
+ # List of all defined tasks.
396
+ def tasks
397
+ Rake.application.tasks
398
+ end
399
+
400
+ # Return a task with the given name. If the task is not currently
401
+ # known, try to synthesize one from the defined rules. If no rules are
402
+ # found, but an existing file matches the task name, assume it is a file
403
+ # task with no dependencies or actions.
404
+ def [](task_name)
405
+ Rake.application[task_name]
406
+ end
407
+
408
+ # TRUE if the task name is already defined.
409
+ def task_defined?(task_name)
410
+ Rake.application.lookup(task_name) != nil
411
+ end
412
+
413
+ # Define a task given +args+ and an option block. If a rule with the
414
+ # given name already exists, the prerequisites and actions are added to
415
+ # the existing task. Returns the defined task.
416
+ def define_task(*args, &block)
417
+ Rake.application.define_task(self, *args, &block)
418
+ end
419
+
420
+ # Define a rule for synthesizing tasks.
421
+ def create_rule(*args, &block)
422
+ Rake.application.create_rule(*args, &block)
423
+ end
424
+
425
+ # Apply the scope to the task name according to the rules for
426
+ # this kind of task. Generic tasks will accept the scope as
427
+ # part of the name.
428
+ def scope_name(scope, task_name)
429
+ scope.path_with_task_name(task_name)
430
+ end
431
+
432
+ end # class << Rake::Task
433
+ end # class Rake::Task
434
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+ module Rake
3
+
4
+ # Error indicating an ill-formed task declaration.
5
+ class TaskArgumentError < ArgumentError
6
+ end
7
+
8
+ end
@@ -0,0 +1,109 @@
1
+ # frozen_string_literal: true
2
+ module Rake
3
+
4
+ ##
5
+ # TaskArguments manage the arguments passed to a task.
6
+ #
7
+ class TaskArguments
8
+ include Enumerable
9
+
10
+ # Argument names
11
+ attr_reader :names
12
+
13
+ # Create a TaskArgument object with a list of argument +names+ and a set
14
+ # of associated +values+. +parent+ is the parent argument object.
15
+ def initialize(names, values, parent=nil)
16
+ @names = names
17
+ @parent = parent
18
+ @hash = {}
19
+ @values = values
20
+ names.each_with_index { |name, i|
21
+ next if values[i].nil? || values[i] == ""
22
+ @hash[name.to_sym] = values[i]
23
+ }
24
+ end
25
+
26
+ # Retrieve the complete array of sequential values
27
+ def to_a
28
+ @values.dup
29
+ end
30
+
31
+ # Retrieve the list of values not associated with named arguments
32
+ def extras
33
+ @values[@names.length..-1] || []
34
+ end
35
+
36
+ # Create a new argument scope using the prerequisite argument
37
+ # names.
38
+ def new_scope(names)
39
+ values = names.map { |n| self[n] }
40
+ self.class.new(names, values + extras, self)
41
+ end
42
+
43
+ # Find an argument value by name or index.
44
+ def [](index)
45
+ lookup(index.to_sym)
46
+ end
47
+
48
+ # Specify a hash of default values for task arguments. Use the
49
+ # defaults only if there is no specific value for the given
50
+ # argument.
51
+ def with_defaults(defaults)
52
+ @hash = defaults.merge(@hash)
53
+ end
54
+
55
+ # Enumerates the arguments and their values
56
+ def each(&block)
57
+ @hash.each(&block)
58
+ end
59
+
60
+ # Extracts the argument values at +keys+
61
+ def values_at(*keys)
62
+ keys.map { |k| lookup(k) }
63
+ end
64
+
65
+ # Returns the value of the given argument via method_missing
66
+ def method_missing(sym, *args)
67
+ lookup(sym.to_sym)
68
+ end
69
+
70
+ # Returns a Hash of arguments and their values
71
+ def to_hash
72
+ @hash.dup
73
+ end
74
+
75
+ def to_s # :nodoc:
76
+ inspect
77
+ end
78
+
79
+ def inspect # :nodoc:
80
+ inspection = @hash.map do |k,v|
81
+ "#{k.to_s}: #{v.to_s}"
82
+ end.join(", ")
83
+
84
+ "#<#{self.class} #{inspection}>"
85
+ end
86
+
87
+ # Returns true if +key+ is one of the arguments
88
+ def has_key?(key)
89
+ @hash.has_key?(key)
90
+ end
91
+ alias key? has_key?
92
+
93
+ def fetch(*args, &block)
94
+ @hash.fetch(*args, &block)
95
+ end
96
+
97
+ protected
98
+
99
+ def lookup(name) # :nodoc:
100
+ if @hash.has_key?(name)
101
+ @hash[name]
102
+ elsif @parent
103
+ @parent.lookup(name)
104
+ end
105
+ end
106
+ end
107
+
108
+ EMPTY_TASK_ARGS = TaskArguments.new([], []) # :nodoc:
109
+ end