Module: Roby::DirectedRelationSupport
Overview
Base support for relations. It is mixed-in objects that are part of relation networks (like Task and EventGenerator)
Instance Method Summary collapse
-
#add_child_object(child, relation, info = nil) ⇒ Object
Add a new child object in the
relationrelation. -
#add_parent_object(parent, relation, info = nil) ⇒ Object
Add a new parent object in the
relationrelation * #adding_child_object onparentand #adding_parent_object onselfjust before the relation is added * #added_child_object onparentand #added_child_object onselfjust after. -
#check_is_relation(type) ⇒ Object
Raises if
typedoes not look like a relation. -
#related_objects(relation = nil, result = nil) ⇒ Object
Computes and returns the set of objects related with this one (parent or child).
-
#relations ⇒ Object
The array of relations this object is part of.
-
#remove_child_object(child, relation = nil) ⇒ Object
Remove the relation between
selfandchild. -
#remove_children(relation = nil) ⇒ Object
Remove relations where self is a parent.
-
#remove_parent_object(parent, relation = nil) ⇒ Object
Remove relations where
selfis a child. -
#remove_parents(relation = nil) ⇒ Object
Remove all parents of
self. -
#remove_relations(to = nil, relation = nil) ⇒ Object
Remove all relations that point to or come from
toIftois nil, it removes all relations ofself.
Instance Method Details
#add_child_object(child, relation, info = nil) ⇒ Object
Add a new child object in the relation relation. This calls
-
#adding_child_object on
selfand #adding_parent_object onchildjust before the relation is added -
#added_child_object on
selfand #added_parent_object onchildjust after
54 55 56 57 |
# File 'lib/roby/relations.rb', line 54 def add_child_object(child, relation, info = nil) check_is_relation(relation) relation.add_relation(self, child, info) end |
#add_parent_object(parent, relation, info = nil) ⇒ Object
Add a new parent object in the relation relation
-
#adding_child_object on
parentand #adding_parent_object onselfjust before the relation is added -
#added_child_object on
parentand #added_child_object onselfjust after
64 65 66 |
# File 'lib/roby/relations.rb', line 64 def add_parent_object(parent, relation, info = nil) parent.add_child_object(self, relation, info) end |
#check_is_relation(type) ⇒ Object
Raises if type does not look like a relation
151 152 153 154 155 |
# File 'lib/roby/relations.rb', line 151 def check_is_relation(type) # :nodoc: if type && !(RelationGraph === type) raise ArgumentError, "#{type} (of class #{type.class}) is not a relation type" end end |
#related_objects(relation = nil, result = nil) ⇒ Object
Computes and returns the set of objects related with this one (parent or child). If relation is given, enumerate only for this relation, otherwise enumerate for all relations. If result is given, it is a ValueSet in which the related objects are added
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/roby/relations.rb', line 33 def (relation = nil, result = nil) result ||= ValueSet.new if relation result.merge(parent_objects(relation).to_value_set) result.merge(child_objects(relation).to_value_set) else each_relation { |rel| (rel, result) } end result end |
#relations ⇒ Object
The array of relations this object is part of
27 |
# File 'lib/roby/relations.rb', line 27 def relations; enum_relations.to_a end |
#remove_child_object(child, relation = nil) ⇒ Object
Remove the relation between self and child. If relation is given, remove only a relations in this relation kind.
86 87 88 89 90 91 |
# File 'lib/roby/relations.rb', line 86 def remove_child_object(child, relation = nil) check_is_relation(relation) apply_selection(relation, (relation || enum_relations)) do |relation| relation.remove_relation(self, child) end end |
#remove_children(relation = nil) ⇒ Object
Remove relations where self is a parent. If relation is given, remove only the relations in this relation graph.
95 96 97 98 99 100 101 |
# File 'lib/roby/relations.rb', line 95 def remove_children(relation = nil) apply_selection(relation, (relation || enum_relations)) do |relation| self.each_child_object(relation) do |child| remove_child_object(child, relation) end end end |
#remove_parent_object(parent, relation = nil) ⇒ Object
Remove relations where self is a child. If relation is given, remove only the relations in this relation graph
105 106 107 |
# File 'lib/roby/relations.rb', line 105 def remove_parent_object(parent, relation = nil) parent.remove_child_object(self, relation) end |
#remove_parents(relation = nil) ⇒ Object
Remove all parents of self. If relation is given, remove only the parents in this relation graph
110 111 112 113 114 115 116 117 |
# File 'lib/roby/relations.rb', line 110 def remove_parents(relation = nil) check_is_relation(relation) apply_selection(relation, (relation || enum_relations)) do |relation| relation.each_parent_object(self) do |parent| remove_parent_object(relation, parent) end end end |
#remove_relations(to = nil, relation = nil) ⇒ Object
Remove all relations that point to or come from to If to is nil, it removes all relations of self
137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/roby/relations.rb', line 137 def remove_relations(to = nil, relation = nil) check_is_relation(relation) if to remove_parent_object(to, relation) remove_child_object(to, relation) else apply_selection(relation, (relation || enum_relations)) do |relation| each_parent_object(relation) { |parent| remove_parent_object(parent, relation) } each_child_object(relation) { |child| remove_child_object(child, relation) } end end end |