Sha256: 8a75903ed4fed210b51a47562a3e194a9384decd6c121930d97cccd65eac44d2

Contents?: true

Size: 1.53 KB

Versions: 13

Compression:

Stored size: 1.53 KB

Contents

#
#       ActiveFacts Generators.
#       Generate text output (verbalise the meta-vocabulary) for ActiveFacts vocabularies.
#
# Copyright (c) 2009 Clifford Heath. Read the LICENSE file.
#
require 'activefacts/persistence'

module ActiveFacts
  module Generate
    # Generate a text verbalisation of the metamodel constellation created for an ActiveFacts vocabulary.
    # Invoke as
    #   afgen --text <file>.cql
    class RECORDS
    private
      def initialize(vocabulary)
        @vocabulary = vocabulary
        @vocabulary = @vocabulary.Vocabulary.values[0] if ActiveFacts::API::Constellation === @vocabulary
      end

    public
      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
    end
  end
end

ActiveFacts::Registry.generator('records', ActiveFacts::Generate::RECORDS)

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
activefacts-1.6.0 lib/activefacts/generate/records.rb
activefacts-1.5.3 lib/activefacts/generate/records.rb
activefacts-1.5.2 lib/activefacts/generate/records.rb
activefacts-1.5.1 lib/activefacts/generate/records.rb
activefacts-1.5.0 lib/activefacts/generate/records.rb
activefacts-1.3.0 lib/activefacts/generate/records.rb
activefacts-1.2.1 lib/activefacts/generate/records.rb
activefacts-1.2.0 lib/activefacts/generate/records.rb
activefacts-1.1.0 lib/activefacts/generate/records.rb
activefacts-1.0.2 lib/activefacts/generate/records.rb
activefacts-1.0.1 lib/activefacts/generate/records.rb
activefacts-1.0.0 lib/activefacts/generate/records.rb
activefacts-0.8.18 lib/activefacts/generate/records.rb