class ActiveFacts::Metamodel::Composite
Add namespace id to metamodel forward referencing
Attributes
xmiid[RW]
Public Instance Methods
classify_constraints()
click to toggle source
# File lib/activefacts/compositions/constraints.rb, line 61 def classify_constraints leaves = mapping.all_leaf # Categorise and index all constraints not already baked-in to the composition # We recurse down the hierarchy, stopping at any foreign keys all_composite_roles = [] all_composite_constraints = [] constraints_by_leaf = {} mapping.gather_constraints all_composite_roles, all_composite_constraints, constraints_by_leaf all_composite_roles.uniq! all_composite_constraints.uniq! # Spanning constraints constrain some role outside this composite: spanning_constraints = all_composite_constraints.select do |constraint| (constraint.all_constrained_role-all_composite_roles).size > 0 end spanning_constraints.each do |spanning_constraint| constellation.SpanningConstraint(composite: self, spanning_constraint: spanning_constraint) end # Local and leaf constraints are what remains. Extract the leaf constraints: local_constraints = all_composite_constraints - spanning_constraints leaves.each do |leaf| # Find any constraints that affect just this leaf: leaf_constraints = leaf.path.flat_map{|component| Array(constraints_by_leaf[component]) }. select do |constraint| # Does this constraint constrain only this leaf? (constraint.all_constrained_role - leaf.path.flat_map(&:all_role)).size == 0 end leaf_constraints.each do |leaf_constraint| constellation.LeafConstraint(component: leaf, leaf_constraint: leaf_constraint) end local_constraints -= leaf_constraints end local_constraints.each do |local_constraint| constellation.LocalConstraint(composite: self, local_constraint: local_constraint) end end
rails()
click to toggle source
# File lib/activefacts/compositions/traits/rails.rb, line 26 def rails @rails_facet ||= ACTR::Composite.new(self) end
retract_constraint_classifications()
click to toggle source
# File lib/activefacts/compositions/constraints.rb, line 53 def retract_constraint_classifications all_spanning_constraint.to_a.each(&:retract) all_local_constraint.to_a.each(&:retract) mapping.all_leaf.each do |component| component.all_leaf_constraint.to_a.each(&:retract) end end
summary()
click to toggle source
# File lib/activefacts/generator/summary.rb, line 54 def summary indices = self.all_indices_by_rank fks = {} fk_count = 0 ( [mapping.name+"\n"] + mapping. all_leaf. reject{|leaf| leaf.is_a?(Absorption) && leaf.forward_mapping}. flat_map do |leaf| # Build a display of the names in this absorption path, with FK and optional indicators path_names = leaf.path.map do |component| is_mandatory = true is_unique = true case component when Absorption is_mandatory = component.parent_role.is_mandatory is_unique = component.parent_role.is_unique when Indicator is_mandatory = false end # if all_foreign_key.detect{|fk| fk.all_foreign_key_field.detect{|fkf| fkf.component == leaf}} if component.is_a?(Mapping) && component.foreign_key && leaf.all_foreign_key_field.size > 0 fk_number = (fks[component.foreign_key] ||= (fk_count += 1)) "[F#{fk_number}:#{component.name}" elsif component == leaf && leaf.all_foreign_key_field.size > 0 "#{component.name}]" else component.name end + (is_mandatory ? '' : '?') + (is_unique ? '' : '*') end*'->' # Build a symbolic representation of the index participation of this leaf pos = 0 indexing = indices.inject([]) do |a, index| # An index can be both Primary and Natural. Otherwise we show if it's Unique type_str = '' type_str << 'P' if index == primary_index type_str << 'N' if index == natural_index type_str = 'U' if type_str == '' && index.is_unique pos += 1 if part = index.position_in_index(leaf) a << "#{type_str}#{pos}" + (index.all_index_field.size > 1 ? ".#{part}" : "") end a end if indexing.empty? indexing = '' else indexing = "[#{indexing*','}]" end column_name = leaf.column_name.capwords*' ' ["\t#{path_names}#{indexing} as #{column_name.inspect}\n"] + leaf.all_leaf_constraint.map{|leaf_constraint| "\t\t### #{leaf_constraint.leaf_constraint.describe}\n"}.sort end + all_local_constraint.map do |local_constraint| "\t### #{local_constraint.local_constraint.describe}\n" end.sort + all_spanning_constraint.map do |spanning_constraint| "### #{spanning_constraint.spanning_constraint.describe}\n" end.sort )*'' end