lib/activefacts/generator/summary.rb in activefacts-compositions-1.9.10 vs lib/activefacts/generator/summary.rb in activefacts-compositions-1.9.12
- old
+ new
@@ -1,8 +1,8 @@
#
# ActiveFacts Compositions, Metamodel aspect to create a textual summary of a composition and its Composites
-#
+#
# Copyright (c) 2015 Clifford Heath. Read the LICENSE file.
#
require "activefacts/metamodel"
require "activefacts/compositions/names"
require "activefacts/compositions/constraints"
@@ -11,11 +11,15 @@
module ActiveFacts
module Metamodel
class Composition
def summary
classify_constraints
- "Summary of #{name}\n" +
+
+ vn = (v = constellation.Vocabulary.values[0]) ? v.version_number : nil
+ version_str = vn ? " version #{vn}" : ''
+
+ "Summary of #{name}#{version_str}\n" +
all_composite.
sort_by{|composite| composite.mapping.name}.
flat_map do |composite|
composite.summary
end*''
@@ -33,40 +37,41 @@
reject{|leaf| leaf.is_a?(Absorption) && leaf.forward_absorption}.
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 = case component
- when Indicator
- false
- when Absorption
- component.parent_role.is_mandatory
- else
- true
- end
+ 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 component.all_foreign_key_field.size > 0
"[#{component.name}]"
elsif component.is_a?(Absorption) && component.foreign_key
"{#{component.name}}"
else
component.name
end +
- (is_mandatory ? '' : '?')
- 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|
pos += 1
if part = index.position_in_index(leaf)
a << "#{pos}.#{part}"
end
a
end
- if indexing.empty?
- indexing = ''
+ if indexing.empty?
+ indexing = ''
else
indexing = "[#{indexing*','}]"
end
column_name = leaf.column_name.capwords*' '
@@ -90,16 +95,16 @@
def self.options
{
}
end
- def initialize compositions, options = {}
- @compositions = compositions
+ def initialize composition, options = {}
+ @composition = composition
@options = options
end
def generate
- @compositions.map(&:summary)*"\n\n"
+ @composition.summary
end
end
publish_generator Summary
end
end