<commit_before>'use strict'

// external dependencies
const
	co = require('co'),
	CronJob = require('cron').CronJob,
	expressSession = require('express-session'),
	fs = require('fs-extra'),
	merge = require('deepmerge'),
	moment = require('moment'),
	path = require('path'),
	redis = require('redis'),
	RedisStore = require('connect-redis')(expressSession),

// ramster modules
	{APIModule} = require('./modules/api'),
	{ClientModule} = require('./modules/client'),
	CodeGenerator = require('./modules/codeGenerator'),
	coreTests = require('./core.spec'),
	{DBModule} = require('./modules/db'),
	{describeSuiteConditionally, runTestConditionally} = require('./modules/toolbelt'),
	Emails = require('./modules/emails'),
	GeneralStore = require('./modules/generalStore'),
	Logger = require('./modules/errorLogger'),
	Migrations = require('./modules/migrations'),
	TokenManager = require('./modules/tokenManager')

class Core {
	constructor(config) {
		try {
			this.config = config
			for (const testName in coreTests) {
				this[testName] = coreTests[testName]
			}
			this.modules = {}
		} catch (e) {
			console.log(e)
		}
	}

	loadDependencies() {
		let instance = this
		return co(function*() {
			instance.logger = new Logger(instance.config)
			instance.generalStore = new GeneralStore(instance.config)
			yield instance.generalStore.createClient()
			instance.tokenManager = new TokenManager(instance.config, instance.generalStore, instance.logger)
			instance.codeGenerator = new CodeGenerator(instance.config)
			return true
		})
	}

	loadDB(mockMode) {
		let instance = this
		return co(function*() {
			const {config, logger, generalStore, tokenManager} = instance
			let db = new DBModule(config, logger, generalStore, tokenManager)
			yield db.connectToDB(mockMode)
			yield db.loadComponents()
			yield db.createAssociations()
			instance.modules.db = db
			return true
		})
	}

	loadMailClient() {
		let instance = this
		return co(function*() {
			const {config} = instance
			let db = instance.modules.db
			if (config.emails.customModulePath) {
				let CustomMailClient = require(config.emails.customModulePath)
				instance.mailClient = new CustomMailClient(config)
			} else {
				instance.mailClient = new Emails(config)
			}
			if (db) {
				db.mailClient = instance.mailClient
				db.setDBInComponents()
			}
			return true
		})
	}

	loadMigrations() {
		let db = this.modules.db<commit_msg>the core.loadDB method now does a force sync in mock mode<commit_after>'use strict'

// external dependencies
const
	co = require('co'),
	CronJob = require('cron').CronJob,
	expressSession = require('express-session'),
	fs = require('fs-extra'),
	merge = require('deepmerge'),
	moment = require('moment'),
	path = require('path'),
	redis = require('redis'),
	RedisStore = require('connect-redis')(expressSession),

// ramster modules
	{APIModule} = require('./modules/api'),
	{ClientModule} = require('./modules/client'),
	CodeGenerator = require('./modules/codeGenerator'),
	coreTests = require('./core.spec'),
	{DBModule} = require('./modules/db'),
	{describeSuiteConditionally, runTestConditionally} = require('./modules/toolbelt'),
	Emails = require('./modules/emails'),
	GeneralStore = require('./modules/generalStore'),
	Logger = require('./modules/errorLogger'),
	Migrations = require('./modules/migrations'),
	TokenManager = require('./modules/tokenManager')

class Core {
	constructor(config) {
		try {
			this.config = config
			for (const testName in coreTests) {
				this[testName] = coreTests[testName]
			}
			this.modules = {}
		} catch (e) {
			console.log(e)
		}
	}

	loadDependencies() {
		let instance = this
		return co(function*() {
			instance.logger = new Logger(instance.config)
			instance.generalStore = new GeneralStore(instance.config)
			yield instance.generalStore.createClient()
			instance.tokenManager = new TokenManager(instance.config, instance.generalStore, instance.logger)
			instance.codeGenerator = new CodeGenerator(instance.config)
			return true
		})
	}

	loadDB(mockMode) {
		let instance = this
		return co(function*() {
			const {config, logger, generalStore, tokenManager} = instance
			let db = new DBModule(config, logger, generalStore, tokenManager)
			yield db.connectToDB(mockMode)
			yield db.loadComponents()
			yield db.createAssociations()
			if (mockMode) {
				yield db.sequelize.sync({force: true})
			}
			instance.modules.db = db
			return true
		})
	}

	loadMailClient() {
		let instance = this
		return co(function*() {
			const {config} = instance
			let db = instance.modules.db
			if (config.emails.customModulePath) {
				let CustomMailClient = require(config.emails.customModulePath)
				instance.mailClient = new CustomMailClient(config)
			} else {
				instance.mailClient = new Emails(config)
			}
			if (db) {
				db.mailClient = instance.mailClient
				db.setDBInComponents()
			}
			return true
		})
	}

	loadMigrations() {
		let db = this.modules.db
{'fraction_non_alphanumeric': 0.1385456755114442, 'fraction_numerical': 0.0, 'mean_word_length': 4.181532004197272, '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': '1702122', 'n_tokens_mistral': 1686, 'n_tokens_neox': 1495, 'n_words': 320}