Class RGen::Fragment::ModelFragment
In: lib/rgen/fragment/model_fragment.rb
Parent: Object

A model fragment is a list of root model elements associated with a location (e.g. a file). It also stores a list of unresolved references as well as a list of unresolved references which have been resolved. Using the latter, a fragment can undo reference resolution.

Optionally, an arbitrary data object may be associated with the fragment. The data object will also be stored in the cache.

If an element within the fragment changes this must be indicated to the fragment by calling mark_changed.

Note: the fragment knows how to resolve references (resolve_local, resolve_external). However considering a fragment a data structure, this functionality might be removed in the future. Instead the fragment should be told about each resolution taking place. Use method mark_resolved for this purpose.

Methods

Classes and Modules

Class RGen::Fragment::ModelFragment::FragmentRef
Class RGen::Fragment::ModelFragment::ResolvedReference

Attributes

data  [RW] 
fragment_ref  [RW] 
location  [RW] 
root_elements  [R] 

Public Class methods

Create a model fragment

 :data
   data object associated with this fragment

 :identifier_provider
   identifier provider to be used when resolving references
   it must be a proc which receives a model element and must return
   that element's identifier or nil if the element has no identifier

Public Instance methods

Builds the index of all elements within this fragment having an identifier the index is an array of 2-element arrays holding the identifier and the element

Indicates whether the fragment has been changed or not

Returns all elements within this fragment

Returns the index of the element contained in this fragment.

Must be called when any of the elements in this fragment has been changed

Marks a particular unresolved reference uref as resolved to target in target_fragment.

Can be used to reset the change status to unchanged.

Resolves references to external fragments using the external_index provided. The external index must be a Hash mapping identifiers uniquely to model elements.

Options:

 :fragment_provider:
   If a +fragment_provider+ is given, the resolve step can be reverted later on
   by a call to unresolve_external or unresolve_external_fragment. The fragment provider
   is a proc which receives a model element and must return the fragment in which it is
   contained.

 :use_target_type:
   reference resolver uses the expected target type to narrow the set of possible targets

Resolves local references (within this fragment) as far as possible

Options:

 :use_target_type:
   reference resolver uses the expected target type to narrow the set of possible targets

Set the root elements, normally done by an instantiator.

For optimization reasons the instantiator of the fragment may provide data explicitly which is normally derived by the fragment itself. In this case it is essential that this data is consistent with the fragment.

Unresolve outgoing references to all external fragments, i.e. references which used to be represented by an unresolved reference from within this fragment. Note, that there may be more references to external fragments due to references which were represented by unresolved references from within other fragments.

Like unresolve_external but only unresolve references to external fragment fragment

Turns resolved references rrefs back into unresolved references

Returns all unresolved references within this fragment, i.e. references to MMProxy objects

[Validate]