<commit_before>package svoysh.util

import java.util.concurrent.atomic.AtomicBoolean
import net.liftweb.util._

object RunMode extends RunMode

/**
 * To configure application for production run mode set system property
 * "run.mode" to "production". If no run mode specified then development mode
 * assumed. Example:
 * [java -Drun.mode=production -jar sbt.jar ~jetty-run]
 * See [http://www.assembla.com/wiki/show/liftweb/Run_Modes]
 */
trait RunMode {

	def isStartedInDevMode: Boolean = ModeHolder.isStartedInDevMode

	def isProdMode: Boolean = ModeHolder.isProdModeCurrently

	def isDevMode: Boolean = !isProdMode

	/**
	 * Can toggle mode only if app was started in development mode.
	 */
	def canSwitchMode: Boolean = {
		// Note: Additional checks can be added here. Eg test if current user is admin.
		isStartedInDevMode
	}

	def switchToDevMode {
		if (canSwitchMode && !isDevMode) ModeHolder.setProdModeCurrently(false)
	}

	def switchToProdMode {
		if (canSwitchMode && !isProdMode) ModeHolder.setProdModeCurrently(true)
	}

	def getModeName: String = {
		if (isProdMode) "PROD"
		else "DEV"
	}
}

private object ModeHolder {

	lazy val isStartedInProdMode: Boolean = Props.productionMode

	lazy val isStartedInDevMode: Boolean = !isStartedInProdMode

	private var _isProdModeCurrently: AtomicBoolean = {
		new AtomicBoolean(isStartedInProdMode)
	}

	def isProdModeCurrently: Boolean = _isProdModeCurrently.get

	def setProdModeCurrently(is: Boolean) {
		_isProdModeCurrently.set(is)

		// TODO: DB can be reconnected here and other startup data updated
		// depending on changed mode.
	}
}<commit_msg>RunMode: _isProdModeCurrently is now val.<commit_after>package svoysh.util

import java.util.concurrent.atomic.AtomicBoolean
import net.liftweb.util._

object RunMode extends RunMode

/**
 * To configure application for production run mode set system property
 * "run.mode" to "production". If no run mode specified then development mode
 * assumed. Example:
 * [java -Drun.mode=production -jar sbt.jar ~jetty-run]
 * See [http://www.assembla.com/wiki/show/liftweb/Run_Modes]
 */
trait RunMode {

	def isStartedInDevMode: Boolean = ModeHolder.isStartedInDevMode

	def isProdMode: Boolean = ModeHolder.isProdModeCurrently

	def isDevMode: Boolean = !isProdMode

	/**
	 * Can toggle mode only if app was started in development mode.
	 */
	def canSwitchMode: Boolean = {
		// Note: Additional checks can be added here. Eg test if current user is admin.
		isStartedInDevMode
	}

	def switchToDevMode {
		if (canSwitchMode && !isDevMode) ModeHolder.setProdModeCurrently(false)
	}

	def switchToProdMode {
		if (canSwitchMode && !isProdMode) ModeHolder.setProdModeCurrently(true)
	}

	def getModeName: String = {
		if (isProdMode) "PROD"
		else "DEV"
	}
}

private object ModeHolder {

	lazy val isStartedInProdMode: Boolean = Props.productionMode

	lazy val isStartedInDevMode: Boolean = !isStartedInProdMode

	private val _isProdModeCurrently: AtomicBoolean = {
		new AtomicBoolean(isStartedInProdMode)
	}

	def isProdModeCurrently: Boolean = _isProdModeCurrently.get

	def setProdModeCurrently(is: Boolean) {
		_isProdModeCurrently.set(is)

		// TODO: DB can be reconnected here and other startup data updated
		// depending on changed mode.
	}
}
{'fraction_non_alphanumeric': 0.0847145488029466, 'fraction_numerical': 0.0, 'mean_word_length': 4.468120805369128, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '5701953', 'n_tokens_mistral': 1119, 'n_tokens_neox': 1046, 'n_words': 294}