-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #35 from olafurpg/docs
Create metaconfig-docs module
- Loading branch information
Showing
24 changed files
with
516 additions
and
203 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
23 changes: 0 additions & 23 deletions
23
metaconfig-core/shared/src/main/scala/metaconfig/DefaultValue.scala
This file was deleted.
Oops, something went wrong.
30 changes: 0 additions & 30 deletions
30
metaconfig-core/shared/src/main/scala/metaconfig/Field.scala
This file was deleted.
Oops, something went wrong.
59 changes: 9 additions & 50 deletions
59
metaconfig-core/shared/src/main/scala/metaconfig/Metaconfig.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 |
---|---|---|
@@ -1,62 +1,21 @@ | ||
package metaconfig | ||
|
||
import scala.collection.mutable | ||
import scala.meta.inputs.Input | ||
import scala.meta.inputs.Position | ||
import scala.meta.internal.inputs._ | ||
|
||
trait MetaconfigParser { | ||
def fromInput(input: Input): Configured[Conf] | ||
} | ||
import metaconfig.internal.ConfGet | ||
|
||
@deprecated( | ||
"Moved to metaconfig.internal.ConfGet. Use Conf.get* variants instead.", | ||
"0.6") | ||
object Metaconfig { | ||
|
||
def getKey(obj: Conf, keys: Seq[String]): Option[Conf] = | ||
if (keys.isEmpty) None | ||
else { | ||
obj match { | ||
case obj @ Conf.Obj(_) => | ||
obj.values | ||
.collectFirst { case (key, value) if key == keys.head => value } | ||
.orElse(getKey(obj, keys.tail)) | ||
case _ => None | ||
} | ||
} | ||
ConfGet.getKey(obj, keys) | ||
|
||
def getOrElse[T](conf: Conf, default: T, path: String, extraNames: String*)( | ||
implicit ev: ConfDecoder[T]): Configured[T] = { | ||
getKey(conf, path +: extraNames) match { | ||
case Some(value) => ev.read(value) | ||
case None => Configured.Ok(default) | ||
} | ||
} | ||
implicit ev: ConfDecoder[T]): Configured[T] = | ||
ConfGet.getOrElse[T](conf, default, path) | ||
|
||
def get[T](conf: Conf, path: String, extraNames: String*)( | ||
implicit ev: ConfDecoder[T]): Configured[T] = { | ||
getKey(conf, path +: extraNames) match { | ||
case Some(value) => ev.read(value) | ||
case None => | ||
conf match { | ||
case obj @ Conf.Obj(_) => ConfError.missingField(obj, path).notOk | ||
case _ => | ||
ConfError | ||
.typeMismatch(s"Conf.Obj with field $path", conf, path) | ||
.notOk | ||
} | ||
} | ||
} | ||
implicit ev: ConfDecoder[T]): Configured[T] = | ||
ConfGet.get[T](conf, path, extraNames: _*) | ||
|
||
// Copy-pasted from scala.meta inputs because it's private. | ||
// TODO(olafur) expose utility in inputs to get offset from line | ||
private[metaconfig] def getOffsetByLine(chars: Array[Char]): Array[Int] = { | ||
val buf = new mutable.ArrayBuffer[Int] | ||
buf += 0 | ||
var i = 0 | ||
while (i < chars.length) { | ||
if (chars(i) == '\n') buf += (i + 1) | ||
i += 1 | ||
} | ||
if (buf.last != chars.length) buf += chars.length // sentinel value used for binary search | ||
buf.toArray | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
metaconfig-core/shared/src/main/scala/metaconfig/MetaconfigParser.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,7 @@ | ||
package metaconfig | ||
|
||
import org.langmeta.inputs.Input | ||
|
||
trait MetaconfigParser { | ||
def fromInput(input: Input): Configured[Conf] | ||
} |
1 change: 1 addition & 0 deletions
1
metaconfig-core/shared/src/main/scala/metaconfig/String2AnyMap.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
2 changes: 1 addition & 1 deletion
2
...c/main/scala/metaconfig/Annotations.scala → ...a/metaconfig/annotation/Annotations.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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package metaconfig | ||
package metaconfig.annotation | ||
|
||
import scala.annotation.StaticAnnotation | ||
|
||
|
Oops, something went wrong.