Code coverage report for preceptor-reporter/lib/abstractMessenger.js

Statements: 100% (14 / 14)      Branches: 100% (6 / 6)      Functions: 100% (6 / 6)      Lines: 100% (14 / 14)      Ignored: none     

All files » preceptor-reporter/lib/ » abstractMessenger.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103      1 1   1                       1               6   6   6                                         118                   118                         118   118 24                     24                         1  
// Copyright 2014, Yahoo! Inc.
// Copyrights licensed under the Mit License. See the accompanying LICENSE file for terms.
 
var Base = require('preceptor-core').Base;
var utils = require('preceptor-core').utils;
 
var defaultsMessenger = require('./defaults/messenger');
 
/**
 * AbstractMessenger messenger
 *
 * @class AbstractMessenger
 * @extends Base
 *
 * @property {object} _options
 *
 * @event message
 */
var AbstractMessenger = Base.extend(
 
	/**
	 * @param {object} [options]
	 * @param {boolean} [options.output=false]
	 * @constructor
	 */
	function (options) {
		this.__super();
 
		this._options = utils.deepExtend({}, [defaultsMessenger, options || {}]);
 
		this.initialize();
	},
 
	{
		/**
		 * Initializes the instance
		 *
		 * @method initialize
		 */
		initialize: function () {
			// Nothing yet
		},
 
 
		/**
		 * Gets the options
		 *
		 * @method getOptions
		 * @return {object}
		 */
		getOptions: function () {
			return this._options;
		},
 
		/**
		 * Should the messages be printed?
		 *
		 * @method shouldOutput
		 * @return {boolean}
		 */
		shouldOutput: function () {
			return !!this.getOptions().output;
		},
 
 
		/**
		 * Triggers a message
		 *
		 * @method trigger
		 * @param {string} msg
		 * @param {object} [options]
		 */
		trigger: function (msg, options) {
 
			this.emit('message', msg, options || {});
 
			if (this.shouldOutput()) {
				this.output(msg);
			}
		},
 
		/**
		 * Outputs data to stdout
		 *
		 * @method output
		 * @param {string} data
		 */
		output: function (data) {
			process.stdout.write(data);
		}
	},
 
	{
		/**
		 * @property TYPE
		 * @type {string}
		 * @static
		 */
		TYPE: 'AbstractMessenger'
	});
 
module.exports = AbstractMessenger;