Sha256: e72f5ea047cd033c6d130da97f5b98c94974acd601f05a902a270f35ef0e24c7

Contents?: true

Size: 1.62 KB

Versions: 2

Compression:

Stored size: 1.62 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'
require 'activefacts'
require 'activefacts/vocabulary'

if ENV['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
true # Ok, got the stack set up, continue to the fault

arg = ARGV.shift

# Load the required generator, or the default "text" generator:
generator = "text"
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
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)
rescue => e
  puts "#{e.message}"
  puts "#{e}:\n\t#{e.backtrace*"\n\t"}" if debug
end

# Generate the output:
output_klass.new(vocabulary, *generator_options).generate if vocabulary

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
activefacts-0.8.6 bin/afgen
activefacts-0.8.5 bin/afgen