slackbuilder/lib/SlackBuilder/Trans.hs
Eugen Wissner e5bde183a5
Some checks failed
Build / audit (push) Successful in 14m44s
Build / test (push) Failing after 5m47s
Support extracting gzip on the fly
2024-03-03 17:12:29 +01:00

62 lines
1.7 KiB
Haskell

{- This Source Code Form is subject to the terms of the Mozilla Public License,
v. 2.0. If a copy of the MPL was not distributed with this file, You can
obtain one at https://mozilla.org/MPL/2.0/. -}
-- | Transformers and exceptions.
module SlackBuilder.Trans
( SlackBuilderException(..)
, SlackBuilderT(..)
, relativeToRepository
) where
import Control.Monad.Trans.Reader (ReaderT(..), asks)
import Data.Text (Text)
import SlackBuilder.Config
import Control.Monad.IO.Class (MonadIO(..))
import Control.Monad.Catch (MonadCatch(..), MonadThrow(..))
import Control.Exception (Exception(..))
import System.FilePath ((</>))
import Text.URI (URI)
data SlackBuilderException
= UpdaterNotFound Text
| HttpsUrlExpected URI
deriving Show
instance Exception SlackBuilderException
newtype SlackBuilderT a = SlackBuilderT
{ runSlackBuilderT :: ReaderT Settings IO a
}
relativeToRepository :: FilePath -> SlackBuilderT FilePath
relativeToRepository filePath =
(</> filePath) <$> SlackBuilderT (asks repository)
instance Functor SlackBuilderT
where
fmap f (SlackBuilderT slackBuilderT) = SlackBuilderT $ f <$> slackBuilderT
instance Applicative SlackBuilderT
where
pure = SlackBuilderT . pure
(SlackBuilderT f) <*> (SlackBuilderT x) = SlackBuilderT $ f <*> x
instance Monad SlackBuilderT
where
return = pure
(SlackBuilderT x) >>= f = SlackBuilderT $ x >>= runSlackBuilderT . f
instance MonadIO SlackBuilderT
where
liftIO = SlackBuilderT . liftIO
instance MonadThrow SlackBuilderT
where
throwM = SlackBuilderT . throwM
instance MonadCatch SlackBuilderT
where
catch (SlackBuilderT action) handler =
SlackBuilderT $ catch action $ runSlackBuilderT . handler