<commit_before>var debug = require('debug')('carcass:Factory:Storage');

var carcass = require('carcass');
var _ = require('underscore');
var EventEmitter = require('events').EventEmitter;

// .
var cache = {};

// Storage
// ---
// Abstract factory; returns a concrete factory.

// .
module.exports = function(args) {
    debug('building');

    args = args || {};

    // Also support only an initialize function as the argument.
    if (typeof args === 'function') {
        args = {
            initialize: args
        };
    }

    // .
    var instances = null;
    if (args.cache) {
        instances = cache[args.cache] = cache[args.cache] || {};
    }

    // The concrete factory.
    function builder(options) {
        // Merge options from builder and factory.
        options = _.extend(_.omit(args, 'initialize'), options);

        // .
        instance = carcass.mixable({
            title: options.title || 'Storage'
        });

        // .
        if (instances && options.id) {
            if (instances[options.id]) {
                return instances[options.id];
            }
            instance.id = options.id;
            instances[options.id] = instance;
        }

        // .
        EventEmitter.call(instance);
        instance.mixin(EventEmitter.prototype);

        // TODO: requires CRUD methods.
        // TODO: map variants of method names?

        // Get ID from data.
        // Requires data; either an object with an id or just an id.
        // Returns an id or nothing; doesn't return any error.
        instance.getId = function(data, callback) {
            if (!data) return callback();
            switch (typeof data) {
            case 'object':
                return callback(data._id || data.id);<commit_msg>Fixed storage: do not merge id; mixin options.<commit_after>var debug = require('debug')('carcass:Factory:Storage');

var carcass = require('carcass');
var _ = require('underscore');
var EventEmitter = require('events').EventEmitter;

// .
var cache = {};

// Storage
// ---
// Abstract factory; returns a concrete factory.

// .
module.exports = function(args) {
    debug('building');

    args = args || {};

    // Also support only an initialize function as the argument.
    if (typeof args === 'function') {
        args = {
            initialize: args
        };
    }

    // .
    var instances = null;
    if (args.cache) {
        instances = cache[args.cache] = cache[args.cache] || {};
    }

    // The concrete factory.
    function builder(options) {
        // Merge options from builder and factory.
        options = _.extend(_.omit(args, 'initialize', 'id'), options);

        // .
        var instance = {
            title: 'Storage'
        };

        // .
        if (instances && options.id) {
            if (instances[options.id]) {
                return instances[options.id];
            }
            instances[options.id] = instance;
        }

        // Mixin.
        carcass.mixable(instance);
        instance.mixin(_.omit(options, 'prototype'));

        // .
        EventEmitter.call(instance);
        instance.mixin(EventEmitter.prototype);

        // TODO: requires CRUD methods.
        // TODO: map variants of method names?

        // Get ID from data.
        // Requires data; either an object with an id or just an id.
        // Returns an id or nothing; doesn't return any error.
        instance.getId = function(data, callback) {
            if (!data) return callback();
            switch (typeof data) {
            case 'object':
                return callback(data._id || data.id);
{'fraction_non_alphanumeric': 0.13368391918073624, 'fraction_numerical': 0.0, 'mean_word_length': 1.8322884012539185, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, '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': '2716655', 'n_tokens_mistral': 989, 'n_tokens_neox': 967, 'n_words': 272}