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.
567
568
569
570
571
572
|
# File 'lib/roby/task_arguments.rb', line 567
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
673
674
675
676
677
678
679
|
# File 'lib/roby/task_arguments.rb', line 673
def method_missing(m, *args)
if args.empty? && !block_given?
dup.add_method(m)
else
super
end
end
|
Instance Method Details
#==(other) ⇒ Object
681
682
683
684
685
|
# File 'lib/roby/task_arguments.rb', line 681
def ==(other)
other.kind_of?(DelayedArgumentFromObject) &&
@object.equal?(other.instance_variable_get(:@object)) &&
@methods == other.instance_variable_get(:@methods)
end
|
#__expected_class__ ⇒ Class
The expected class of the resolved argument
The __ markers are used to avoid possible collisions with an actual method
597
598
599
|
# File 'lib/roby/task_arguments.rb', line 597
def __expected_class__
@expected_class
end
|
#__methods__ ⇒ Array<Symbol>
The chain of methods that are called on #__object__ to find the argument
The __ markers are used to avoid possible collisions with an actual method
588
589
590
|
# File 'lib/roby/task_arguments.rb', line 588
def __methods__
@methods.dup
end
|
#__object__ ⇒ Object
The object from which the delayed argument is derived
The __ markers are used to avoid possible collisions with an actual method
579
580
581
|
# File 'lib/roby/task_arguments.rb', line 579
def __object__
@object
end
|
#add_method(m) ⇒ Object
614
615
616
617
|
# File 'lib/roby/task_arguments.rb', line 614
def add_method(m)
@methods += [m]
self
end
|
#can_merge?(task, other_task, other_arg) ⇒ Boolean
619
620
621
622
623
624
625
626
|
# File 'lib/roby/task_arguments.rb', line 619
def can_merge?(task, other_task, other_arg)
catch(:no_value) do
this_evaluated = evaluate_delayed_argument(task)
other_evaluated = other_arg.evaluate_delayed_argument(other_task)
return other_evaluated == this_evaluated
end
false
end
|
#evaluate_delayed_argument(task) ⇒ Object
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
|
# File 'lib/roby/task_arguments.rb', line 639
def evaluate_delayed_argument(task)
result = @methods.inject(@object || task) do |v, m|
if v.kind_of?(Roby::Task) && v.model.has_argument?(m)
unless v.arguments.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
|
#merge(task, other_task, other_arg) ⇒ Object
628
629
630
631
632
633
634
635
636
637
|
# File 'lib/roby/task_arguments.rb', line 628
def merge(task, other_task, other_arg)
case other_arg
when TaskArguments::StaticArgumentWrapper
other_arg.value
else
evaluate_delayed_argument(task)
end
end
|
#of_type(expected_class) ⇒ Object
601
602
603
|
# File 'lib/roby/task_arguments.rb', line 601
def of_type(expected_class)
dup.of_type!(expected_class)
end
|
#of_type!(expected_class) ⇒ Object
605
606
607
608
|
# File 'lib/roby/task_arguments.rb', line 605
def of_type!(expected_class)
@expected_class = expected_class
self
end
|
#pretty_print(pp) ⇒ Object
691
692
693
|
# File 'lib/roby/task_arguments.rb', line 691
def pretty_print(pp)
pp.text to_s
end
|
#strong? ⇒ Boolean
610
611
612
|
# File 'lib/roby/task_arguments.rb', line 610
def strong?
true
end
|
687
688
689
|
# File 'lib/roby/task_arguments.rb', line 687
def to_s
"delayed_argument_from(#{@object || 'task'}.#{@methods.map(&:to_s).join('.')})"
end
|