dotenv 0.5.2.3 → 0.5.2.4
raw patch · 5 files changed
+51/−10 lines, 5 filesdep ~exceptionsdep ~yamlPVP: minor bump suggested
API additions: PVP suggests at least a minor version bump
Dependency ranges changed: exceptions, yaml
API changes (from Hackage documentation)
+ Configuration.Dotenv.Scheme: checkScheme :: [Env] -> [Env]
+ Configuration.Dotenv.Scheme.Types: instance GHC.Classes.Ord Configuration.Dotenv.Scheme.Types.Env
+ Configuration.Dotenv.Scheme.Types: instance GHC.Classes.Ord Configuration.Dotenv.Scheme.Types.EnvType
Files
- CHANGELOG.md +5/−0
- dotenv.cabal +6/−6
- spec/Configuration/Dotenv/SchemeSpec.hs +21/−1
- src/Configuration/Dotenv/Scheme.hs +16/−1
- src/Configuration/Dotenv/Scheme/Types.hs +3/−2
CHANGELOG.md view
@@ -1,5 +1,10 @@ ## MASTER+## Dotenv 0.5.2.4+* Add error message when there is more than one definition in the Scheme for the+same env+ ## Dotenv 0.5.2.3+* Update bounds `exceptions` == 0.9.* * Support `megaparsec` >= 6.4.0 ## Dotenv 0.5.2.1
dotenv.cabal view
@@ -1,5 +1,5 @@ name: dotenv-version: 0.5.2.3+version: 0.5.2.4 synopsis: Loads environment variables from dotenv files homepage: https://github.com/stackbuilders/dotenv-hs description:@@ -65,7 +65,7 @@ , process >= 1.4.3.0 , text , transformers >=0.4 && < 0.6- , yaml+ , yaml >= 0.8 other-modules: Paths_dotenv hs-source-dirs: app@@ -93,8 +93,8 @@ , process >= 1.4.3.0 , text , transformers >=0.4 && < 0.6- , exceptions >= 0.8 && < 0.9- , yaml+ , exceptions >= 0.8 && < 0.10+ , yaml >= 0.8 if !impl(ghc >= 7.10) build-depends: void == 0.7.*@@ -135,9 +135,9 @@ , process >= 1.4.3.0 , text , transformers >=0.4 && < 0.6- , exceptions >= 0.8 && < 0.9+ , exceptions >= 0.8 && < 0.10 , hspec-megaparsec >= 1.0 && < 2.0- , yaml+ , yaml >= 0.8 if !impl(ghc >= 7.10) build-depends: void == 0.7.*
spec/Configuration/Dotenv/SchemeSpec.hs view
@@ -2,11 +2,31 @@ import Configuration.Dotenv.Scheme import Configuration.Dotenv.Scheme.Types+import Control.Exception (evaluate) import Test.Hspec spec :: Spec-spec =+spec = do+ describe "checkScheme" $ do+ context "when the env configs are unique" $+ it "should succeed the check" $+ let schemeEnvs =+ [ Env "FOO" EnvBool True+ , Env "BAR" EnvInteger True+ ]+ in checkScheme schemeEnvs `shouldBe` schemeEnvs++ context "when there are duplicated env configs" $+ it "should fail the check" $+ let schemeEnvs =+ [ Env "FOO" EnvBool True+ , Env "BAR" EnvInteger True+ , Env "FOO" EnvInteger True+ ]+ msg = "Duplicated env variable configuration in schema: FOO"+ in evaluate (checkScheme schemeEnvs) `shouldThrow` errorCall msg+ describe "checkConfig" $ context "when the envs have the correct type" $ do context "when the envs in the dotenvs are defined in the scheme" $ do
src/Configuration/Dotenv/Scheme.hs view
@@ -1,5 +1,6 @@ module Configuration.Dotenv.Scheme ( checkConfig+ , checkScheme , loadSafeFile , runSchemaChecker )@@ -8,6 +9,7 @@ import Control.Monad import Control.Monad.IO.Class (MonadIO(..)) +import Data.List import Data.Yaml (decodeFileEither, prettyPrintParseException) import Text.Megaparsec import System.Directory (doesFileExist)@@ -27,7 +29,7 @@ -> m [(String, String)] loadSafeFile schemaFile config = do envs <- loadFile config- liftIO (readScheme schemaFile >>= checkConfig envs)+ liftIO (readScheme schemaFile >>= checkConfig envs . checkScheme) return envs readScheme :: FilePath -> IO [Env]@@ -36,6 +38,19 @@ case eitherEnvConf of Right envConfs -> return envConfs Left errorYaml -> error (prettyPrintParseException errorYaml)++checkScheme :: [Env] -> [Env]+checkScheme envConfs =+ case duplicatedConfs of+ [] -> envConfs+ dups -> error (duplicatedConfErrorMsg $ uniqueConfs dups)+ where+ duplicatedConfs = deleteFirstsBy confEquals envConfs (uniqueConfs envConfs)+ uniqueConfs = nubBy confEquals+ a `confEquals` b = envName a == envName b++duplicatedConfErrorMsg :: [Env] -> String+duplicatedConfErrorMsg = ("Duplicated env variable configuration in schema: " ++) . showMissingDotenvs checkConfig :: [(String, String)]
src/Configuration/Dotenv/Scheme/Types.hs view
@@ -13,7 +13,8 @@ data EnvType = EnvInteger | EnvBool- | EnvText deriving (Show, Eq)+ | EnvText+ deriving (Show, Eq, Ord) instance FromJSON EnvType where parseJSON (String "integer") = pure EnvInteger@@ -27,7 +28,7 @@ { envName :: String , envType :: EnvType , required :: Bool- } deriving (Show, Eq)+ } deriving (Show, Eq, Ord) instance FromJSON Env where parseJSON (Object m) =