<commit_before>var mongodb = require('mongodb')
  , _ = require("underscore")
  , redModels = [];

module.exports.connect = function(opt, cb){
  var options = _.extend({host: '127.0.0.1', port: 27017, auto_reconnect: true, poolSize: 10, w:1, strict: true, native_parser: true}, opt)
    ,  mongoserver = new mongodb.Server(options.host, options.port, options)
    ,  dbconnector = module.exports.db = new mongodb.Db(options.database, mongoserver, options);

  dbconnector.open(function(err, db){
    if (err) return cb(err);

    for(var i in redModels){
      redModels[i].connect(db);
    }

    console.log("red-mongo is ready for your requests ...");

    cb(null, db); 
  });
  return this;
};

module.exports.close = function(cb){ module.exports.db.close(cb); };


var Model = module.exports.Model = new Function;

/** 
* Model.collection -> mongodb.collection
*
* MongoDB collection getter
*
**/
Model.prototype = {
  get collection(){
  // Obsolete
    return this.constructor.collection;
  }
};

/**
* Model.bless([[Object]]) -> Object
*
* Use to dynamically type an object as Model by setting object's __proto__ with
* Model.prototype:
*
*     function(obj){
*         obj.__proto__ = this.prototype;
*         return obj;
*     }
*
* Very dangerous: use it carefully !!<commit_msg>add redMongo.objectID<commit_after>var mongodb = require('mongodb')
  , _ = require("underscore")
  , redModels = [];

module.exports.connect = function(opt, cb){
  var options = _.extend({host: '127.0.0.1', port: 27017, auto_reconnect: true, poolSize: 10, w:1, strict: true, native_parser: true}, opt)
    ,  mongoserver = new mongodb.Server(options.host, options.port, options)
    ,  dbconnector = module.exports.db = new mongodb.Db(options.database, mongoserver, options);

  dbconnector.open(function(err, db){
    if (err) return cb(err);

    for(var i in redModels){
      redModels[i].connect(db);
    }

    console.log("mongo-redline is ready for your requests ...");

    cb(null, db); 
  });
  return this;
};

module.exports.objectID = mongodb.ObjectID;

module.exports.close = function(cb){ module.exports.db.close(cb); };


var Model = module.exports.Model = new Function;

/** 
* Model.collection -> mongodb.collection
*
* MongoDB collection getter
*
**/
Model.prototype = {
  get collection(){
  // Obsolete
    return this.constructor.collection;
  }
};

/**
* Model.bless([[Object]]) -> Object
*
* Use to dynamically type an object as Model by setting object's __proto__ with
* Model.prototype:
*
*     function(obj){
*         obj.__proto__ = this.prototype;
*         return obj;
*     }
*
* Very dangerous: use it carefully !!
{'fraction_non_alphanumeric': 0.15221507004922377, 'fraction_numerical': 0.010602044680045438, 'mean_word_length': 3.5239726027397262, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6655557', 'n_tokens_mistral': 898, 'n_tokens_neox': 852, 'n_words': 205}