packages feed

aeson-iproute 0.1.2 → 0.1.3

raw patch · 3 files changed

+68/−10 lines, 3 filesdep +doctestdep +unordered-containersdep ~basedep ~iproutePVP ok

version bump matches the API change (PVP)

Dependencies added: doctest, unordered-containers

Dependency ranges changed: base, iproute

API changes (from Hackage documentation)

+ Data.Aeson.IP: instance (Data.Aeson.Types.FromJSON.FromJSONKey k, GHC.Read.Read (Data.IP.Range.AddrRange k), Data.IP.RouteTable.Internal.Routable k) => Data.Aeson.Types.FromJSON.FromJSON1 (Data.IP.RouteTable.Internal.IPRTable k)
+ Data.Aeson.IP: instance (Data.Aeson.Types.FromJSON.FromJSONKey k, GHC.Read.Read (Data.IP.Range.AddrRange k), Data.IP.RouteTable.Internal.Routable k, Data.Aeson.Types.FromJSON.FromJSON v) => Data.Aeson.Types.FromJSON.FromJSON (Data.IP.RouteTable.Internal.IPRTable k v)
+ Data.Aeson.IP: instance (Data.IP.RouteTable.Internal.Routable k, GHC.Show.Show k, Data.Aeson.Types.ToJSON.ToJSON k) => Data.Aeson.Types.ToJSON.ToJSON1 (Data.IP.RouteTable.Internal.IPRTable k)
+ Data.Aeson.IP: instance (Data.IP.RouteTable.Internal.Routable k, GHC.Show.Show k, Data.Aeson.Types.ToJSON.ToJSON k, Data.Aeson.Types.ToJSON.ToJSON v) => Data.Aeson.Types.ToJSON.ToJSON (Data.IP.RouteTable.Internal.IPRTable k v)

Files

Data/Aeson/IP.hs view
@@ -7,11 +7,15 @@ import Control.Applicative (pure) #endif -import Data.Aeson-import Data.Aeson.Types-import Data.IP+import           Data.Aeson+import           Data.Aeson.Types+import           Data.Aeson.Internal+import qualified Data.HashMap.Strict as HashMap+import           Data.IP+import           Data.IP.RouteTable (Routable, IPRTable)+import qualified Data.IP.RouteTable as RouteTable import qualified Data.Text as Text-import Text.Read (readMaybe)+import           Text.Read (readMaybe)  instance FromJSON IPv4 where     parseJSON (String s)@@ -25,6 +29,10 @@                           Just r -> pure r                           Nothing -> fail "Unable to parse IPv4" +-- | The @ToJSON@ instance produces JSON strings matching the @Show@ instance.+--+-- >>> toJSON (toIPv4 [127,0,0,1])+-- String "127.0.0.1" instance ToJSON IPv4 where     toJSON = String . Text.pack . show @@ -43,6 +51,10 @@                           Just r -> pure r                           Nothing -> fail "Unable to parse IPv6" +-- | The @ToJSON@ instance produces JSON strings matching the @Show@ instance.+--+-- >>> toJSON (toIPv6 [0x2001,0xDB8,0,0,0,0,0,1])+-- String "2001:db8::1" instance ToJSON IPv6 where     toJSON = String . Text.pack . show @@ -102,3 +114,33 @@  instance ToJSONKey IPRange where     toJSONKey = toJSONKeyText (Text.pack . show)++instance ( FromJSONKey k+         , Read (AddrRange k)+         , Routable k+         ) => FromJSON1 (IPRTable k) where+    liftParseJSON p _ = case fromJSONKey of+        FromJSONKeyTextParser f -> withObject "IPRTable k v" $+            HashMap.foldrWithKey+                (\k v rt -> RouteTable.insert <$> f k <?> Key k+                                              <*> p v <?> Key k+                                              <*> rt)+                (pure RouteTable.empty)+        _ -> \_ -> fail "using IPRTable in this context is not yet supported"++instance ( FromJSONKey k+         , Read (AddrRange k)+         , Routable k+         , FromJSON v+         ) => FromJSON (IPRTable k v) where+    parseJSON = parseJSON1++instance (Routable k, Show k, ToJSON k) => ToJSON1 (IPRTable k) where+    liftToJSON g _ = case toJSONKey of+        ToJSONKeyText f _ -> Object . HashMap.fromList+                                    . map (\(k, v) -> (f k, g v))+                                    . RouteTable.toList+        _ -> error "using IPRTable as a JSON key is not yet supported"++instance (Routable k, Show k, ToJSON k, ToJSON v) => ToJSON (IPRTable k v) where+    toJSON = toJSON1
aeson-iproute.cabal view
@@ -2,7 +2,7 @@ -- documentation, see http://haskell.org/cabal/users-guide/  name:                aeson-iproute-version:             0.1.2+version:             0.1.3 synopsis:            Aeson instances for iproute types description:         Aeson instances for iproute types. license:             BSD3@@ -13,14 +13,15 @@ category:            Data build-type:          Simple cabal-version:       >=1.10-Tested-With: GHC == 7.10.3, GHC == 8.0.2, GHC == 8.2.2+Tested-With:         GHC == 8.0.2, GHC == 8.2.2, GHC == 8.4.4, GHC == 8.6.5, GHC == 8.8.3  library   exposed-modules:     Data.Aeson.IP-  build-depends:       base >=4 && <5,-                       aeson >= 0.8,-                       iproute >= 1.5,-                       text >= 1.0+  build-depends:       aeson >= 0.8,+                       base >=4 && <5,+                       iproute >= 1.7.3,+                       text >= 1.0,+                       unordered-containers                                                     default-language:    Haskell2010@@ -29,3 +30,12 @@ source-repository head   type: git   location: https://github.com/greydot/aeson-iproute.git++test-suite doctest+  type:                 exitcode-stdio-1.0+  hs-source-dirs:       test+  main-is:              doctests.hs+  build-depends:        base >= 4.6 && < 5,+                        doctest >= 0.9.3++  default-language:     Haskell2010
+ test/doctests.hs view
@@ -0,0 +1,6 @@+module Main where++import Test.DocTest++main :: IO ()+main = doctest ["Data/Aeson/IP.hs"]