Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SymbolReader #28

Merged
merged 1 commit into from
May 27, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main/scala/net/ceedubs/ficus/Ficus.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import com.typesafe.config.Config
import net.ceedubs.ficus.readers._
import scala.language.implicitConversions

trait FicusInstances extends AnyValReaders with StringReader with OptionReader
trait FicusInstances extends AnyValReaders with StringReader with SymbolReader with OptionReader
with CollectionReaders with ConfigReader with DurationReaders
with TryReader with ConfigValueReader with BigNumberReaders
with ISOZonedDateTimeReader
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package net.ceedubs.ficus.readers

trait AllValueReaderInstances extends AnyValReaders with StringReader with OptionReader
trait AllValueReaderInstances extends AnyValReaders with StringReader with SymbolReader with OptionReader
with CollectionReaders with ConfigReader with DurationReaders with ArbitraryTypeReader
with TryReader with ConfigValueReader

Expand Down
11 changes: 11 additions & 0 deletions src/main/scala/net/ceedubs/ficus/readers/SymbolReader.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package net.ceedubs.ficus.readers

import com.typesafe.config.Config

trait SymbolReader {
implicit val symbolValueReader: ValueReader[Symbol] = new ValueReader[Symbol] {
def read(config: Config, path: String): Symbol = Symbol(config.getString(path))
}
}

object SymbolReader extends SymbolReader
16 changes: 16 additions & 0 deletions src/test/scala/net/ceedubs/ficus/readers/SymbolReaderSpec.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package net.ceedubs.ficus
package readers

import com.typesafe.config.ConfigFactory
import ConfigSerializerOps._

class SymbolReaderSpec extends Spec with SymbolReader { def is = s2"""
The Symbol value reader should
read a Symbol $readSymbol
"""

def readSymbol = prop { string: String =>
val cfg = ConfigFactory.parseString(s"myValue = ${string.asConfigValue}")
symbolValueReader.read(cfg, "myValue") must beEqualTo(Symbol(string))
}
}