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

Safe HaskellSafe-Inferred



Various functions used inside Gitson.



entryPath :: FilePath -> String -> FilePathSource

Combines two paths and adds the .json extension.

>>> entryPath "things" "entry"
>>> entryPath "things/" "entry"

lockPath :: FilePathSource

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"]

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

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

insideDirectory :: FilePath -> IO a -> IO aSource

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 StringSource

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

shell :: String -> [String] -> IO ()Source

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

intoMaybe :: Maybe a -> b -> Maybe (a, b)Source

Adds a value to a Maybe.

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"

nextKeyId :: [String] -> IntSource

Returns the next numeric id in a sequence of keys.

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