<commit_before>/**
 * @package admiral
 * @author <NAME> <<EMAIL>>
 * @copyright 2015 WizardApps
 */

var moment = require('moment'),
Promise    = require('bluebird'),
uuid       = require('node-uuid'),
validate   = require('validate.js');

exports = module.exports = function (config) {
    var Deployments = {
        /**
         * Retrieve all deployments
         */
        all: function () {
            return config.getAsync('/deployments', {recursive: true})
                .spread(function (result) {
                    return Promise.all((result.node.nodes || [] ).map(function (node) {
                        return config.getAsync(node.key.replace(/^\/admiral/ig, ''), { recursive: true });
                    }));
                })
                .then(function(dirs) {
                    var results = [];

                    for(var i = 0; i < dirs.length; i++) {
                        results = results.concat(dirs[i][0].node.nodes || []);
                    }<commit_msg>Add helper to filter deployments by a service<commit_after>/**
 * @package admiral
 * @author <NAME> <<EMAIL>>
 * @copyright 2015 WizardApps
 */

var moment = require('moment'),
Promise    = require('bluebird'),
uuid       = require('node-uuid'),
validate   = require('validate.js');

exports = module.exports = function (config) {
    var Deployments = {
        /**
         * Retrieve all deployments
         */
        all: function () {
            return Deployments.whereServiceIs(null);
        },

        /**
         * Retrieve all deployments by the specified service
         * @param service
         */
        whereServiceIs: function(service) {
            if(typeof(service) == 'string') {
                service = [service];
            }

            return config.getAsync('/deployments', {recursive: true})
                .spread(function (result) {
                    return Promise.all((result.node.nodes || [] )
                            .filter(function(node) {
                                if(service) {
                                    for(var i = 0; i < service.length; i++) {
                                        if(node.key.indexOf(service[i]) > -1) {
                                            return true;
                                        }
                                    }

                                    return false;
                                } else {
                                    return true;
                                }
                            })
                            .map(function (node) {
                                return config.getAsync(node.key.replace(/^\/admiral/ig, ''), { recursive: true });
                            })
                    );
                })
                .then(function(dirs) {
                    var results = [];

                    for(var i = 0; i < dirs.length; i++) {
                        results = results.concat(dirs[i][0].node.nodes || []);
                    }
{'fraction_non_alphanumeric': 0.12624254473161034, 'fraction_numerical': 0.004638833664678595, 'mean_word_length': 1.1185964912280701, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 9, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5417396', 'n_tokens_mistral': 758, 'n_tokens_neox': 701, 'n_words': 149}