Skip to content

Commit

Permalink
add missing INLINABLEs
Browse files Browse the repository at this point in the history
  • Loading branch information
hendi committed Sep 2, 2021
1 parent 6f48acf commit 5ecb542
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion IHP/ValidationSupport/ValidateField.hs
Expand Up @@ -129,6 +129,7 @@ validateAny validators text =
case any isSuccess $ map ($ text) validators of
True -> Success
False -> Failure "did not pass any validators"
{-# INLINABLE validateAny #-}


-- | Validates that value passes all of the given validators
Expand All @@ -146,6 +147,8 @@ validateAll validators text =
in case all isSuccess results of
True -> Success
False -> (filter isFailure results) !! 0
{-# INLINABLE validateAll #-}


-- | Validates that value is not empty
--
Expand Down Expand Up @@ -389,6 +392,7 @@ isColor = validateAny [isRgbHexColor, isRgbaHexColor, isRgbColor, isRgbaColor]
|> withCustomErrorMessage "is not a valid color"
{-# INLINABLE isColor #-}


-- | Validates string starts with @http://@ or @https://@
--
-- >>> isUrl "https://digitallyinduced.com"
Expand All @@ -405,7 +409,7 @@ isUrl text = Failure "is not a valid url. It needs to start with http:// or http
isInList :: (Eq value, Show value) => [value] -> value -> ValidatorResult
isInList list value | list |> includes value = Success
isInList list value = Failure ("is not allowed. It needs to be one of the following: " <> (tshow list))

{-# INLINABLE isInList #-}

-- | Validates that value is True
--
Expand All @@ -416,6 +420,7 @@ isInList list value = Failure ("is not allowed. It needs to be one of the follow
-- Failure "This field cannot be false"
isTrue :: Bool -> ValidatorResult
isTrue value = if value then Success else Failure "This field cannot be false"
{-# INLINABLE isTrue #-}


-- | Validates that value is False
Expand All @@ -427,6 +432,7 @@ isTrue value = if value then Success else Failure "This field cannot be false"
-- Failure "This field cannot be true"
isFalse :: Bool -> ValidatorResult
isFalse value = if not value then Success else Failure "This field cannot be true"
{-# INLINABLE isFalse #-}


-- | Validates that value is matched by the regular expression
Expand All @@ -442,6 +448,7 @@ isFalse value = if not value then Success else Failure "This field cannot be tru
--
matchesRegex :: Text -> Text -> ValidatorResult
matchesRegex regex text = if text =~ regex then Success else Failure $ "This field does not match the regular expression \"" <> regex <> "\""
{-# INLINABLE matchesRegex #-}


-- | Validates that value is a valid slug
Expand All @@ -454,3 +461,4 @@ matchesRegex regex text = if text =~ regex then Success else Failure $ "This fie
isSlug :: Text -> ValidatorResult
isSlug text | text =~ ("^[a-zA-Z0-9_-]+$" :: Text) = Success
isSlug text = Failure "is not a valid slug (consisting of only letters, numbers, underscores or hyphens)"
{-# INLINABLE isSlug #-}

0 comments on commit 5ecb542

Please sign in to comment.