Class: Roby::DelayedArgumentFromObject
Overview
Placeholder that can be used to assign an argument from an object’s attribute, reading the attribute only when the task is started
This will usually not be used directly. One should use Task.from instead
Instance Method Summary
collapse
droby_dump
#droby_dump
Constructor Details
Returns a new instance of DelayedArgumentFromObject.
289
290
291
292
293
294
|
# File 'lib/roby/task_arguments.rb', line 289
def initialize(object, weak = true)
@object = object
@methods = []
@expected_class = Object
@weak = weak
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(m, *args) ⇒ Object
335
336
337
338
339
340
341
342
|
# File 'lib/roby/task_arguments.rb', line 335
def method_missing(m, *args)
if args.empty? && !block_given?
@methods << m
self
else
super
end
end
|
Instance Method Details
#==(other) ⇒ Object
344
345
346
347
348
|
# File 'lib/roby/task_arguments.rb', line 344
def ==(other)
other.kind_of?(DelayedArgumentFromObject) &&
@object.object_id == other.instance_variable_get(:@object).object_id &&
@methods == other.instance_variable_get(:@methods)
end
|
#evaluate_delayed_argument(task) ⇒ Object
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
|
# File 'lib/roby/task_arguments.rb', line 301
def evaluate_delayed_argument(task)
result = @methods.inject(@object || task) do |v, m|
if v.kind_of?(Roby::Task) && v.model.has_argument?(m)
if !v.arguments.has_key?(m)
throw :no_value
end
argument = v.arguments.values[m]
if TaskArguments.delayed_argument?(argument)
argument.evaluate_delayed_argument(v)
else
argument
end
elsif v.respond_to?(m)
begin v.send(m)
rescue Exception
throw :no_value
end
elsif @weak
throw :no_value
else
task.failed_to_start!("#{v} has no method called #{m}")
throw :no_value
end
end
if @expected_class && !result.kind_of?(@expected_class)
throw :no_value
end
result
end
|
#of_type(expected_class) ⇒ Object
296
297
298
299
|
# File 'lib/roby/task_arguments.rb', line 296
def of_type(expected_class)
@expected_class = expected_class
self
end
|
#pretty_print(pp) ⇒ Object
354
355
356
|
# File 'lib/roby/task_arguments.rb', line 354
def pretty_print(pp)
pp.text to_s
end
|
350
351
352
|
# File 'lib/roby/task_arguments.rb', line 350
def to_s
"delayed_argument_from(#{@object || 'task'}.#{@methods.map(&:to_s).join(".")})"
end
|