Skip to content
This repository has been archived by the owner. It is now read-only.
Branch: master
Go to file
Code

Latest commit

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

README.md

Build Status codecov.io Maven Central License Latest version Scala.js GitHub Issues

Case Classy (ABANDONED)

DEPRECATION NOTICE

The case-classy was a small Scala library, written in a functional style, to handle loading configurations. It was developed between August 2016 and April 2017. At that time, there was not any great Scala-FP alternative for loading configuration from HOCON .conf files. However, since then new alternative libraries like pureconfig or ciris have appeared, which provide more features and have received wider adoption. We recommend using those.

47 Degrees hasf therefore discontinued development and maintenance of this library. The source code is left here for those interesting in studying it.

Introduction

Case classy is a tiny library to make it easy to decode untyped structured data into case class hierarchies of your choosing. It's completely modular, support Scala 2.11 and 2.12, ScalaJS ready, and the core module has zero external dependencies.

// required
libraryDependencies += "com.47deg" %% "classy-core"            % "0.4.0"

// at least one required
libraryDependencies += "com.47deg" %% "classy-config-typesafe" % "0.4.0"
libraryDependencies += "com.47deg" %% "classy-config-shocon"   % "0.4.0"

// optional
libraryDependencies += "com.47deg" %% "classy-generic"         % "0.4.0"
libraryDependencies += "com.47deg" %% "classy-cats"            % "0.4.0"

The modules provide the following support:

  • classy-core: Basic set of configuration decoders and combinators. required
  • classy-generic: Automatic derivation for your case class hierarchies. depends on shapeless
  • classy-config-typesafe: Support for Typesafe's Config library.
  • classy-config-shocon: Support for the Shocon config library.
  • classy-cats: Instances for Cats.

All module support ScalaJS except classy-config-typesafe.

Documentation

Documentation is available on the website.

Quick Example

import classy.generic._
import classy.config._

// Our configuration class hierarchy
sealed trait Shape
case class Circle(radius: Double) extends Shape
case class Rectangle(length: Double, width: Double) extends Shape

case class MyConfig(
  someString: Option[String],
  shapes: List[Shape])

import com.typesafe.config.Config
val decoder1 = deriveDecoder[Config, MyConfig]
decoder1.fromString("""shapes = []""")
// res4: Either[classy.DecodeError,MyConfig] = Right(MyConfig(None,List()))

decoder1.fromString("""
  someString = "hello"
  shapes     = []""")
// res5: Either[classy.DecodeError,MyConfig] = Right(MyConfig(Some(hello),List()))

decoder1.fromString("""shapes = [
  { circle    { radius: 200.0 } },
  { rectangle { length: 10.0, width: 20.0 } }
]""")
// res6: Either[classy.DecodeError,MyConfig] = Right(MyConfig(None,List(Circle(200.0), Rectangle(10.0,20.0))))

// mismatched config
val res = decoder1.fromString("""shapes = [
  { rectangle { radius: 200.0 } },
  { circle    { length: 10.0, width: 20.0 } }
]""")
// res: Either[classy.DecodeError,MyConfig] = Left(AtPath(shapes,And(AtIndex(0,Or(AtPath(circle,Missing),List(AtPath(rectangle,And(AtPath(length,Missing),List(AtPath(width,Missing))))))),List(AtIndex(1,Or(AtPath(circle,AtPath(radius,Missing)),List(AtPath(rectangle,Missing))))))))

// error pretty printing
res.fold(
  error => error.toPrettyString,
  conf  => s"success: $conf")
// res9: String =
// errors.shapes (conjunction/AND):
//   [0] (disjunction/OR):
//     circle: missing value
//     rectangle (conjunction/AND):
//       length: missing value
//       width: missing value
//   [1] (disjunction/OR):
//     circle.radius: missing value
//     rectangle: missing value

Case Classy in the wild

If you wish to add your library here please consider a PR to include it in the list below.

Commercial Support

47 Degrees offers commercial support for the Case Classy library and associated technologies. To find out more, visit 47 Degrees' Open Source Support.

Copyright

Case Classy is designed and developed by 47 Degrees

Copyright (C) 2017 47 Degrees. http://47deg.com

You can’t perform that action at this time.