Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into scala-version-root-project
- Loading branch information
Showing
25 changed files
with
205 additions
and
212 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
39 changes: 39 additions & 0 deletions
39
modules/generic/src/main/scala/pureconfig/generic/EnumCoproductHint.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package pureconfig.generic | ||
|
||
import com.typesafe.config.{ ConfigFactory, ConfigObject, ConfigValue, ConfigValueType } | ||
import pureconfig._ | ||
import pureconfig.error._ | ||
import pureconfig.syntax._ | ||
|
||
/** | ||
* Hint applicable to sealed families of case objects where objects are written and read as strings with their type | ||
* names. Trying to read or write values that are not case objects results in failure. | ||
* | ||
* @tparam T the type of the coproduct or sealed family for which this hint applies | ||
*/ | ||
@deprecated("Use `pureconfig.generic.semiauto.deriveEnumerationReader[T]`, `pureconfig.generic.semiauto.deriveEnumerationWriter[T]` and `pureconfig.generic.semiauto.deriveEnumerationConvert[T]` instead", "0.11.0") | ||
class EnumCoproductHint[T] extends CoproductHint[T] { | ||
|
||
/** | ||
* Returns the field value for a class or coproduct option name. | ||
* | ||
* @param name the name of the class or coproduct option | ||
* @return the field value associated with the given class or coproduct option name. | ||
*/ | ||
protected def fieldValue(name: String): String = name.toLowerCase | ||
|
||
def from(cur: ConfigCursor, name: String) = cur.asString.right.map { str => | ||
if (str == fieldValue(name)) Some(ConfigCursor(ConfigFactory.empty.root, cur.pathElems)) else None | ||
} | ||
|
||
// TODO: improve handling of failures on the write side | ||
def to(cv: ConfigValue, name: String) = cv match { | ||
case co: ConfigObject if co.isEmpty => Right(fieldValue(name).toConfig) | ||
case _: ConfigObject => Left(ConfigReaderFailures(ConvertFailure( | ||
NonEmptyObjectFound(name), ConfigValueLocation(cv), ""))) | ||
case _ => Left(ConfigReaderFailures(ConvertFailure( | ||
WrongType(cv.valueType, Set(ConfigValueType.OBJECT)), ConfigValueLocation(cv), ""))) | ||
} | ||
|
||
def tryNextOnFail(name: String) = false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
modules/joda/src/test/scala/pureconfig/module/joda/arbitrary/package.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package pureconfig.module.joda | ||
|
||
import scala.collection.JavaConverters._ | ||
|
||
import org.joda.time._ | ||
import org.scalacheck.{ Arbitrary, Gen } | ||
import pureconfig.gen._ | ||
|
||
package object arbitrary { | ||
private def nanoToMilli(n: Int): Int = n / 1000000 | ||
|
||
implicit val instantArbitrary: Arbitrary[Instant] = | ||
Arbitrary(Arbitrary.arbitrary[Long].map(new Instant(_))) | ||
|
||
implicit val intervalArbitrary: Arbitrary[Interval] = | ||
Arbitrary(Arbitrary.arbitrary[(DateTime, DateTime)] | ||
.map { i => | ||
val (from, to) = if (i._1.isBefore(i._2)) i else i.swap | ||
// Comparing new Interval(foo) with Interval.parseWithOffset(foo) will return false | ||
// See http://www.joda.org/joda-time/apidocs/org/joda/time/Interval.html#parseWithOffset-java.lang.String- | ||
Interval.parseWithOffset(new Interval(from, to).toString) | ||
}) | ||
|
||
implicit val durationArbitrary: Arbitrary[Duration] = | ||
Arbitrary(Arbitrary.arbitrary[Long].map(new Duration(_))) | ||
|
||
implicit val localTimeArbitrary: Arbitrary[LocalTime] = Arbitrary( | ||
genLocalTime.map { t => | ||
new LocalTime(t.getHour, t.getMinute, t.getSecond, nanoToMilli(t.getNano)) | ||
}) | ||
|
||
implicit val localDateArbitrary: Arbitrary[LocalDate] = Arbitrary( | ||
genLocalDate.map { d => | ||
new LocalDate(d.getYear, d.getMonthValue, d.getDayOfMonth) | ||
}) | ||
|
||
implicit val localDateTimeArbitrary: Arbitrary[LocalDateTime] = Arbitrary( | ||
genLocalDateTime.map { d => | ||
new LocalDateTime( | ||
d.getYear, d.getMonthValue, d.getDayOfMonth, | ||
d.getHour, d.getMinute, d.getSecond, nanoToMilli(d.getNano)) | ||
}) | ||
|
||
implicit val monthDayArbitrary: Arbitrary[MonthDay] = Arbitrary( | ||
genMonthDay.map { m => | ||
new MonthDay(m.getMonthValue, m.getDayOfMonth) | ||
}) | ||
|
||
implicit val yearMonthArbitrary: Arbitrary[YearMonth] = Arbitrary( | ||
genYearMonth.map { y => | ||
new YearMonth(y.getYear, y.getMonthValue) | ||
}) | ||
|
||
implicit val zoneIdArbitrary: Arbitrary[DateTimeZone] = | ||
Arbitrary(Gen.oneOf(DateTimeZone.getAvailableIDs.asScala.toSeq).map(DateTimeZone.forID)) | ||
|
||
implicit val dateTimeArbitrary: Arbitrary[DateTime] = | ||
Arbitrary( | ||
for { | ||
zoneId <- zoneIdArbitrary.arbitrary | ||
localDateTime <- localDateTimeArbitrary.arbitrary if !zoneId.isLocalDateTimeGap(localDateTime) | ||
} yield localDateTime.toDateTime(zoneId)) | ||
|
||
implicit val periodArbitrary: Arbitrary[Period] = | ||
Arbitrary(Arbitrary.arbitrary[Int].map { i => | ||
// Generated large longs crash Period constructor internally | ||
new Period(i.toLong) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
Oops, something went wrong.