Sha256: 1e0dc50a49f8f523d26e76f2823e1bb76b94dbebd966afbd12c24a66da748b1e

Contents?: true

Size: 1.78 KB

Versions: 3

Compression:

Stored size: 1.78 KB

Contents

#! /usr/bin/env ruby
#
#       ActiveFacts: Read a Vocabulary (from a NORMA, CQL or other file) and run a generator
#
# Copyright (c) 2009 Clifford Heath. Read the LICENSE file.
#
$:.unshift File.dirname(File.expand_path(__FILE__))+"/../lib"

require 'rubygems'

# Load the ruby debugger before everything else, if requested
if d = ENV['DEBUG'] and d.split(/,/).include?('debug')
  begin
    require 'ruby-debug'
    Debugger.start(:post_mortem => true)        # Stop when an exception is thrown, but before it's rescued
  rescue LoadError
    # Ok, no debugger, tough luck.
  end
end

require 'activefacts'
require 'activefacts/vocabulary'

arg = ARGV.shift

# Load the required generator, or the default "text" generator:
generator = "text"
generator_options = []
if arg =~ /^--([^=]*)(?:=(.*))?/
  generator = $1
  generator_options = ($2||"").split(/,/)
  arg = ARGV.shift
end

output_handler = "activefacts/generate/#{generator.downcase}"
require output_handler
output_class = generator.upcase.gsub(%r{[/\\]+},'::')
output_klass = eval("ActiveFacts::Generate::#{output_class}")
raise "Expected #{output_handler} to define #{output_class}" unless output_klass

# Load the file type input method
arg, *options = *arg.split(/=/)
extension = arg.sub(/\A.*\./,'').downcase
input_handler = "activefacts/input/#{extension}"
require input_handler

input_class = extension.upcase
input_klass = ActiveFacts::Input.const_get(input_class.to_sym)
raise "Expected #{input_handler} to define #{input_class}" unless input_klass

# Read the input file:
begin
  vocabulary = input_klass.readfile(arg, *options)

  # Generate the output:
  output_klass.new(vocabulary, *generator_options).generate if vocabulary
rescue => e
  puts "#{e.message}"
  # puts "\t#{e.backtrace*"\n\t"}"
  puts "\t#{e.backtrace*"\n\t"}" if debug :exception
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
activefacts-0.8.10 bin/afgen
activefacts-0.8.9 bin/afgen
activefacts-0.8.8 bin/afgen