Class: ActiveFacts::Generators::Absorption
- Inherits:
-
Object
- Object
- ActiveFacts::Generators::Absorption
- Defined in:
- lib/activefacts/generators/absorption.rb
Overview
Emit the absorption (Relational summary) for vocabulary. 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
-
all Show ObjectTypes 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
Instance Method Summary collapse
-
#generate(out = $>) ⇒ Object
:nodoc:.
-
#initialize(vocabulary, *options) ⇒ Absorption
constructor
:nodoc:.
-
#show(object_type) ⇒ Object
:nodoc:.
Constructor Details
#initialize(vocabulary, *options) ⇒ Absorption
:nodoc:
24 25 26 27 28 29 30 |
# File 'lib/activefacts/generators/absorption.rb', line 24 def initialize(vocabulary, *) #:nodoc: @vocabulary = vocabulary @vocabulary = @vocabulary.Vocabulary.values[0] if ActiveFacts::API::Constellation === @vocabulary @no_columns = .include? "no_columns" @paths = .include? "paths" @no_identifier = .include? "no_identifier" end |
Instance Method Details
#generate(out = $>) ⇒ Object
:nodoc:
32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/activefacts/generators/absorption.rb', line 32 def generate(out = $>) #:nodoc: @out = out no_absorption = 0 single_absorption_vts = 0 single_absorption_ets = 0 multi_absorption_vts = 0 multi_absorption_ets = 0 @vocabulary.tables @vocabulary.all_object_type.sort_by{|c| c.name}.each do |o| next if !o.is_table show(o) end end |
#show(object_type) ⇒ Object
:nodoc:
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/activefacts/generators/absorption.rb', line 46 def show object_type #:nodoc: indices = object_type.indices pk = indices.select(&:is_primary)[0] indices = indices.clone indices.delete pk @out.puts "#{object_type.name}: #{ # "[#{object_type.indices.size} indices] " # } #{ object_type.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 |