Class: Syskit::Models::SpecializationManager::SpecializationBlockContext

Inherits:
BasicObject
Defined in:
lib/syskit/models/specialization_manager.rb

Overview

Class used to give a proper evaluation context to the specialization blocks

Its job is to make sure that the composition that is being modified by the specialization block “looks like” the plain composition plus the specialization, regardless of all the other specializations that have been applied

Defined Under Namespace

Classes: Child

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model, reference_model) ⇒ SpecializationBlockContext

Returns a new instance of SpecializationBlockContext



409
410
411
412
413
# File 'lib/syskit/models/specialization_manager.rb', line 409

def initialize(model, reference_model)
    @model, @reference_model =
        model, reference_model
    @overload_info = ::Hash.new
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m, *args, &block) ⇒ Object



426
427
428
429
430
431
432
433
434
435
436
437
438
# File 'lib/syskit/models/specialization_manager.rb', line 426

def method_missing(m, *args, &block)
    if m =~ /_child$/
        child_name = $`
        if info = overload_info[child_name]
            info
        else
            child = model.public_send(m, *args, &block)
            ref_child = reference_model.public_send(m, *args, &block)
            overload_info[name] = Child.new(child, ref_child)
        end
    else model.send(m, *args, &block)
    end
end

Instance Attribute Details

#modelObject (readonly)

The final composition model (i.e. the one on which the specialization is being applied)



395
396
397
# File 'lib/syskit/models/specialization_manager.rb', line 395

def model
  @model
end

#overload_infoModels::FacetedAccess (readonly)

The overload information



402
403
404
# File 'lib/syskit/models/specialization_manager.rb', line 402

def overload_info
  @overload_info
end

#reference_modelObject (readonly)

The composition model that is made of the root model and only the relevant specialization applied



398
399
400
# File 'lib/syskit/models/specialization_manager.rb', line 398

def reference_model
  @reference_model
end

Instance Method Details

#apply_block(block) ⇒ Object



415
416
417
418
419
420
# File 'lib/syskit/models/specialization_manager.rb', line 415

def apply_block(block)
    if !model.definition_blocks.include?(block)
        instance_eval(&block)
        model.definition_blocks << block
    end
end

#respond_to_missing?(symbol, include_private) ⇒ Boolean

Returns:

  • (Boolean)


422
423
424
# File 'lib/syskit/models/specialization_manager.rb', line 422

def respond_to_missing?(symbol, include_private)
    model.respond_to?(symbol) || super
end