All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.ruippeixotog.scalascraper.config.util.ConfigReader.scala Maven / Gradle / Ivy

The newest version!
package net.ruippeixotog.scalascraper.config.util

import com.github.nscala_time.time.Imports._
import com.typesafe.config.Config

trait ConfigReader[A] {
  def read(conf: Config, path: String): A
}

object ConfigReader {
  def apply[A](readFunc: (Config, String) => A) =
    new ConfigReader[A] {
      def read(conf: Config, path: String) = readFunc(conf, path)
    }

  implicit def boolConfReader: ConfigReader[Boolean] = ConfigReader(_.getBoolean(_))
  implicit def stringConfReader: ConfigReader[String] = ConfigReader(_.getString(_))
  implicit def intConfReader: ConfigReader[Int] = ConfigReader(_.getInt(_))
  implicit def doubleConfReader: ConfigReader[Double] = ConfigReader(_.getDouble(_))
  implicit def localDateConfReader: ConfigReader[LocalDate] = ConfigReader(_.getString(_).toLocalDate)
  implicit def dateTimeConfReader: ConfigReader[DateTime] = ConfigReader(_.getString(_).toDateTime)
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy