Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add a function (getEnvironment) so that snaplets can get the environm…

…ent string
  • Loading branch information...
commit 2bba6f45c577d5423b1af42e90eee7ac09d09a7e 1 parent efdb064
@pjones pjones authored
View
1  src/Snap/Snaplet.hs
@@ -93,6 +93,7 @@ module Snap.Snaplet
, addPostInitHookBase
, printInfo
, getRoutes
+ , getEnvironment
-- * Routes
-- $routes
View
8 src/Snap/Snaplet/Internal/Initializer.hs
@@ -22,6 +22,7 @@ module Snap.Snaplet.Internal.Initializer
, loadAppConfig
, printInfo
, getRoutes
+ , getEnvironment
, modifyMaster
) where
@@ -85,6 +86,13 @@ iGets f = Initializer $ do
getRoutes :: Initializer b v [ByteString]
getRoutes = liftM (map fst) $ iGets _handlers
+------------------------------------------------------------------------------
+-- | Return the current environment string. This will be the
+-- environment given to 'runSnaplet' or from the command line when
+-- using 'serveSnaplet'. Usefully for changing behavior during
+-- development and testing.
+getEnvironment :: Initializer b v String
+getEnvironment = iGets _environment
------------------------------------------------------------------------------
-- | Converts a plain hook into a Snaplet hook.
View
3  test/suite/Snap/Snaplet/Internal/Tests.hs
@@ -82,6 +82,9 @@ appInit = makeSnaplet "app" "Test application" Nothing $ do
configAssertions "root "
([], cwd, Just "app", "Test application", "")
+
+ assertGet "environment" getEnvironment "devel"
+
f <- nestSnaplet "foo" foo $ fooInit
b <- nestSnaplet "bar" bar $ barInit
return $ App f b

0 comments on commit 2bba6f4

Please sign in to comment.
Something went wrong with that request. Please try again.