interpolator 0.1.2 → 1.0.0
raw patch · 2 files changed
+13/−18 lines, 2 files
Files
- interpolator.cabal +2/−2
- src/Data/Interpolation.hs +11/−16
interpolator.cabal view
@@ -4,10 +4,10 @@ -- -- see: https://github.com/sol/hpack ----- hash: 99eadf3b4df4c6738c42e6f6e4789426dc11140f7faae6ecb7253fc6017283a2+-- hash: 979db35e1db7cb62265111ec02f96847dd76e6fe139072073c2b4c0030bb7f85 name: interpolator-version: 0.1.2+version: 1.0.0 synopsis: Runtime interpolation of environment variables in records using profunctors description: Runtime interpolation of environment variables in records using profunctors. See the [README](https://github.com/tvision-insights/interpolator/blob/master/README.md).
src/Data/Interpolation.hs view
@@ -18,7 +18,7 @@ import Data.Set (Set) import qualified Data.Text as T import System.Environment (getEnvironment)-import Test.QuickCheck (Arbitrary, Gen, arbitrary, frequency, listOf1, oneof, suchThat)+import Test.QuickCheck (Arbitrary, Arbitrary1, arbitrary, arbitrary1, liftArbitrary, listOf1, oneof, suchThat) import Text.Read (readMaybe) -- |Newtype wrapper for an environment variable key.@@ -184,24 +184,19 @@ Templated x -> toJSON x Literal x -> toJSON x -maybeGen :: Gen a -> Gen (Maybe a)-maybeGen x = frequency [(1, pure Nothing), (3, Just <$> x)]--noEnv, varNameAllowed :: Gen T.Text-noEnv = fmap T.pack $ arbitrary `suchThat` (\ s -> not ("_env:" `isPrefixOf` s) && not (null s))-varNameAllowed = fmap T.pack . listOf1 $ arbitrary `suchThat` (\c -> isAlphaNum c || c == '_')- instance Arbitrary TemplateKey where arbitrary = TemplateKey <$> varNameAllowed+ where varNameAllowed = fmap T.pack . listOf1 $ arbitrary `suchThat` (\c -> isAlphaNum c || c == '_') -instance {-# OVERLAPPABLE #-} Arbitrary a => Arbitrary (Uninterpolated a) where- arbitrary = oneof- [ Literal <$> arbitrary- , Templated <$> (Template <$> arbitrary <*> arbitrary)+instance Arbitrary1 Uninterpolated where+ liftArbitrary g = oneof+ [ Literal <$> g+ , Templated <$> (Template <$> arbitrary <*> liftArbitrary g) ] +instance {-# OVERLAPPABLE #-} Arbitrary a => Arbitrary (Uninterpolated a) where+ arbitrary = arbitrary1+ instance {-# OVERLAPPING #-} Arbitrary (Uninterpolated T.Text) where- arbitrary = oneof- [ Literal <$> noEnv- , Templated <$> (Template <$> arbitrary <*> maybeGen noEnv)- ]+ arbitrary = liftArbitrary noEnv+ where noEnv = fmap T.pack $ arbitrary `suchThat` (\ s -> not ("_env:" `isPrefixOf` s) && not (null s))