Sha256: 96bb495bb6071f97cb4bef09bd1e95a1c22b730a3c686a78446c5525ee6bc0aa

Contents?: true

Size: 992 Bytes

Versions: 2

Compression:

Stored size: 992 Bytes

Contents

require 'gecode.so'
module Gecode
  # The Gecode::Raw module is what the interface should use to access methods
  # in Gecode. The actual bindings are located in ::GecodeRaw.
  
  # Describes a layer that delegates to GecodeRaw only after having logged the 
  # call.
  module LoggingLayer #:nodoc:
    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
  
  # We just make Gecode::Raw an alias of the real module.
  Raw = ::GecodeRaw
  # Log all calls via Gecode::Raw.
  #Raw = LoggingLayer
end

Version data entries

2 entries across 2 versions & 2 rubygems

Version Path
gecoder-0.7.1 lib/gecoder/bindings.rb
gecoder-with-gecode-0.7.1 lib/gecoder/bindings.rb