conferer 0.1.0.2 → 0.1.0.3
raw patch · 3 files changed
+23/−3 lines, 3 filesPVP: minor bump suggested
API additions: PVP suggests at least a minor version bump
API changes (from Hackage documentation)
+ Conferer.FetchFromConfig.Basics: instance Conferer.Types.FetchFromConfig GHC.Integer.Type.Integer
+ Conferer.FetchFromConfig.Basics: instance Conferer.Types.FetchFromConfig a => Conferer.Types.FetchFromConfig (GHC.Maybe.Maybe a)
Files
- conferer.cabal +2/−2
- src/Conferer/FetchFromConfig/Basics.hs +10/−1
- test/Conferer/FetchFromConfig/BasicsSpec.hs +11/−0
conferer.cabal view
@@ -4,10 +4,10 @@ -- -- see: https://github.com/sol/hpack ----- hash: a30bb964060c98a8149ad2b98ca2bfc764e40aac9a70c603ab2e27722c25d131+-- hash: 45fd44d5d84b2f4cd58f0b44ccd4cea950effce5e344718897c38433efc2764a name: conferer-version: 0.1.0.2+version: 0.1.0.3 synopsis: Configuration management library description: Library to abstract the parsing of many haskell config values from different config sources
src/Conferer/FetchFromConfig/Basics.hs view
@@ -15,6 +15,9 @@ instance FetchFromConfig Int where fetch = fetchFromConfigByRead +instance FetchFromConfig Integer where+ fetch = fetchFromConfigByRead+ instance FetchFromConfig Float where fetch = fetchFromConfigByRead @@ -24,6 +27,13 @@ instance FetchFromConfig ByteString where fetch = fetchFromConfigWith (Just . Text.encodeUtf8) +instance FetchFromConfig a => FetchFromConfig (Maybe a) where+ fetch k c = do+ v <- getKey k c+ if v == Right ""+ then return (Right Nothing)+ else fmap Just <$> fetch k c+ instance FetchFromConfig String where fetch = fetchFromConfigWith (Just . Text.unpack) @@ -38,7 +48,6 @@ "false" -> Just False "true" -> Just True _ -> Nothing- fromValueWith :: (Text -> Maybe a) -> Key -> Text -> Either Text a fromValueWith parseValue key valueAsText = case parseValue valueAsText of Just value -> Right value
test/Conferer/FetchFromConfig/BasicsSpec.hs view
@@ -54,3 +54,14 @@ config <- configWith [ ("aFloat", "ASD") ] fetchedValue <- fetch "aFloat" config fetchedValue `shouldBe` (Left "Key aFloat could not be parsed correctly" :: Either Text Float)++ describe "fetching a Maybe from config" $ do+ it "getting a value returns the value as a Just string" $ do+ config <- configWith [ ("aString", "Bleh") ]+ fetchedValue <- fetch "aString" config+ fetchedValue `shouldBe` (Right (Just "Bleh") :: Either Text (Maybe String))+ context "with an empty value that's present" $ do+ it "returns Nothing" $ do+ config <- configWith [ ("aString", "") ]+ fetchedValue <- fetch "aString" config+ fetchedValue `shouldBe` (Right Nothing :: Either Text (Maybe String))