router .route('/remount') .post(function remount(req, res) { app.vault.reMount(req.body) .then(function remountSuccess(mounts) { console.info('Remount successful!'); res.json(mounts); }) .catch(_.partial(onError, res, 'There was an error remounting')); });
function createObjectSpec(predicate, gen) { if (isSpec(predicate)) { return predicate; } else { return { conform: (value, unwrap = false) => conform(value, unwrap, _.partial(_.has, predicate)), unform: _.identity, gen }; } }
function star(spec) { return { op: 'star', conform: _.partial(_conform, spec), unform: _.identity, gen: () => tcg.null.then(() => tcg.array(gen(spec), {size: _.random(0, 5)})), describe: () => [star.name, ...describe([spec])], explain: function*(values, {via}) { yield* explainInvalid(values, spec, via); } }; }
/* * Private method * Starts the specified container */ _startContainer(container, cb) { container.instance.start( (err, data) => { if (err) { return container.cleanup(_.partial(cb, err)) } cb(null, container) }) }
function createArraySpec(predicate) { return { conform: (value, unwrap = false) => conform(value, unwrap, _.partial(_.includes, predicate)), describe: () => predicate, explain: function*(value, options) { if (!_.includes(predicate, value)) { yield getExplanation(value, options); } }, gen: () => tcg.null.then(() => tcg.return(_.sample(predicate))) }; }
function load(config, metadata) { var defaults = {}, base_url = getVaultURL(config) + '/' + API_PREFIX, partial; if (config.has('timeout')) { defaults.timeout = config.get('timeout'); } defaults = _.assign(defaults, getSSLOptions(config)); defaults = _.assign(defaults, getProxy(config)); partial = _.partial(Endpoint.create, base_url, defaults); return _.transform(metadata, partial, {}); }
/** * Creates a [fs.writeFile](https://nodejs.org/api/fs.html#fs_fs_writefile_file_data_options_callback) * function with `filePath` and `data` partially applied. * * @memberOf file * @param {string} destPath The path to write the file to. * @param {string} data The data to write to the file. * @returns {Function} Returns the partially applied function. */ function write(destPath, data) { return _.partial(fs.writeFile, destPath, data); }
/* * Private method * Retrieves info of a container */ _getContainerInfo(container, cb) { container.instance.inspect( (err, data) => { if (err || !data || !data.NetworkSettings || !data.NetworkSettings.IPAddress || data.NetworkSettings.IPAddress.length == 0) { err = err || new Error("unable to retrieve container IP") return container.cleanup(_.partial(cb, err)) } container.setIp(data.NetworkSettings.IPAddress) cb(null, container) }) }
addProduct (product) { if (!_.every(['name', 'link', 'price', 'variation'], _.partial(_.has, product))) { this.emit('error', 'Fields missing in ' + JSON.stringify(product)) return this } if (!this.doUrlMatch(product.link)) { this.emit('error', url.parse(product.link).hostname + ' mismatch ' + this.url) return this } this.products.push(product) debug('Product', product.name, 'added') this.emit('submit', product) return this /* for method chaining */ }
/*----------------------------------------------------------------------------*/ /** * Creates browser builds of the FP converter and mappings at the `target` path. * * @private * @param {string} target The output directory path. */ function build() { async.series([ _.partial(webpack, mappingConfig), _.partial(webpack, fpConfig), file.min(path.join(distPath, filename)) ], util.pitch); }
function mapOf(kpred, vpred, options = {}) { return { conform: _.partial(_conform, kpred, vpred, options), unform: _.identity, gen: () => tcg.object(gen(kpred), gen(vpred)), describe: () => [mapOf.name, ...describe([kpred, vpred])], explain: function*(value, {via}) { yield* explainInvalid(value, kpred, vpred, via); } }; }
function cat(...predicates) { const pairs = _.chunk(predicates, 2); return { op: 'cat', conform: _.partial(_conform, pairs), unform: values => _.map(pairs, ([k, p]) => unform(p, values[k])), gen: () => tcg.array(_.map(pairs, ([, p]) => gen(p))), describe: () => [cat.name, ...describe(predicates)], explain: function*(values, {via}) { yield* explainInsufficientInput(values, pairs, via); yield* explainExtraInput(pairs, values, via); yield* explainInvalid(values, pairs, via); } }; }
/*----------------------------------------------------------------------------*/ /** * Creates a [fs.copy](https://github.com/jprichardson/node-fs-extra#copy) * function with `srcPath` and `destPath` partially applied. * * @memberOf file * @param {string} srcPath The path of the file to copy. * @param {string} destPath The path to copy the file to. * @returns {Function} Returns the partially applied function. */ function copy(srcPath, destPath) { return _.partial(fs.copy, srcPath, destPath); }
/** * Creates a `minify` function with `srcPath` and `destPath` partially applied. * * @memberOf file * @param {string} srcPath The path of the file to minify. * @param {string} destPath The path to write the file to. * @returns {Function} Returns the partially applied function. */ function min(srcPath, destPath) { return _.partial(minify, srcPath, destPath); }
router .route('/remount') .post(function remount(req, res) { app.vault.reMount(req.body) .then(function remountSuccess(mounts) { console.info('Remount successful!'); res.json(mounts); }) .catch(_.partial(onError, res, 'There was an error remounting')); });