Module: Roby::Models::PlanObject
- Extended by:
- MetaRuby::Attributes
- Includes:
- MetaRuby::ModelAsClass, Transaction::Proxying::Cache
- Included in:
- PlanObject
- Defined in:
- lib/roby/models/plan_object.rb
Instance Attribute Summary
Attributes included from Transaction::Proxying::Cache
#transaction_forwarder_module, #transaction_proxy_module
Instance Method Summary collapse
-
#child_plan_object(attribute) ⇒ Object
This class method sets up the enclosing class as a child object, with the root object being returned by the given attribute.
-
#finalization_handler ⇒ Array<UnboundMethod>
Set of finalization handlers defined at the model level.
-
#match ⇒ Object
Create a Queries::PlanObjectMatcher.
-
#when_finalized(&block) ⇒ void
Adds a model-level finalization handler, i.e.
Instance Method Details
#child_plan_object(attribute) ⇒ Object
This class method sets up the enclosing class as a child object, with the root object being returned by the given attribute. Task event generators are for instance defined by
class TaskEventGenerator < EventGenerator
# The task this generator belongs to
attr_reader :task
child_plan_object :task
end
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/roby/models/plan_object.rb', line 48 def child_plan_object(attribute) class_eval <<~ATTRIBUTE_ACCESSORS, __FILE__, __LINE__ + 1 def root_object; #{attribute} end def root_object?; false end def owners; #{attribute}.owners end def distribute?; #{attribute}.distribute? end def plan; #{attribute}.plan end def executable?; #{attribute}.executable? end def subscribed?; #{attribute}.subscribed? end def updated?; #{attribute}.updated? end def updated_by?(peer); #{attribute}.updated_by?(peer) end def update_on?(peer); #{attribute}.update_on?(peer) end def updated_peers; #{attribute}.updated_peers end def remotely_useful?; #{attribute}.remotely_useful? end def forget_peer(peer) remove_sibling_for(peer) end def sibling_of(remote_object, peer) if !distribute? raise ArgumentError, "#{self} is local only" end add_sibling_for(peer, remote_object) end private :plan= private :executable= ATTRIBUTE_ACCESSORS end |
#finalization_handler ⇒ Array<UnboundMethod>
Returns set of finalization handlers defined at the model level.
13 14 15 |
# File 'lib/roby/models/plan_object.rb', line 13 inherited_attribute(:finalization_handler, :finalization_handlers) do [] end |
#match ⇒ Object
Create a Queries::PlanObjectMatcher
81 82 83 |
# File 'lib/roby/models/plan_object.rb', line 81 def match Queries::PlanObjectMatcher.new.with_model(self) end |
#when_finalized(&block) ⇒ void
This method returns an undefined value.
Adds a model-level finalization handler, i.e. a handler that will be called on every instance of the class
The block is called in the context of the task that got finalized (i.e. in the block, self is this task)
24 25 26 27 28 |
# File 'lib/roby/models/plan_object.rb', line 24 def when_finalized(&block) method_name = "finalization_handler_#{block.object_id}" define_method(method_name, &block) finalization_handlers << instance_method(method_name) end |