<commit_before># Opifex.coffee
#
#	© 2013 <NAME> <<EMAIL>>
#
amqp = require 'amqp'

Opifex = (Url,Modules...) ->
	[ proto, user, password, host, port, domain, exchange, key, queue, dest, path ] = Url.match(
		///([^:]+)://([^:]+):([^@]+)@([^:]+):(\d+)/([^\/]*)/([^\/]+)/([^\/]+)/([^\/]*)/*([^\/]*)/*([^\/]*)///
	)[1...]
	dest ||= exchange # for publish only
	path ||= key # for publish only, NB: you can not send to # or * routes
	self = (message, headers, info)  ->
		$ = arguments.callee
		[ method, args... ] = JSON.parse message.data.toString()
		$.key = info.routingKey
		$.exchange = info.exchange
		$.queue = info.queue
		$.dest = dest
		$.path = path
		if not $[method] and $["*"]
			$["*"].apply $, [method].concat(args)
		else
			$[method]?.apply $, args
	Modules?.map (x) -> (require "opifex.#{x}").apply(self,[])
	self.exchanges = {}
	self.connection = amqp.createConnection
		host: host,
		port: port*1,
		login: user,
		password: password,
		vhost: domain || '/'
	self.connection.on 'error', (Message) ->
		console.log "Connection error", Message
	self.connection.on 'end', () ->
		console.log "Connection closed"
	self.connection.on 'ready', () ->
		self.connection.exchange exchange, { durable: false, type: 'topic', autoDelete: true }, (Exchange) ->
			self.exchange = Exchange
		self.connection.queue queue,{ arguments: { "x-message-ttl" : 60000 } }, (Queue) ->
			self.queue = Queue
			self.queue.bind exchange, key
			self.queue.subscribe self
	self.send = (msg,route,recipient) -># route & recipient are optional, default to destination exchange and key respectively
		route ?= dest
		recipient ?= path
		if typeof msg != "string"
			msg = JSON.stringify msg
		if self[route]
			self[route].publish(recipient,msg)
		else
			self.connection.exchange route, { durable: false, type: 'topic', autoDelete: true }, (Exchange) ->
				self[route] = Exchange
				Exchange?.publish(recipient,msg)
	self

module.exports = Opifex
<commit_msg>Adding init method callback on startup<commit_after># Opifex.coffee
#
#	© 2013 <NAME> <<EMAIL>>
#
amqp = require 'amqp'

Opifex = (Url,Modules...) ->
	[ proto, user, password, host, port, domain, exchange, key, queue, dest, path ] = Url.match(
		///([^:]+)://([^:]+):([^@]+)@([^:]+):(\d+)/([^\/]*)/([^\/]+)/([^\/]+)/([^\/]*)/*([^\/]*)/*([^\/]*)///
	)[1...]
	dest ||= exchange # for publish only
	path ||= key # for publish only, NB: you can not send to # or * routes
	self = (message, headers, info)  ->
		$ = arguments.callee
		[ method, args... ] = JSON.parse message.data.toString()
		$.key = info.routingKey
		$.exchange = info.exchange
		$.queue = info.queue
		$.dest = dest
		$.path = path
		if not $[method] and $["*"]
			$["*"].apply $, [method].concat(args)
		else
			$[method]?.apply $, args
	Modules?.map (x) -> (require "opifex.#{x}").apply(self,[])
	self.exchanges = {}
	self.connection = amqp.createConnection
		host: host,
		port: port*1,
		login: user,
		password: password,
		vhost: domain || '/'
	self.connection.on 'error', (Message) ->
		console.log "Connection error", Message
	self.connection.on 'end', () ->
		console.log "Connection closed"
	self.connection.on 'ready', () ->
		self.connection.exchange exchange, { durable: false, type: 'topic', autoDelete: true }, (Exchange) ->
			self.exchange = Exchange
		self.connection.queue queue,{ arguments: { "x-message-ttl" : 60000 } }, (Queue) ->
			self.queue = Queue
			self.queue.bind exchange, key
			self.queue.subscribe self
			self['init']?.apply(self,[])
	self.send = (msg,route,recipient) -># route & recipient are optional, default to destination exchange and key respectively
		route ?= dest
		recipient ?= path
		if typeof msg != "string"
			msg = JSON.stringify msg
		if self[route]
			self[route].publish(recipient,msg)
		else
			self.connection.exchange route, { durable: false, type: 'topic', autoDelete: true }, (Exchange) ->
				self[route] = Exchange
				Exchange?.publish(recipient,msg)
	self

module.exports = Opifex

{'fraction_non_alphanumeric': 0.20788077797423593, 'fraction_numerical': 0.0055569588279868656, 'mean_word_length': 3.5674740484429064, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 29, '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': '5785741', 'n_tokens_mistral': 1499, 'n_tokens_neox': 1355, 'n_words': 344}