Class: ActiveFacts::Generate::RECORDS

Inherits:
Object
  • Object
show all
Defined in:
lib/activefacts/generate/records.rb

Overview

Generate a text verbalisation of the metamodel constellation created for an ActiveFacts vocabulary. Invoke as

afgen --text <file>.cql

Instance Method Summary collapse

Instance Method Details

#generate(out = $>) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/activefacts/generate/records.rb', line 22

def generate(out = $>)
  # Extract the list of tables in the relational mapping of the metamodel
  # We'll use the columns too.
  @metamodel = ActiveFacts::CQL::Compiler.new.compile_file "examples/CQL/Metamodel.cql"
  tables = @metamodel.tables.sort_by{|t| t.name}

  class_names = tables.map{|t| t.name.gsub(/\s/,'')}
  # map{|t| ActiveFacts::Metamodel.const_get(t.name.gsub(/\s/,''))}

  tables.zip(class_names).each do |table, class_name|
    instance_index = @vocabulary.constellation.send(class_name)
    debugger
    next if instance_index.empty?
    out.puts "#{table.name}(#{table.columns.map{|c| c.name}*', '})"
    debugger
    instance_index.each do |key, value|
      out.puts "\t"+value.verbalise
    end
  end
end