Sha256: 55ddb19eccf41356f3104bc07f37c29a0b176d4883dde9330da5dd94066de5e2

Contents?: true

Size: 1.05 KB

Versions: 11

Compression:

Stored size: 1.05 KB

Contents

#
#       ActiveFacts CQL loader.
#       Use Polyglot to patch things so you can *require* a CQL file and have it define a Ruby module.
#
# Copyright (c) 2009 Clifford Heath. Read the LICENSE file.
#
require 'rubygems'
require 'polyglot'
require 'activefacts/support'
require 'activefacts/input/cql'
require 'activefacts/generate/ruby'

module ActiveFacts
  # This class has a load method for Polyglot to tell it how to _require_ a CQL file.
  # The CQL file is parsed to a vocabulary constellation, which is generated
  # to Ruby code and eval'd, making the generated classes available.
  # To make this Loader available, simply
  #   require 'activefacts/cql'
  class CQLLoader
    def self.load(file) #:nodoc:
      debug "Loading #{file}" do
        vocabulary = ActiveFacts::Input::CQL.readfile(file)

        ruby = StringIO.new
        @dumper = ActiveFacts::Generate::RUBY.new(vocabulary.constellation)
        @dumper.generate(ruby)
        ruby.rewind
        eval ruby.read, ::TOPLEVEL_BINDING
      end
    end
  end

  Polyglot.register('cql', CQLLoader)
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
activefacts-0.8.15 lib/activefacts/cql.rb
activefacts-0.8.13 lib/activefacts/cql.rb
activefacts-0.8.12 lib/activefacts/cql.rb
activefacts-0.8.10 lib/activefacts/cql.rb
activefacts-0.8.9 lib/activefacts/cql.rb
activefacts-0.8.8 lib/activefacts/cql.rb
activefacts-0.8.6 lib/activefacts/cql.rb
activefacts-0.8.5 lib/activefacts/cql.rb
activefacts-0.7.3 lib/activefacts/cql.rb
activefacts-0.7.2 lib/activefacts/cql.rb
activefacts-0.7.1 lib/activefacts/cql.rb