<commit_before>var getSingle = require('./get-single');
var promise = require('bluebird');

module.exports = {
    get: get,
    create: create
};

var samples = [
    {
        id: 'sample1',
        name: 'sample1'
    },
    {
        id: 'sample2',
        name: 'sample2'
    }
];

function get(id, index) {
    'use strict';

    return new Promise(function(resolve, reject) {
        let sample = getSingle(samples, id, index);
        resolve(sample);
    });
}

function create(sample) {
    return promise.resolve().then(function() {
        sample.id = sample.name;
        samples.push(sample);
        return sample;
    });
}<commit_msg>Create mock update method.<commit_after>var getSingle = require('./get-single');
var promise = require('bluebird');
var _ = require('lodash');

module.exports = {
    get: get,
    create: create,
    update: update
};

var samples = [
    {
        id: 'sample1',
        name: 'sample1'
    },
    {
        id: 'sample2',
        name: 'sample2'
    }
];

function get(id, index) {
    'use strict';

    return new Promise(function(resolve, reject) {
        let sample = getSingle(samples, id, index);
        resolve(sample);
    });
}

function create(sample) {
    return promise.resolve().then(function() {
        sample.id = sample.name;
        samples.push(sample);
        return sample;
    });
}

function update(id, fields) {
    return promise.resolve().then(function() {
        let index = _.indexOf(samples, function(sample) {
            return sample.id == id;
        });
        if (index === -1) {
            return {};
        }
        for(let key in fields) {
            samples[index][key] = fields[key];
        }
        return samples[index];
    });
}
{'fraction_non_alphanumeric': 0.15017261219792866, 'fraction_numerical': 0.005178365937859608, 'mean_word_length': 2.1503623188405796, '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': '3613541', 'n_tokens_mistral': 528, 'n_tokens_neox': 523, 'n_words': 121}