packages feed

gitson 0.2.0 → 0.2.1

raw patch · 3 files changed

+29/−15 lines, 3 filesdep +aeson-prettyPVP ok

version bump matches the API change (PVP)

Dependencies added: aeson-pretty

API changes (from Hackage documentation)

Files

gitson.cabal view
@@ -1,8 +1,8 @@ name:            gitson-version:         0.2.0+version:         0.2.1 synopsis:        A document store library for Git + JSON. description:     A simple document store library for Git + JSON, based on Aeson. Uses command line git, at least for now. No fancy indexes and stuff, but it does what I need right now. Transactions use flock, so it's safe even across completely separate programs!-category:        Database+category:        Database, JSON, Git homepage:        https://github.com/myfreeweb/gitson author:          Greg V copyright:       2014 Greg V <floatboth@me.com>@@ -32,6 +32,7 @@       , errors       , flock       , aeson+      , aeson-pretty     default-language: Haskell2010     exposed-modules:         Gitson
library/Gitson.hs view
@@ -1,5 +1,14 @@ -- | Gitson is a simple document store library for Git + JSON.-module Gitson (module Gitson) where+module Gitson (+  TransactionWriter,+  createRepo,+  transaction,+  saveEntry,+  readEntry,+  listEntryKeys,+  listEntries,+  listCollections+) where  import           System.Directory import           System.Lock.FLock@@ -8,11 +17,15 @@ import           Control.Error.Util import           Control.Monad.Trans.Writer import           Control.Monad.IO.Class (liftIO)-import           Data.Aeson (ToJSON, encode, FromJSON, decode)+import           Data.Aeson (ToJSON, FromJSON, decode)+import           Data.Aeson.Encode.Pretty import           Data.Maybe (fromMaybe) import qualified Data.ByteString.Lazy as BL import           Gitson.Util +-- | A transaction monad.+type TransactionWriter = WriterT [IO ()] IO ()+ -- | Creates a git repository under a given path. createRepo :: FilePath -> IO () createRepo path = do@@ -21,15 +34,6 @@     shell "git" ["init"]     writeFile lockPath "" --- | A transaction monad.-type TransactionWriter = WriterT [IO ()] IO ()---- | Adds a write action to a transaction.-saveEntry :: ToJSON a => FilePath -> FilePath -> a -> TransactionWriter-saveEntry collection key content = do-  liftIO $ createDirectoryIfMissing True collection-  tell [BL.writeFile (entryPath collection key) (encode content)]- -- | Executes a blocking transaction on a repository, committing the results to git. transaction :: FilePath -> TransactionWriter -> IO () transaction repoPath action = do@@ -39,6 +43,15 @@     sequence_ writeActions     shell "git" ["add", "--all"]     shell "git" ["commit", "-m", "Gitson transaction"]++prettyConfig :: Config+prettyConfig = Config { confIndent = 2, confCompare = compare }++-- | Adds a write action to a transaction.+saveEntry :: ToJSON a => FilePath -> FilePath -> a -> TransactionWriter+saveEntry collection key content = do+  liftIO $ createDirectoryIfMissing True collection+  tell [BL.writeFile (entryPath collection key) (encodePretty' prettyConfig content)]  -- | Reads an entry from a collection by key. readEntry :: FromJSON a => FilePath -> FilePath -> IO (Maybe a)
test-suite/GitsonSpec.hs view
@@ -26,9 +26,9 @@         liftIO $ (readFile "things/second-thing.json") `shouldThrow` anyIOException       insideDirectory "tmp/repo" $ do         first <- readFile "things/first-thing.json"-        first `shouldBe` "{\"val\":1}"+        first `shouldBe` "{\n  \"val\": 1\n}"         second <- readFile "things/second-thing.json"-        second `shouldBe` "{\"val\":2}"+        second `shouldBe` "{\n  \"val\": 2\n}"         commitMsg <- lastCommitText         commitMsg `shouldBe` "Gitson transaction"