<commit_before>'use strict';

var path = require('path'),
    _ = require('lodash'),
    usersController = require(path.join(__dirname, './users/controller')),
    ridesController = require(path.join(__dirname, './rides/controller'));

function addRoutes(server) {
    server.route({
        method: 'GET',
        path: '/users',
        handler: function (request, reply) {
            usersController.getList(function (err, data) {
                reply(data);
            });
        },
        config: {
            tags: ['api'],
            plugins: {
                hal: {
                    api: 'users',
                    prepare: function (rep, next) {
                        _.each(rep.entity.users, function (user) {
                            rep.embed('users', './' + user.id, user);
                        });

                        rep.ignore('users');

                        next();
                    }
                }
            }
        }
    });

    server.route({
        method: 'GET',
        path: '/rides',
        handler: function (request, reply) {
            ridesController.getList(function (err, data) {
                reply(data);
            });
        },
        config: {
            tags: ['api'],
            plugins: {
                hal: {
                    api: 'rides',
                    prepare: function (rep, next) {
                        _.each(rep.entity.rides, function (ride) {
                            rep.embed('rides', './' + ride.id, ride);
                        });

                        rep.ignore('rides');

                        next();
                    }
                }
            }
        }
    });
}

module.exports = {
    addRoutesTo: addRoutes
};<commit_msg>extracted duplicate halacious config<commit_after>'use strict';

var path = require('path'),
    _ = require('lodash'),
    usersController = require(path.join(__dirname, './users/controller')),
    ridesController = require(path.join(__dirname, './rides/controller'));

function configureHalaciousFor(resourceType) {
    return {
        api: resourceType,
        prepare: function (rep, next) {
            _.each(rep.entity[resourceType], function (resource) {
                rep.embed(resourceType, './' + resource.id, resource);
            });

            rep.ignore(resourceType);

            next();
        }
    };
}

function addRoutesTo(server) {
    server.route({
        method: 'GET',
        path: '/users',
        handler: function (request, reply) {
            usersController.getList(function listResponse(err, data) {
                reply(data);
            });
        },
        config: {
            tags: ['api'],
            plugins: {
                hal: configureHalaciousFor('users')
            }
        }
    });

    server.route({
        method: 'GET',
        path: '/rides',
        handler: function (request, reply) {
            ridesController.getList(function (err, data) {
                reply(data);
            });
        },
        config: {
            tags: ['api'],
            plugins: {
                hal: configureHalaciousFor('rides')
            }
        }
    });
}

module.exports = {
    addRoutesTo: addRoutesTo
};
{'fraction_non_alphanumeric': 0.13591635916359163, 'fraction_numerical': 0.0, 'mean_word_length': 1.2828070175438597, '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': '3338757', 'n_tokens_mistral': 850, 'n_tokens_neox': 823, 'n_words': 156}