conf-json (empty) → 1.0
raw patch · 7 files changed
+188/−0 lines, 7 filesdep +QuickCheckdep +aesondep +basesetup-changed
Dependencies added: QuickCheck, aeson, base, binary, bytestring, conf-json, directory, hspec
Files
- PublicDomain +24/−0
- Setup.hs +2/−0
- changelog.md +5/−0
- conf-json.cabal +69/−0
- src/Data/Conf/Json.hs +46/−0
- test/Main.hs +7/−0
- test/Test/TestParse.hs +35/−0
+ PublicDomain view
@@ -0,0 +1,24 @@+This is free and unencumbered software released into the public domain.++Anyone is free to copy, modify, publish, use, compile, sell, or+distribute this software, either in source code form or as a compiled+binary, for any purpose, commercial or non-commercial, and by any+means.++In jurisdictions that recognize copyright laws, the author or authors+of this software dedicate any and all copyright interest in the+software to the public domain. We make this dedication for the benefit+of the public at large and to the detriment of our heirs and+successors. We intend this dedication to be an overt act of+relinquishment in perpetuity of all present and future rights to this+software under copyright law.++THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.+IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR+OTHER DEALINGS IN THE SOFTWARE.++For more information, please refer to <http://unlicense.org>
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ changelog.md view
@@ -0,0 +1,5 @@+##### 1.0+ initial version+ + test pass +
+ conf-json.cabal view
@@ -0,0 +1,69 @@+name: conf-json+version: 1.0+synopsis: read, parse json config+description: read, parse json config to a Haskell type+author: Imants Cekusins+maintainer: Imants Cekusins+category: Configuration+license: PublicDomain+license-file: PublicDomain+extra-source-files: changelog.md++cabal-version: >=1.10+build-type: Simple+homepage: https://github.com/ciez/conf-json+source-repository head+ type: git+ location: https://github.com/ciez/conf-json.git+ ++library+ exposed-modules:+ Data.Conf.Json+ + ghc-options: -fwarn-unused-imports + + build-depends: base >=4.8 && <5.0,+ directory,+ bytestring,+ aeson+ + hs-source-dirs: src+ default-language: Haskell2010+ default-extensions: FlexibleInstances+ MultiParamTypeClasses+ TypeSynonymInstances+ BangPatterns+ InstanceSigs+ OverloadedStrings+ FunctionalDependencies+ StandaloneDeriving+++test-suite spec+ default-language:Haskell2010+ type: exitcode-stdio-1.0+ ghc-options: -fwarn-unused-imports+ hs-source-dirs: test, src+ default-extensions: FlexibleInstances+ MultiParamTypeClasses+ TypeSynonymInstances+ BangPatterns+ InstanceSigs+ OverloadedStrings+ FunctionalDependencies+ StandaloneDeriving+ DeriveGeneric++ main-is: Main.hs+ other-modules:+ Test.TestParse++ build-depends: base >= 4.8,+ hspec >= 2.1.7,+ QuickCheck >= 2.8.1,+ binary,+ bytestring,+ directory,+ aeson,+ conf-json
+ src/Data/Conf/Json.hs view
@@ -0,0 +1,46 @@+{- | reads config or any valid json file and parses it to a Haskell type ++arg: full or relative (to current directory) path to the json file ++@+import Data.Aeson+import GHC.Generics++data TestProp = TestProp {+ prop::Int+ } deriving (Generic,Eq,Show)++instance FromJSON TestProp +@+-}+module Data.Conf.Json+ (readParse) where++import Data.Aeson as A+import Data.ByteString as B+import Data.ByteString.Lazy as L+import Prelude as P+import System.Directory as D+import System.IO as I+++readParse::FromJSON conf =>+ FilePath -> IO (Either String conf)+readParse fullPath0 = do+ tbs1 <- readEntireFile fullPath0::IO (Either String B.ByteString)+ pure $ tbs1 >>= + Right . toLazy >>=+ eitherDecode' -- ::Either String Config+++readEntireFile::FilePath -> IO (Either String B.ByteString)+readEntireFile path0 = do+ exists1 <- doesFileExist path0+ if exists1 then do+ a1 <- withBinaryFile path0 ReadMode B.hGetContents+ pure $ Right a1+ else pure $ Left $ "file n/a: " ++ path0+++toLazy::B.ByteString -> L.ByteString+toLazy bs0 = L.fromChunks [bs0]
+ test/Main.hs view
@@ -0,0 +1,7 @@+module Main where++import qualified Test.TestParse as T+++main::IO()+main = T.main
+ test/Test/TestParse.hs view
@@ -0,0 +1,35 @@+module Test.TestParse where++import Test.Hspec+import Data.Aeson+import GHC.Generics+import Data.Conf.Json as J+++main::IO()+main = hspec $ do+ describe "Test.TestParse" $ do+ it "case 1" $ do+ econf1 <- readParse "./test/Test/test-conf.json" + econf1 `shouldBe` (Right expect1)+ where expect1 = TestConf {+ a = 1,+ b = "val b",+ arr = [TestProp 10, TestProp 12]+ }+ ++data TestProp = TestProp {+ prop::Int+ } deriving (Generic,Eq,Show)+++data TestConf = TestConf {+ a::Int,+ b::String,+ arr::[TestProp]+ } deriving (Generic,Eq,Show)+++instance FromJSON TestProp +instance FromJSON TestConf