lib/gecoder/bindings.rb in gecoder-0.5.0 vs lib/gecoder/bindings.rb in gecoder-0.6.0

- old
+ new

@@ -1,7 +1,34 @@ require 'gecode.so' module Gecode - # The bindings are located in ::GecodeRaw, so we assign that to ::Gecode::Raw. - # This is done because bindings/bindings.rb use ::GecodeRaw and appears to - # have limitations that do not allow using a sub-namespace. + # The Gecode::Raw module is what the interface should use to access methods + # in Gecode. The actual bindings are located in ::GecodeRaw. + + # We just make Gecode::Raw an alias of the real module. Raw = ::GecodeRaw + # Log all calls via Gecode::Raw. + #Raw = ::LoggingLayer + + # Describes a layer that delegates to GecodeRaw only after having logged the + # call. + module LoggingLayer + require 'logger' + + def self.method_missing(name, *args) + logger.info{ "#{name}(#{args.join(', ')})" } + ::GecodeRaw.send(name, *args) + end + + def self.const_missing(name) + ::GecodeRaw.const_get(name) + end + + # Gets the logger, or creates one if none exists. + def self.logger + return @logger unless @logger.nil? + file = open('gecoder.log', File::WRONLY | File::APPEND | File::CREAT) + @logger = ::Logger.new(file) + @logger.datetime_format = "%Y-%m-%d %H:%M:%S" + @logger + end + end end