Skip to content

Commit

Permalink
Tidying up module structure
Browse files Browse the repository at this point in the history
  • Loading branch information
sordina committed Jan 9, 2015
1 parent fb11c9f commit 6bb613b
Show file tree
Hide file tree
Showing 8 changed files with 101 additions and 23 deletions.
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,8 @@ todo:

docker-build:
./scripts/docker-build

dot:
find src -name '*.hs' | xargs graphmod -q > doc/modules.dot
dot -Tpng doc/modules.dot > doc/modules.png
open doc/modules.png
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,10 @@ You can look for incomplete items in the source by running `make todo`.
* Use more qualified imports, including for internal imports
* Narrow package dependency versions
* Random number generation as-per the spec
* Adopt a more layered aproach for internal organisation with an 'apps' layer before Deadpan.hs
* Adopt a more layered aproach (see doc/dot.png)
* Use proper opt-parser for main module
* Try out a auth example
* Non Negative GUID Strings


## Binaries
Expand Down
65 changes: 65 additions & 0 deletions doc/modules.dot
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
digraph G {
size="6,4";
ratio="fill";
u5[label="Main"];
subgraph cluster_0 {
label="Data";
color="#ccffcc";
style="filled";
u4[label="EJson"];
subgraph cluster_1 {
label="EJson";
color="#99ff99";
style="filled";
u3[label="Props"];
u2[label="EJson2Value"];
u1[label="EJson"];
u0[label="Aeson"];

}

}
subgraph cluster_2 {
label="Web";
color="#ccffcc";
style="filled";
subgraph cluster_3 {
label="DDP";
color="#99ff99";
style="filled";
u11[label="Deadpan"];
subgraph cluster_4 {
label="Deadpan";
color="#66ff66";
style="filled";
u10[label="Websockets"];
u9[label="GUID"];
u8[label="DSL"];
u7[label="Comms"];
u6[label="Callbacks"];

}

}

}
u0 -> u1;
u0 -> u2;
u2 -> u1;
u3 -> u4;
u4 -> u0;
u4 -> u1;
u4 -> u2;
u5 -> u11;
u6 -> u8;
u7 -> u4;
u8 -> u4;
u8 -> u7;
u8 -> u9;
u9 -> u4;
u11 -> u6;
u11 -> u8;
u11 -> u10;

}

Binary file added doc/modules.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 18 additions & 1 deletion src/Data/EJson.hs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ module Data.EJson (

module Exports,

decodeText,
decodeString,
decodeByteString,

matches,

getInPath,
Expand Down Expand Up @@ -66,9 +70,22 @@ import Data.EJson.EJson2Value as Exports
import Data.Monoid as Exports
import Control.Lens as Exports
import Control.Monad.State (execState)
import Data.Text (Text())
import Data.Text (Text())
import Data.Aeson (decode)
import Data.EJson.Aeson()

import qualified Data.HashMap.Strict as HM
import qualified Data.ByteString.Lazy.Char8 as C8
import qualified Data.Text as T

decodeText :: Text -> Maybe EJsonValue
decodeText = decodeString . T.unpack

decodeString :: String -> Maybe EJsonValue
decodeString = decode . C8.pack

decodeByteString :: C8.ByteString -> Maybe EJsonValue
decodeByteString = decode

-- $setup
-- >>> :set -XOverloadedStrings
Expand Down
2 changes: 1 addition & 1 deletion src/Data/EJson/Aeson.hs
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ instance FromJSON EJsonValue where parseJSON = return . value2EJson
-- take advantage of the Aeson functionality.
--
-- This is not used internally.
instance ToJSON EJsonValue where toJSON = ejson2value
instance ToJSON EJsonValue where toJSON = ejson2value
25 changes: 9 additions & 16 deletions src/Data/EJson/Props.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,7 @@
module Data.EJson.Props where

import Data.EJson
import Data.EJson.Aeson ()

import Data.Maybe
import Data.Aeson
import qualified Data.ByteString.Lazy as BS

-- $setup
-- >>> import Control.Applicative
Expand Down Expand Up @@ -53,44 +49,41 @@ prop_ejarrayixtest_array = ejarray ["hello"]

-- Examples from real apps

decodeEJ :: BS.ByteString -> Maybe EJsonValue
decodeEJ = decode

ttt :: (a -> Bool) -> Maybe a -> Bool
ttt f v = Just True == fmap f v

-- | prop> prop_decodable_1
prop_decodable_1 :: Bool
prop_decodable_1 = ttt isEJDate $ decodeEJ "{\"$date\":1418373430495}"
prop_decodable_1 = ttt isEJDate $ decodeByteString "{\"$date\":1418373430495}"

-- | prop> prop_decodable_2
prop_decodable_2 :: Bool
prop_decodable_2 = ttt isEJObject $ decodeEJ "{\"msg\":\"added\",\"collection\":\"todos\",\"id\":\"jsoQsi4QWhTjyLM3v\",\"fields\":{\"checked\":false,\"createdAt\":{\"$date\":1418373430495},\"listId\":\"By8CtgWGvbZfJPFsd\",\"text\":\"Data on the Wire\"}}"
prop_decodable_2 = ttt isEJObject $ decodeByteString "{\"msg\":\"added\",\"collection\":\"todos\",\"id\":\"jsoQsi4QWhTjyLM3v\",\"fields\":{\"checked\":false,\"createdAt\":{\"$date\":1418373430495},\"listId\":\"By8CtgWGvbZfJPFsd\",\"text\":\"Data on the Wire\"}}"

-- | prop> prop_decodable_3
prop_decodable_3 :: Bool
prop_decodable_3 = ttt isEJObject $ decodeEJ "{\"msg\":\"ready\",\"subs\":[\"42463a77-578f-4503-8d2b-637a3c6c9ed6\"]}"
prop_decodable_3 = ttt isEJObject $ decodeByteString "{\"msg\":\"ready\",\"subs\":[\"42463a77-578f-4503-8d2b-637a3c6c9ed6\"]}"

-- | prop> prop_decodable_4
prop_decodable_4 :: Bool
prop_decodable_4 = ttt isEJObject $ decodeEJ "{\"msg\":\"added\",\"collection\":\"lists\",\"id\":\"By8CtgWGvbZfJPFsd\",\"fields\":{\"name\":\"Meteor Principles\",\"incompleteCount\":6}}"
prop_decodable_4 = ttt isEJObject $ decodeByteString "{\"msg\":\"added\",\"collection\":\"lists\",\"id\":\"By8CtgWGvbZfJPFsd\",\"fields\":{\"name\":\"Meteor Principles\",\"incompleteCount\":6}}"

-- | prop> prop_decodable_5
prop_decodable_5 :: Bool
prop_decodable_5 = ttt isEJObject $ decodeEJ "{\"msg\":\"added\",\"collection\":\"lists\",\"id\":\"sqrAXjWmzAE6WZhdf\",\"fields\":{\"name\":\"Languages\",\"incompleteCount\":6}}"
prop_decodable_5 = ttt isEJObject $ decodeByteString "{\"msg\":\"added\",\"collection\":\"lists\",\"id\":\"sqrAXjWmzAE6WZhdf\",\"fields\":{\"name\":\"Languages\",\"incompleteCount\":6}}"

-- | prop> prop_decodable_6
prop_decodable_6 :: Bool
prop_decodable_6 = ttt isEJObject $ decodeEJ "{\"msg\":\"added\",\"collection\":\"lists\",\"id\":\"F73xFyAuKrqsb2J3m\",\"fields\":{\"name\":\"Favorite Scientists\",\"incompleteCount\":6}}"
prop_decodable_6 = ttt isEJObject $ decodeByteString "{\"msg\":\"added\",\"collection\":\"lists\",\"id\":\"F73xFyAuKrqsb2J3m\",\"fields\":{\"name\":\"Favorite Scientists\",\"incompleteCount\":6}}"

-- | prop> prop_decodable_7
prop_decodable_7 :: Bool
prop_decodable_7 = ttt isEJObject $ decodeEJ "{\"msg\":\"added\",\"collection\":\"lists\",\"id\":\"pY53869jRS5LdLuze\",\"fields\":{\"incompleteCount\":0,\"name\":\"List foo\"}}"
prop_decodable_7 = ttt isEJObject $ decodeByteString "{\"msg\":\"added\",\"collection\":\"lists\",\"id\":\"pY53869jRS5LdLuze\",\"fields\":{\"incompleteCount\":0,\"name\":\"List foo\"}}"

-- | prop> prop_decodable_8
prop_decodable_8 :: Bool
prop_decodable_8 = ttt isEJObject $ decodeEJ "{\"msg\":\"ready\",\"subs\":[\"8a82270b-8087-4dcc-90d3-ae758d236056\"]}"
prop_decodable_8 = ttt isEJObject $ decodeByteString "{\"msg\":\"ready\",\"subs\":[\"8a82270b-8087-4dcc-90d3-ae758d236056\"]}"

-- | prop> prop_decodable_9
prop_decodable_9 :: Bool
prop_decodable_9 = ttt isEJObject $ decodeEJ "{\"msg\":\"added\",\"collection\":\"todos\",\"id\":\"wf2dBLkR78vebkPMf\",\"fields\":{\"checked\":true,\"createdAt\":{\"$date\":1418373430499},\"listId\":\"By8CtgWGvbZfJPFsd\",\"text\":\"Full Stack Reactivity\"}}"
prop_decodable_9 = ttt isEJObject $ decodeByteString "{\"msg\":\"added\",\"collection\":\"todos\",\"id\":\"wf2dBLkR78vebkPMf\",\"fields\":{\"checked\":true,\"createdAt\":{\"$date\":1418373430499},\"listId\":\"By8CtgWGvbZfJPFsd\",\"text\":\"Full Stack Reactivity\"}}"
5 changes: 1 addition & 4 deletions src/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,8 @@ import System.IO
import System.Exit
import Web.DDP.Deadpan
import System.Environment
import Data.Aeson
import Data.Maybe
import Control.Concurrent.Chan
import Data.EJson.Aeson()
import qualified Data.ByteString.Lazy.Char8 as C8
import qualified System.Console.Haskeline as R

main :: IO ()
Expand Down Expand Up @@ -53,7 +50,7 @@ inOutLoop c = do

sendPossibleMessage :: String -> DeadpanApp ()
sendPossibleMessage msgStr = do
let decoded = decode $ C8.pack msgStr
let decoded = decodeString msgStr
case decoded of Just m -> sendData m
Nothing -> liftIO $ putStrLn "Invalid Message"

Expand Down

0 comments on commit 6bb613b

Please sign in to comment.