<commit_before>package org.labrad

import org.labrad.annotations.Setting
import org.labrad.data._
import scala.collection.mutable
import scala.reflect.runtime.universe._

case class RequestContext(source: Long, context: Context, id: Long, data: Data)

object Reflect {

  def makeHandler[T: TypeTag]: (Seq[SettingInfo], T => RequestContext => Data) = {
    val t = typeOf[T]
    val allMethods = t.members.toSeq.collect { case m: MethodSymbol => m }
    val overloads = allMethods.groupBy(_.name.decodedName.toString).toSeq
<commit_msg>Add the ability to store extra values in RequestContext. (#71)<commit_after>package org.labrad

import org.labrad.annotations.Setting
import org.labrad.data._
import scala.collection.mutable
import scala.reflect.runtime.universe._

case class RequestContext(
  source: Long,
  context: Context,
  id: Long,
  data: Data,
  private val values: Map[RequestContext.Key[_], Any] = Map()
) {
  def withValue[A](key: RequestContext.Key[A], value: A): RequestContext = {
    copy(values = values + (key -> value))
  }

  def get[A](key: RequestContext.Key[A]): Option[A] = {
    values.get(key).map(_.asInstanceOf[A])
  }
}

object RequestContext {
  case class Key[A](name: String)
}

object Reflect {

  def makeHandler[T: TypeTag]: (Seq[SettingInfo], T => RequestContext => Data) = {
    val t = typeOf[T]
    val allMethods = t.members.toSeq.collect { case m: MethodSymbol => m }
    val overloads = allMethods.groupBy(_.name.decodedName.toString).toSeq

{'fraction_non_alphanumeric': 0.1284465366509751, 'fraction_numerical': 0.0013449899125756557, 'mean_word_length': 4.410909090909091, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 10, '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': '4725980', 'n_tokens_mistral': 485, 'n_tokens_neox': 479, 'n_words': 121}