object Configuration
Companion object for the Configuration
class
- Alphabetic
- By Inheritance
- Configuration
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Value Members
-
final
def
!=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
##(): Int
- Definition Classes
- AnyRef → Any
-
final
def
==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- val DefaultCommentPattern: Regex
- val DefaultSectionNamePattern: Regex
-
def
apply(source: Source, sections: Map[String, Map[String, String]], sectionNamePattern: Regex, commentPattern: Regex): Either[String, Configuration]
Read a configuration file, permitting some predefined sections to be added to the configuration before it is read.
Read a configuration file, permitting some predefined sections to be added to the configuration before it is read. The predefined sections are defined in a map of maps. The outer map is keyed by predefined section name. The inner maps consist of options and their values. For instance, to read a configuration file, giving it access to certain command line parameters, you could do something like this:
object Foo { def main(args: Array[String]) = { // You'd obviously want to do some real argument checking here. val configFile = args(0) val name = args(1) val ipAddress = args(2) val sections = Map("args" -> Map("name" -> name, "ip" -> ipAddress)) val config = Configuration(Source.fromFile(new File(configFile)), sections) ... } }
- source
scala.io.Source
object to read- sections
the predefined sections. An empty map means there are no predefined sections. not (
true
). Default:false
- sectionNamePattern
Regular expression that matches legal section names.
- commentPattern
Regular expression that matches comment lines.
- returns
Right(config)
on success,Left(error)
on error.
-
def
apply(source: Source, sections: Map[String, Map[String, String]]): Either[String, Configuration]
Read a configuration file, permitting some predefined sections to be added to the configuration before it is read.
Read a configuration file, permitting some predefined sections to be added to the configuration before it is read. The predefined sections are defined in a map of maps. The outer map is keyed by predefined section name. The inner maps consist of options and their values. For instance, to read a configuration file, giving it access to certain command line parameters, you could do something like this:
object Foo { def main(args: Array[String]) = { // You'd obviously want to do some real argument checking here. val configFile = args(0) val name = args(1) val ipAddress = args(2) val sections = Map("args" -> Map("name" -> name, "ip" -> ipAddress)) val config = Configuration(Source.fromFile(new File(configFile)), sections) ... } }
- source
scala.io.Source
object to read- sections
the predefined sections. An empty map means there are no predefined sections.
- returns
Right[Configuration]
on success,Left(error)
on error.
-
def
apply(source: Source, sectionNamePattern: Regex = ..., commentPattern: Regex = Configuration.DefaultCommentPattern, normalizeOptionName: (String) ⇒ String = DefaultOptionNameTransformer, notFoundFunction: Option[NotFoundFunction] = None, safe: Boolean = true): Either[String, Configuration]
Read a configuration file, returning an
Either
, instead of throwing an exception on error.Read a configuration file, returning an
Either
, instead of throwing an exception on error.- source
scala.io.Source
object to read- sectionNamePattern
Regular expression that matches legal section names. Defaults as described above.
- commentPattern
Regular expression that matches comment lines. Default: "^\s*(#.*)$"
- normalizeOptionName
Partial function used to transform option names into keys. The default function transforms the names to lower case.
- notFoundFunction
a function to call if an option isn't found in the configuration, or None. The function must take a section name and an option name as parameters. It must return
Failure
on error,Success(None)
if the value isn't found, and SuccessRight(Some(string))
if the value is found.- safe
true
does "safe" substitutions, with substitutions of nonexistent values replaced by empty strings.false
ensures that bad substitutions result in errors (orNone
in functions, likeget()
, that returnOption
values).- returns
Right(config)
on success,Left(error)
on error.
-
final
def
asInstanceOf[T0]: T0
- Definition Classes
- Any
-
def
clone(): AnyRef
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @native() @throws( ... )
-
final
def
eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
def
equals(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
def
finalize(): Unit
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( classOf[java.lang.Throwable] )
-
final
def
getClass(): Class[_]
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
-
def
hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
-
final
def
isInstanceOf[T0]: Boolean
- Definition Classes
- Any
-
final
def
ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
final
def
notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
-
final
def
notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
-
def
read(source: Source, sections: Map[String, Map[String, String]], sectionNamePattern: Regex, commentPattern: Regex): Either[String, Configuration]
Read a configuration file, permitting some predefined sections to be added to the configuration before it is read.
Read a configuration file, permitting some predefined sections to be added to the configuration before it is read. The predefined sections are defined in a map of maps. The outer map is keyed by predefined section name. The inner maps consist of options and their values. For instance, to read a configuration file, giving it access to certain command line parameters, you could do something like this:
object Foo { def main(args: Array[String]) = { // You'd obviously want to do some real argument checking here. val configFile = args(0) val name = args(1) val ipAddress = args(2) val sections = Map("args" -> Map("name" -> name, "ip" -> ipAddress)) val config = Configuration.read(Source.fromFile(new File(configFile)), sections) ... } }
- source
scala.io.Source
object to read- sections
the predefined sections. An empty map means there are no predefined sections. not (
true
). Default:false
- sectionNamePattern
Regular expression that matches legal section names.
- commentPattern
Regular expression that matches comment lines.
- returns
Success[Configuration]
on success,Failure(exception)
on error.
-
def
read(source: Source, sections: Map[String, Map[String, String]]): Try[Configuration]
Read a configuration file, permitting some predefined sections to be added to the configuration before it is read.
Read a configuration file, permitting some predefined sections to be added to the configuration before it is read. The predefined sections are defined in a map of maps. The outer map is keyed by predefined section name. The inner maps consist of options and their values. For instance, to read a configuration file, giving it access to certain command line parameters, you could do something like this:
object Foo { def main(args: Array[String]) = { // You'd obviously want to do some real argument checking here. val configFile = args(0) val name = args(1) val ipAddress = args(2) val sections = Map("args" -> Map("name" -> name, "ip" -> ipAddress)) val config = Configuration.read(Source.fromFile(new File(configFile)), sections) ... } }
- source
scala.io.Source
object to read- sections
the predefined sections. An empty map means there are no predefined sections.
- returns
Success[Configuration]
on success,Failure(exception)
on error.
-
def
read(source: Source, sectionNamePattern: Regex = ..., commentPattern: Regex = Configuration.DefaultCommentPattern, normalizeOptionName: (String) ⇒ String = DefaultOptionNameTransformer, notFoundFunction: Option[NotFoundFunction] = None, safe: Boolean = true): Try[Configuration]
Read a configuration file, returning an
Either
, instead of throwing an exception on error.Read a configuration file, returning an
Either
, instead of throwing an exception on error.- source
scala.io.Source
object to read- sectionNamePattern
Regular expression that matches legal section names. Defaults as described above.
- commentPattern
Regular expression that matches comment lines. Default: "^\s*(#.*)$"
- normalizeOptionName
Partial function used to transform option names into keys. The default function transforms the names to lower case.
- notFoundFunction
a function to call if an option isn't found in the configuration, or None. The function must take a section name and an option name as parameters. It must return
Failure
on error,Success(None)
if the value isn't found, and SuccessRight(Some(string))
if the value is found.- safe
true
does "safe" substitutions, with substitutions of nonexistent values replaced by empty strings.false
ensures that bad substitutions result in errors (orNone
in functions, likeget()
, that returnOption
values).- returns
Success(config)
on success,Failure(exception)
on error.
-
final
def
synchronized[T0](arg0: ⇒ T0): T0
- Definition Classes
- AnyRef
-
def
toString(): String
- Definition Classes
- AnyRef → Any
-
final
def
wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @native() @throws( ... )
-
object
Implicits
Import this object's contents (
import Configuration.Implicits._
) to get the implicit converters.