packages feed

lackey 0.1.2 → 0.2.0

raw patch · 9 files changed

+8/−107 lines, 9 filesdep ~servant

Dependency ranges changed: servant

Files

lackey.cabal view
@@ -3,7 +3,7 @@ -- see: https://github.com/sol/hpack  name:           lackey-version:        0.1.2+version:        0.2.0 synopsis:       Generate Ruby consumers of Servant APIs. description:    Lackey generates Ruby consumers of Servant APIs. category:       Web@@ -31,7 +31,7 @@   ghc-options: -Wall   build-depends:       base >=4.7 && <4.9-    , servant >=0.4 && <0.5+    , servant >=0.4 && <0.6   exposed-modules:       Lackey       Lackey.Internal@@ -39,7 +39,6 @@       Lackey.Internal.HasCode       Lackey.Internal.HasRuby       Lackey.Internal.Header-      Lackey.Internal.MatrixItem       Lackey.Internal.Method       Lackey.Internal.PathSegment       Lackey.Internal.QueryItem
library/Lackey/Internal.hs view
@@ -6,7 +6,6 @@     ( module Lackey.Internal.Endpoint     , module Lackey.Internal.HasCode     , module Lackey.Internal.HasRuby-    , module Lackey.Internal.MatrixItem     , module Lackey.Internal.Method     , module Lackey.Internal.PathSegment     , module Lackey.Internal.QueryItem@@ -15,7 +14,6 @@ import Lackey.Internal.Endpoint import Lackey.Internal.HasCode import Lackey.Internal.HasRuby-import Lackey.Internal.MatrixItem import Lackey.Internal.Method import Lackey.Internal.PathSegment import Lackey.Internal.QueryItem
library/Lackey/Internal/HasCode.hs view
@@ -9,7 +9,6 @@ import GHC.TypeLits (KnownSymbol, symbolVal) import Lackey.Internal.Endpoint import Lackey.Internal.Header-import Lackey.Internal.MatrixItem import Lackey.Internal.Method import Lackey.Internal.PathSegment import Lackey.Internal.QueryItem@@ -74,32 +73,6 @@         b = Proxy :: Proxy b         segments = endpointPathSegments e ++ [segment]         segment = PathCapture (symbolVal s)-        s = Proxy :: Proxy s---- Matrix items--instance (KnownSymbol s, HasCode a) => HasCode (S.MatrixFlag s :> a) where-    type Ruby (S.MatrixFlag s :> a) = Ruby a-    codeFor _ e = codeFor a (e { endpointPathSegments = segments }) where-        a = Proxy :: Proxy a-        segments = endpointPathSegments e ++ [segment]-        segment = PathMatrix (MatrixFlag (symbolVal s))-        s = Proxy :: Proxy s--instance (KnownSymbol s, HasCode b) => HasCode (S.MatrixParam s a :> b) where-    type Ruby (S.MatrixParam s a :> b) = Ruby b-    codeFor _ e = codeFor b (e { endpointPathSegments = segments }) where-        b = Proxy :: Proxy b-        segments = endpointPathSegments e ++ [segment]-        segment = PathMatrix (MatrixParam (symbolVal s))-        s = Proxy :: Proxy s--instance (KnownSymbol s, HasCode b) => HasCode (S.MatrixParams s a :> b) where-    type Ruby (S.MatrixParams s a :> b) = Ruby b-    codeFor _ e = codeFor b (e { endpointPathSegments = segments }) where-        b = Proxy :: Proxy b-        segments = endpointPathSegments e ++ [segment]-        segment = PathMatrix (MatrixParams (symbolVal s))         s = Proxy :: Proxy s  -- Query items
library/Lackey/Internal/HasRuby.hs view
@@ -4,7 +4,6 @@  import Lackey.Internal.Endpoint import Lackey.Internal.Header-import Lackey.Internal.MatrixItem import Lackey.Internal.PathSegment import Lackey.Internal.QueryItem import Servant.API ((:<|>)(..))@@ -48,13 +47,10 @@          renderPathSegment (PathLiteral literal) = literal         renderPathSegment (PathCapture capture) = capture-        renderPathSegment (PathMatrix (MatrixFlag flag)) = flag-        renderPathSegment (PathMatrix (MatrixParam param)) = param-        renderPathSegment (PathMatrix (MatrixParams params)) = params         pathSegments =             let segments = endpointPathSegments endpoint                 renderedSegments = map renderPathSegment segments-            in  if all isPathMatrix segments+            in  if null segments                 then "index" : renderedSegments                 else renderedSegments         path = List.intercalate "_" pathSegments@@ -85,15 +81,6 @@             & map renderPathSegment             & Maybe.catMaybes -        renderMatrixItem (PathMatrix (MatrixFlag flag)) = Just (sanitize flag ++ ": false")-        renderMatrixItem (PathMatrix (MatrixParam param)) = Just (sanitize param ++ ": nil")-        renderMatrixItem (PathMatrix (MatrixParams params)) = Just (sanitize params ++ ": []")-        renderMatrixItem _ = Nothing-        matrixItems-            = endpoint-            & endpointPathSegments-            & Maybe.mapMaybe renderMatrixItem-         renderQueryItem (QueryFlag flag) = Just (sanitize flag ++ ": false")         renderQueryItem (QueryParam param) = Just (sanitize param ++ ": nil")         renderQueryItem (QueryParams params) = Just (sanitize params ++ ": []")@@ -108,7 +95,7 @@         body = ["body" | endpointHasBody endpoint]      in  List.intercalate ", "-        (concat [["excon"], pathSegments, body, matrixItems, queryItems, headers])+        (concat [["excon"], pathSegments, body, queryItems, headers])  renderMethod :: Endpoint -> String renderMethod endpoint = endpoint & endpointMethod & show & map Char.toLower@@ -117,15 +104,11 @@ renderPath endpoint =     let renderPathSegment (PathLiteral literal) = '/' : literal         renderPathSegment (PathCapture capture) = concat ["/#{", sanitize capture, "}"]-        renderPathSegment (PathMatrix (MatrixFlag flag)) = concat ["#{\";", flag, "\" if ", sanitize flag, "}"]-        renderPathSegment (PathMatrix (MatrixParam param)) = concat [";", param, "=#{", sanitize param, "}"]-        renderPathSegment (PathMatrix (MatrixParams params)) = concat ["#{", sanitize params, ".map { |x| \";", params, "[]=#{x}\" }.join}"]         pathSegments =             let segments = endpointPathSegments endpoint                 renderedSegments = concatMap renderPathSegment segments             in  case segments of                 [] -> '/' : renderedSegments-                (PathMatrix _ : _) -> '/' : renderedSegments                 _ -> renderedSegments          renderQueryItem (QueryFlag flag) = concat ["#{\"&", flag, "\" if ", sanitize flag, "}"]
− library/Lackey/Internal/MatrixItem.hs
@@ -1,7 +0,0 @@-module Lackey.Internal.MatrixItem where--data MatrixItem-    = MatrixFlag String-    | MatrixParam String-    | MatrixParams String-    deriving (Eq, Ord, Read, Show)
library/Lackey/Internal/PathSegment.hs view
@@ -1,13 +1,6 @@ module Lackey.Internal.PathSegment where -import Lackey.Internal.MatrixItem (MatrixItem)- data PathSegment     = PathLiteral String     | PathCapture String-    | PathMatrix MatrixItem     deriving (Eq, Ord, Read, Show)--isPathMatrix :: PathSegment -> Bool-isPathMatrix (PathMatrix _) = True-isPathMatrix _ = False
package.yaml view
@@ -12,7 +12,7 @@ library:   dependencies:   - base >=4.7 && <4.9-  - servant >=0.4 && <0.5+  - servant >=0.4 && <0.6   source-dirs: library license: MIT maintainer: Taylor Fausak@@ -28,4 +28,4 @@     - tasty-hspec >=1.1 && <1.2     source-dirs: test-suite     main: Main.hs-version: '0.1.2'+version: '0.2.0'
stack.yaml view
@@ -1,3 +1,5 @@+extra-deps:+- servant-0.5 install-ghc: true require-stack-version: ! '>=1.0.4' resolver: lts-5.8
test-suite/Main.hs view
@@ -72,21 +72,6 @@             rubyForAPI api `shouldBe`                 ruby "get_id" ", id" "get" "#{id}" "" "nil" -        it "supports matrix flags" $ do-            let api = Proxy :: Proxy (MatrixFlag "flag" :> Get '[] ())-            rubyForAPI api `shouldBe`-                ruby "get_index_flag" ", flag: false" "get" "#{\";flag\" if flag}" "" "nil"--        it "supports matrix params" $ do-            let api = Proxy :: Proxy (MatrixParam "param" () :> Get '[] ())-            rubyForAPI api `shouldBe`-                ruby "get_index_param" ", param: nil" "get" ";param=#{param}" "" "nil"--        it "supports multiple matrix params" $ do-            let api = Proxy :: Proxy (MatrixParams "params" () :> Get '[] ())-            rubyForAPI api `shouldBe`-                ruby "get_index_params" ", params: []" "get" "#{params.map { |x| \";params[]=#{x}\" }.join}" "" "nil"-         it "supports query flags" $ do             let api = Proxy :: Proxy (QueryFlag "flag" :> Get '[] ())             rubyForAPI api `shouldBe`@@ -126,11 +111,6 @@             rubyForAPI api `shouldBe`                 ruby "get_index" "" "get" "" "" "nil" -        it "always starts the path with a slash" $ do-            let api = Proxy :: Proxy (MatrixFlag "a" :> "b" :> Get '[] ())-            rubyForAPI api `shouldBe`-                ruby "get_a_b" ", a: false" "get" "#{\";a\" if a}/b" "" "nil"-         it "puts the body param after captures" $ do             let api = Proxy :: Proxy (Capture "segment" () :> ReqBody '[] () :> Get '[] ())             rubyForAPI api `shouldBe`@@ -141,11 +121,6 @@             rubyForAPI api `shouldBe`                 ruby "get_index_flag" ", body, flag: false" "get" "?#{\"&flag\" if flag}" "" "body" -        it "puts the body param before matrix params" $ do-            let api = Proxy :: Proxy (MatrixFlag "flag" :> ReqBody '[] () :> Get '[] ())-            rubyForAPI api `shouldBe`-                ruby "get_index_flag" ", body, flag: false" "get" "#{\";flag\" if flag}" "" "body"-         it "sanitizes path segments" $ do             let api = Proxy :: Proxy ("A!" :> Get '[] ())             rubyForAPI api `shouldBe`@@ -155,21 +130,6 @@             let api = Proxy :: Proxy (Capture "A!" () :> Get '[] ())             rubyForAPI api `shouldBe`                 ruby "get_a_" ", a_" "get" "#{a_}" "" "nil"--        it "sanitizes matrix flags" $ do-            let api = Proxy :: Proxy (MatrixFlag "A!" :> Get '[] ())-            rubyForAPI api `shouldBe`-                ruby "get_index_a_" ", a_: false" "get" "#{\";A!\" if a_}" "" "nil"--        it "sanitizes matrix params" $ do-            let api = Proxy :: Proxy (MatrixParam "A!" () :> Get '[] ())-            rubyForAPI api `shouldBe`-                ruby "get_index_a_" ", a_: nil" "get" ";A!=#{a_}" "" "nil"--        it "sanitizes multiple matrix params" $ do-            let api = Proxy :: Proxy (MatrixParams "A!" () :> Get '[] ())-            rubyForAPI api `shouldBe`-                ruby "get_index_a_" ", a_: []" "get" "#{a_.map { |x| \";A![]=#{x}\" }.join}" "" "nil"          it "sanitizes query flags" $ do             let api = Proxy :: Proxy (QueryFlag "A!" :> Get '[] ())