I have an object that looks like this:
object Settings {
final val Host = "host"
final val Protocol = "protocol"
object User {
final val Name = "username"
final val Password = "password"
}
object Subject {
final val Query = "query"
final val Predicate = "predicate"
}
}
What I'd like to do is something like membersAsHash(classOf[CollectionSettings])
and receive a hash) of all of the vals that I've declared in the object:
[
Host => "host",
Protocol => "protocol",
Name => "username",
Password => "password",
Query => "query",
Predicate => "predicate"
]
It'd be fine if the key was a string, even the full package name (e.g. com.example.Settings.User). What I really need is the values, so if I can only get that, it's still acceptable.
This has gotten me the name of the subobjects, but I can't seem to figure out how to get the vals that are internal to each:
val optionsToCheck = {
import scala.reflect.runtime.{universe => ru}
val mirror = ru.runtimeMirror(getClass.getClassLoader)
val subObjects = ru.typeOf[CollectionSettings.type].declarations.filter(_.isModule)
subobjects.map(o => mirror.reflectModule(o.asModule).instance.asInstanceOf[Object].toString).toList
}