<commit_before>
var _ = require('underscore');


var Service = exports.Service = function (options) {
    this._system = options.system;
    this._methods = options.methods;
    this.name = options.system.name;

    var ServiceInstance = this.ServiceInstance = function (system, socket, session) {
	this.system = system;
	this.socket = socket;
	this.session = session;
    };

    _.extend(ServiceInstance.prototype, options.methods, {
	trigger: function (name, data) {
	    var _this = this;
	    this.socket.emit(_this.system.channel, {
		subject: 'trigger'
		, trigger: name
		, data: data
	    });
	}
    });
};

_.extend(Service.prototype, {
    serve: function (socket, session) {
	var _service = this;
	socket.on(_service._system.name, function (msg) {
	    if (_service._methods.hasOwnProperty(msg.method)) {
		var instance = new _service.ServiceInstance(_service._system.get(msg.id), socket, session);
		instance[msg.method](msg.data);
	    }
	    else {
		console.log('ignored service call ', msg);<commit_msg>Add service responses in service.<commit_after>
var _ = require('underscore');


var Service = exports.Service = function (options) {
    this._system = options.system;
    this._methods = options.methods;
    this.name = options.system.name;

    var ServiceInstance = this.ServiceInstance = function (system, socket, session) {
	this.system = system;
	this.socket = socket;
	this.session = session;
    };

    _.extend(ServiceInstance.prototype, options.methods, {
	trigger: function (name, data) {
	    var _this = this;
	    this.socket.emit(_this.system.channel, {
		subject: 'trigger'
		, trigger: name
		, data: data
	    });
	}
    });
};

_.extend(Service.prototype, {
    serve: function (socket, session) {
	var _service = this
	, name = _service._system.name
	;
	socket.on(name, function (msg) {
	    if (_service._methods.hasOwnProperty(msg.method)) {
		var instance = new _service.ServiceInstance(_service._system.get(msg.id), socket, session);
		instance[msg.method](msg.data);
	    }
	    else if (msg.check) {
		socket.emit(name);
	    }
	    else {
		console.log('ignored service call ', msg);
{'fraction_non_alphanumeric': 0.13696060037523453, 'fraction_numerical': 0.0, 'mean_word_length': 3.4905263157894737, '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': '2524273', 'n_tokens_mistral': 688, 'n_tokens_neox': 654, 'n_words': 145}