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

ciris.CirisPlatformSpecificNative.scala Maven / Gradle / Ivy

There is a newer version: 0.12.1
Show newest version
package ciris

import ciris.api._

import java.io.File
import java.nio.charset.Charset

private[ciris] trait CirisPlatformSpecific {
  def file[Value](
    file: File,
    modifyFileContents: String => String = identity,
    charset: Charset = Charset.defaultCharset
  )(implicit decoder: ConfigDecoder[String, Value])
    : ConfigEntry[Id, (File, Charset), String, Value] = {
    ConfigSource.File
      .read((file, charset))
      .mapValue(modifyFileContents)
      .decodeValue[Value]
  }

  def fileSync[F[_]: Sync, Value](
    file: File,
    modifyFileContents: String => String = identity,
    charset: Charset = Charset.defaultCharset
  )(
    implicit decoder: ConfigDecoder[String, Value]
  ): ConfigEntry[F, (File, Charset), String, Value] = {
    ConfigSource.File
      .suspendF[F]
      .read((file, charset))
      .mapValue(modifyFileContents)
      .decodeValue[Value]
  }

  def fileWithName[Value](
    name: String,
    modifyFileContents: String => String = identity,
    charset: Charset = Charset.defaultCharset
  )(implicit decoder: ConfigDecoder[String, Value])
    : ConfigEntry[Id, (File, Charset), String, Value] = {
    this.file(new File(name), modifyFileContents, charset)
  }

  def fileWithNameSync[F[_]: Sync, Value](
    name: String,
    modifyFileContents: String => String = identity,
    charset: Charset = Charset.defaultCharset
  )(
    implicit decoder: ConfigDecoder[String, Value]
  ): ConfigEntry[F, (File, Charset), String, Value] = {
    this.fileSync[F, Value](new File(name), modifyFileContents, charset)
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy