Module: Syskit::Models::CompositionSpecialization::Extension
- Defined in:
- lib/syskit/models/composition_specialization.rb
Overview
Additional methods that are mixed in composition specialization models. I.e. composition models created by CompositionModel#specialize
Instance Attribute Summary collapse
-
#root_model ⇒ Object
The root composition model in the specialization chain.
Instance Method Summary collapse
-
#apply_specialization_block(block) ⇒ Object
Applies the specialization block
block
onself
. -
#instanciate_specialization(merged, list) ⇒ Object
Registers a new composition model that is a specialization of
self
. - #is_specialization? ⇒ Boolean
-
#name ⇒ Object
Returns the model name.
- #setup_submodel(submodel, options = Hash.new) ⇒ Object
Instance Attribute Details
#root_model ⇒ Object
The root composition model in the specialization chain
11 12 13 |
# File 'lib/syskit/models/composition_specialization.rb', line 11 def root_model @root_model end |
Instance Method Details
#apply_specialization_block(block) ⇒ Object
Applies the specialization block block
on self
.
If recursive
is true, also applies it on the children of this
particular specialization
Whenever a new specialization block is applied on an existing specialization, calling this method with recursive = true ensures that the block is applied on all specialization models that should have it applied
43 44 45 46 47 48 |
# File 'lib/syskit/models/composition_specialization.rb', line 43 def apply_specialization_block(block) if !definition_blocks.include?(block) instance_eval(&block) definition_blocks << block end end |
#instanciate_specialization(merged, list) ⇒ Object
Registers a new composition model that is a specialization of
self
. The generated model is registered on the root model (not
this one)
53 54 55 56 57 58 59 60 61 |
# File 'lib/syskit/models/composition_specialization.rb', line 53 def instanciate_specialization(merged, list) return super if root_model == self applied_specializations.each do |s| merged.merge(s) end list = list + applied_specializations.to_a root_model.instanciate_specialization(merged, list) end |
#is_specialization? ⇒ Boolean
8 |
# File 'lib/syskit/models/composition_specialization.rb', line 8 def is_specialization?; true end |
#name ⇒ Object
Returns the model name
This is formatted as root_model/child_name.is_a?(specialized_list),other_child.is_a?(…)
20 21 22 23 24 25 26 27 28 |
# File 'lib/syskit/models/composition_specialization.rb', line 20 def name return super if root_model == self specializations = self.specialized_children.map do |child_name, child_models| "#{child_name}.is_a?(#{child_models.map(&:short_name).join(",")})" end "#{root_model.short_name}/#{specializations}" end |
#setup_submodel(submodel, options = Hash.new) ⇒ Object
30 31 32 33 |
# File 'lib/syskit/models/composition_specialization.rb', line 30 def setup_submodel(submodel, = Hash.new) submodel.root_model = submodel super end |