gitson-0.5.1: A document store library for Git + JSON.

Safe HaskellSafe
LanguageHaskell2010

Gitson.Util

Description

Various functions used inside Gitson.

Synopsis

Documentation

documentPath :: FilePath -> String -> FilePath Source

Combines two paths and adds the .json extension.

>>> documentPath "things" "document"
"things/document.json"
>>> documentPath "things/" "document"
"things/document.json"

lockPath :: FilePath Source

Path to the transaction lock file, relative to the repo root.

filterFilenamesAsKeys :: [FilePath] -> [String] Source

Turns a list of filenames into a list of keys, ignoring non-JSON files.

>>> filterFilenamesAsKeys [".", "..", "k1.json", "unrelated.file"]
["k1"]

filterDirs :: [FilePath] -> IO [FilePath] Source

Filters a list of file paths, leaving only paths to existing non-hidden directories.

insideDirectory :: MonadIO i => FilePath -> i a -> i a Source

Returns an IO action that switches the current directory to a given path, executes the given IO action and switches the current directory back.

lastCommitText :: IO String Source

Returns the message of the last git commit in the repo where the current directory is located.

shell :: MonadIO i => String -> [String] -> i () Source

Runs a shell command with stdin, stdout and stderr set to devnull.

intoFunctor :: Functor f => f a -> b -> f (a, b) Source

Appends a value to a functor, making the inside a tuple if it's a single value.

>>> intoFunctor (Just 1) 2
Just (1,2)
>>> intoFunctor Nothing 2
Nothing

maybeReadIntString :: String -> Maybe (Int, String) Source

Tries to extract the first int out of a string.

>>> maybeReadIntString "0123-hell0w0rld"
Just (123,"-hell0w0rld")
>>> maybeReadIntString "1"
Just (1,"")
>>> maybeReadIntString "hello"
Nothing

nextKeyId :: [String] -> Int Source

Returns the next numeric id in a sequence of keys.

>>> nextKeyId []
1
>>> nextKeyId ["aaaaarrrrrrrrrrr"]
1
>>> nextKeyId ["1-hell0-w0rld-123456.json", "002-my-second-post.json"]
3