Sha256: d48df52f60fce3ade2ee3b7368678e1afb6bc5610813ac8c09faac131e85a040

Contents?: true

Size: 1.55 KB

Versions: 1

Compression:

Stored size: 1.55 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 if debug :exception
  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

1 entries across 1 versions & 1 rubygems

Version Path
activefacts-0.7.3 bin/afgen