conferer 0.1.0.1 → 0.1.0.2
raw patch · 5 files changed
+47/−36 lines, 5 filessetup-changedPVP: minor bump suggested
API additions: PVP suggests at least a minor version bump
API changes (from Hackage documentation)
+ Conferer.FetchFromConfig.Basics: findKeyAndApplyConfig :: FetchFromConfig newvalue => Config -> Key -> Key -> (newvalue -> config -> config) -> Either Text config -> IO (Either Text config)
Files
- LICENSE +17/−26
- Setup.hs +2/−0
- conferer.cabal +2/−2
- src/Conferer.hs +7/−7
- src/Conferer/FetchFromConfig/Basics.hs +19/−1
LICENSE view
@@ -1,30 +1,21 @@-Copyright Lucas David Traverso (c) 2018--All rights reserved.--Redistribution and use in source and binary forms, with or without-modification, are permitted provided that the following conditions are met:+MIT License - * Redistributions of source code must retain the above copyright- notice, this list of conditions and the following disclaimer.+Copyright (c) 2019 Lucas David Traverso - * Redistributions in binary form must reproduce the above- copyright notice, this list of conditions and the following- disclaimer in the documentation and/or other materials provided- with the distribution.+Permission is hereby granted, free of charge, to any person obtaining a copy+of this software and associated documentation files (the "Software"), to deal+in the Software without restriction, including without limitation the rights+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell+copies of the Software, and to permit persons to whom the Software is+furnished to do so, subject to the following conditions: - * Neither the name of Lucas David Traverso nor the names of other- contributors may be used to endorse or promote products derived- from this software without specific prior written permission.+The above copyright notice and this permission notice shall be included in all+copies or substantial portions of the Software. -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS-"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT-LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR-A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT-OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,-SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT-LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,-DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY-THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT-(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE-OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE+SOFTWARE.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
conferer.cabal view
@@ -4,10 +4,10 @@ -- -- see: https://github.com/sol/hpack ----- hash: a139753b9c1bc2266c7b90feb57d35995b1b57ffa23dcf6f7d8a2b8dad4a7238+-- hash: a30bb964060c98a8149ad2b98ca2bfc764e40aac9a70c603ab2e27722c25d131 name: conferer-version: 0.1.0.1+version: 0.1.0.2 synopsis: Configuration management library description: Library to abstract the parsing of many haskell config values from different config sources
src/Conferer.hs view
@@ -16,13 +16,13 @@ -- command line arguments of @.properties@ files -- -- @- -- > import Conferer- -- > import Conferer.FetchFromConfig.Warp () -- from package conferer-warp- -- >- -- > main = do- -- > config <- 'defaultConfig' \"awesomeapp\"- -- > warpSettings <- 'getFromConfig' \"warp\" config- -- > runSettings warpSettings application+ -- import Conferer+ -- import Conferer.FetchFromConfig.Warp () -- from package conferer-warp+ --+ -- main = do+ -- config <- 'defaultConfig' \"awesomeapp\"+ -- warpSettings <- 'getFromConfig' \"warp\" config+ -- runSettings warpSettings application -- @ -- -- In the above example we see that we are getting a configuration value for
src/Conferer/FetchFromConfig/Basics.hs view
@@ -2,7 +2,7 @@ module Conferer.FetchFromConfig.Basics where import Conferer.Types-import Conferer.Core (getKey)+import Conferer.Core (getKey, (/.)) import Data.Text (Text) import qualified Data.Text as Text import qualified Data.Text.Encoding as Text@@ -47,3 +47,21 @@ fetchFromConfigWith :: (Text -> Maybe a) -> Key -> Config -> IO (Either Text a) fetchFromConfigWith parseValue key config = (fromValueWith parseValue key =<<) <$> getKey key config++-- | Concatenate many transformations to the config based on keys and functions+findKeyAndApplyConfig ::+ FetchFromConfig newvalue+ => Config -- ^ Complete config+ -> Key -- ^ Key that indicates the part of the config that we care about+ -> Key -- ^ Key that we use to find the config (usually concatenating with the+ -- other key)+ -> (newvalue -> config -> config) -- ^ Function that knows how to use the+ -- value to update the config+ -> Either Text config -- ^ Result of the last config updating+ -> IO (Either Text config) -- ^ Updated config+findKeyAndApplyConfig config k relativeKey f (Right customConfig) =+ fetch (k /. relativeKey) config+ >>= \case+ Left a -> return $ Right customConfig+ Right a -> return $ Right $ f a customConfig+findKeyAndApplyConfig config k relativeKey f (Left e) = return $ Left e