lib/activefacts/generate/absorption.rb in activefacts-0.7.1 vs lib/activefacts/generate/absorption.rb in activefacts-0.7.2
- old
+ new
@@ -12,22 +12,21 @@
# Not currently working, it relies on the old relational composition code.
# Invoke as
# afgen --absorption[=options] <file>.cql"
# Options are comma or space separated:
# * no_columns Don't emit the columns
- # * dependent Show Concepts that are not tables as well
+ # * all Show Concepts that are not tables as well
# * paths Show the references paths through which each column was defined
# * no_identifier Don't show the identified_by columns for an EntityType
class ABSORPTION
include Metamodel
def initialize(vocabulary, *options) #:nodoc:
@vocabulary = vocabulary
@vocabulary = @vocabulary.Vocabulary.values[0] if ActiveFacts::API::Constellation === @vocabulary
@no_columns = options.include? "no_columns"
- @dependent = options.include? "dependent"
@paths = options.include? "paths"
@no_identifier = options.include? "no_identifier"
end
def generate(out = $>) #:nodoc:
@@ -36,42 +35,33 @@
single_absorption_ets = 0
multi_absorption_vts = 0
multi_absorption_ets = 0
@vocabulary.tables
@vocabulary.all_feature.sort_by{|c| c.name}.each do |o|
- # Don't dump imported (base) ValueTypes:
- next if ValueType === o && !o.supertype
+ next if !o.is_table
show(o)
end
end
def show concept #:nodoc:
- return unless concept.is_table || @dependent
-
- print "#{concept.name}"
- print " (#{concept.tentative ? "tentatively " : ""}#{concept.is_table ? "in" : ""}dependent)" if @dependent
-
- if !@no_identifier && concept.is_a?(EntityType)
- print " is identified by:\n\t#{
-"REVISIT" # concept.references_from.to_s
- }"
- end
- print "\n"
-
- unless @no_columns
- puts "#{ concept.references_from.map do |role_ref|
- "\t#{role_ref.column_name(".")}\n"
- end*"" }"
- end
-
- if (@paths)
- ap = concept.absorption_paths
- puts "#{ ap.map {|role|
- prr = role.preferred_reference.describe
- player = role.fact_type.entity_type == concept ? role.concept : (role.fact_type.all_role-[role])[0].concept
- "\tcan absorb #{prr != role.concept.name ? "(via #{prr}) " : "" }into #{player.name}\n"
- }*"" }"
- end
+ indices = concept.indices
+ pk = indices.select(&:is_primary)[0]
+ indices = indices.clone
+ indices.delete pk
+ puts "#{concept.name}: #{
+# "[#{concept.indices.size} indices] "
+# } #{
+ concept.columns.sort_by do |column|
+ column.name(nil)
+ end.map do |column|
+ index_nrs =
+ [pk && pk.columns.include?(column) ? "*" : nil] +
+ (0...indices.size).select{|i| indices[i].columns.include?(column)}.map{|i| (i+1).to_i }
+ index_nrs.compact!
+ (@paths ? column.references.map{|r| r.to_names}.flatten : column.name(nil)) * "." +
+ (index_nrs.empty? ? "" : "["+index_nrs*""+"]")
+ end*", "
+ }"
end
end
end
end