Sha256: 0deb87f6940f6d60ab720bb26036079353d225c87147d631b7852eed4f7ddbbc

Contents?: true

Size: 983 Bytes

Versions: 2

Compression:

Stored size: 983 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
    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 & 1 rubygems

Version Path
gecoder-0.6.1 lib/gecoder/bindings.rb
gecoder-0.7.0 lib/gecoder/bindings.rb