Giter Site home page Giter Site logo

juanpedromoreno / case-classy Goto Github PK

View Code? Open in Web Editor NEW

This project forked from 47degrees/case-classy

0.0 2.0 0.0 2.16 MB

configuration with less hassle

Home Page: http://47deg.github.io/case-classy/

License: Apache License 2.0

Scala 99.89% CSS 0.11%

case-classy's Introduction

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.