This repository has been archived by the owner on Jun 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #40 from safareli/import
Make sure we only `import` directory
- Loading branch information
Showing
5 changed files
with
108 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
module SqlSquared.Path | ||
( AnyFilePath | ||
, AnyDirPath | ||
, parseAnyFilePath | ||
, printAnyFilePath | ||
, parseAnyDirPath | ||
, printAnyDirPath | ||
, genAnyFilePath | ||
, genAnyDirPath | ||
) where | ||
|
||
import Prelude | ||
import Data.Either as E | ||
import Data.NonEmpty ((:|)) | ||
import Data.Path.Pathy as Pt | ||
import Data.Path.Pathy.Gen as PtGen | ||
import Control.Monad.Gen as Gen | ||
import Control.Monad.Rec.Class (class MonadRec) | ||
import SqlSquared.Utils ((∘)) | ||
|
||
type AnyDirPath = E.Either (Pt.AbsDir Pt.Unsandboxed) (Pt.RelDir Pt.Unsandboxed) | ||
type AnyFilePath = E.Either (Pt.AbsFile Pt.Unsandboxed) (Pt.RelFile Pt.Unsandboxed) | ||
|
||
printAnyDirPath :: AnyDirPath -> String | ||
printAnyDirPath = E.either Pt.unsafePrintPath Pt.unsafePrintPath | ||
|
||
parseAnyDirPath :: forall m. Applicative m => (forall a. String -> m a) -> String -> m AnyDirPath | ||
parseAnyDirPath fail = Pt.parsePath | ||
(pure ∘ E.Right) | ||
(pure ∘ E.Left) | ||
(const $ fail "Expected a directory path") | ||
(const $ fail "Expected a directory path") | ||
|
||
printAnyFilePath :: AnyFilePath -> String | ||
printAnyFilePath = E.either Pt.unsafePrintPath Pt.unsafePrintPath | ||
|
||
parseAnyFilePath :: forall m. Applicative m => (forall a. String -> m a) -> String -> m AnyFilePath | ||
parseAnyFilePath fail = Pt.parsePath | ||
(const $ fail "Expected a file path") | ||
(const $ fail "Expected a file path") | ||
(pure ∘ E.Right) | ||
(pure ∘ E.Left) | ||
|
||
genAnyFilePath :: forall m. Gen.MonadGen m => MonadRec m => m AnyFilePath | ||
genAnyFilePath = Gen.oneOf | ||
$ (E.Left ∘ Pt.unsandbox <$> PtGen.genAbsFilePath) | ||
:| [E.Right ∘ Pt.unsandbox <$> PtGen.genRelFilePath] | ||
|
||
genAnyDirPath :: forall m. Gen.MonadGen m => MonadRec m => m AnyDirPath | ||
genAnyDirPath = Gen.oneOf | ||
$ (E.Left ∘ Pt.unsandbox <$> PtGen.genAbsDirPath) | ||
:| [E.Right ∘ Pt.unsandbox <$> PtGen.genRelDirPath] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters