Mixin that adds #check method to be used with variables of an instance of the class including it.
+The idea is to check the instance variables of the class extending it
+against rules defined with Check.rules plus executing custom checkers defined with Checker.
Mixin that adds .check method to be used with a Hash.
+The idea is to check a Hash against rules defined with Check.rules
+plus executing custom checkers defined with Checker annotation.
Lifecycle method triggered after each call of .check.
+
+
This method (in static call) must returns the cleaned Hash
+which is provided in the third argument.
+You can update this cleaned hash but you have to return it.
+
+
# Triggered on a static call: `User.check(h)` (with a `Hash` or `JSON::Any`)
+defself.after_check(v : Check::Validation, h, cleaned_h, required : Bool=true, format : Bool=true) : Hash
+ # Code...
+ pp cleaned_h
+ cleaned_h # <= returns cleaned_h!
+end
Lifecycle method triggered before each call of .check.
+
+
# Triggered on a static call: `User.check(h)` (with a `Hash` or `JSON::Any`)
+defself.before_check(v : Check::Validation, h, required : Bool=true, format : Bool=true)
+ # Code...
+ pp h
+end
Returns a Hash from a JSON input.
+The return type is a tuple with a bool as a first argument indicating
+that the JSON.parse has been processed successfully or not and the 2nd
+argument is the json Hash.
Combines a series of checks into one validation instance,
+with a customized error message for each case.
+
+
A Validation instance provides the means to write sequential checks,
+fine-tune each micro-validation with their own rules and custom error message,
+the possibility to retrieve all error messages, etc.
+
+
Validation is also used with Check.rules and Check.checkable
+that provide a powerful and productive system of validation rules
+which makes data cleaning and data validation in Crystal very easy.
+With self-generated granular methods for cleaning and checking data.
require"validator/check"
+
+# Validates the *user* data received in the HTTP controller or other.
+defvalidate_user(user : Hash) : Check::Validation
+ v =Check.new_validation
+
+ # -- email
+
+ # Hash key can be a String or a Symbol
+ v.check :email, "The email is required.", is :presence?, :email, user
+
+ v.check "email", "The email is required.", is :presence?, "email", user
+ v.check "email", "#{user["email"]} is an invalid email.", is :email?, user["email"]
+
+ # -- username
+
+ v.check "username", "The username is required.", is :presence?, "username", user
+
+ v.check(
+ "username",
+ "The username must contain at least 2 characters.",
+ is :min?, user["username"], 2
+ )
+
+ v.check(
+ "username",
+ "The username must contain a maximum of 20 characters.",
+ is :max?, user["username"], 20
+ )
+end
+
+v = validate_user user
+
+pp v.valid? # => true (or false)
+
+# Inverse of v.valid?
+if v.errors.empty?
+ return"no error"
+end
+
+# display all the errors (if any)
+pp v.errors
+
+# It's a Hash of Array
+errors = v.errors
+
+puts errors.size
+puts errors.first_value
+
+errors.each do|key, messages|
+ puts key # => "username"
+ puts messages # => ["The username is required.", "etc..."]
+end
# check(key : Symbol | String, valid : Bool)
+# Using default standard error message
+v.check(
+ "username",
+ is(:min?, user["username"], 2)
+)
+
+# check(key : Symbol | String, message : String, valid : Bool)
+# Using custom error message
+v.check(
+ "username",
+ "The username must contain at least 2 characters.",
+ is(:min?, user["username"], 2)
+)
+
+# check(key : Symbol | String, valid : Bool, message : String)
+# Using custom error message
+v.check(
+ "username",
+ is(:min?, user["username"], 2),
+ "The username must contain at least 2 characters."
+)
+
+
Check is a simple and lightweight wrapper.
+Check::Validation is agnostic of the checked data,
+of the context (model, controller, CSV file, HTTP data, socket data, JSON, etc).
+
+
Use case example:
+ Before saving to the database or process user data for a particular task,
+ the custom error messages can be used for the end user response.
+
+
But a Validation instance can be used just to store validation errors:
If valid is false, the error message is added in the #errors.
+Nothing if valid is true.
+
+
v =Check.new_validation
+
+# -- email
+
+v.check :email, "The email is required.", is :presence?, :email, user
+v.check :email, "#{user[:email]} is an invalid email.", is :email?, user[:email]?
+
+# -- username
+
+v.check :username, "The username is required.", is :presence?, :username, user
+
+v.check(
+ :username,
+ "The username must contain at least 2 characters.",
+ is :min?, user[:username]?, 2
+)
+
+v.check(
+ :username,
+ "The username must contain a maximum of 20 characters.",
+ is :max?, user[:username]?, 20
+)
+
+# Print all errors
+pp v.errors
If valid is false, the error message is added in the #errors.
+Nothing if valid is true.
+
+
v =Check.new_validation
+
+# -- email
+
+v.check(:email, is(:presence?, :email, user), "The email is required.")
+v.check(:email, is(:email?, user[:email]?), "#{user[:email]} is an invalid email.")
+
+# -- username
+
+v.check(:username, is(:presence?, :username, user), "The username is required.")
+
+v.check(
+ :username,
+ is :min?, user[:username]?, 2,
+ "The username must contain at least 2 characters."
+)
+
+v.check(
+ :username,
+ is :max?, user[:username]?, 20,
+ "The username must contain a maximum of 20 characters."
+)
+
+# Print all errors
+pp v.errors
∠(・.-)―〉 →◎ validator is a Crystal data validation module.
+Very simple and efficient, all validations return true or false.
+
+
Also validator/check
+(not exposed by default) provides error message handling intended for the end user.
+
+
There are 2 main ways to use validator:
+
+
As a simple validator to check rules (eg: email, url, min, max, presence, in, ...) which return a boolean.
As a more advanced validation system which will check a series of rules
+ and returns all validation errors encountered with custom or standard messages.
+
+
By default the validator module expose only Validator and Valid (alias) in the scope:
An (optional) expressive validation flavor, is available as an alternative. \
+Not exposed by default, it must be imported:
+
+
require"validator/is"
+
+is :email?, "contact@example.org"# => true
+is :url?, "https://github.com/Nicolab/crystal-validator"# => true
+is :my_validator?, "value to validate", "hello", 42# => true
+
+# raises an error if the email is not valid
+is! :email?, "contact@@example..org"# => Validator::Error
+
+
is is a macro, no overhead during the runtime 🚀
+ By the nature of the macros, you can't pass the validator name dynamically
+ with a variable like that is(validator_name, "my value to validate", arg).
+ But of course you can pass arguments with variables is(:validator_name?, arg1, arg2).
Just add your own method to register a custom validator or to overload an existing validator.
+
+
moduleValidator
+ # My custom validator
+ defself.my_validator?(value, arg : String, another_arg : Int32) : Bool
+ # write here the logic of your validator...
+ returntrue
+ end
+end
+
+# Call it
+puts Valid.my_validator?("value to validate", "hello", 42) # => true
+
+# or with the `is` flavor
+puts is :my_validator?, "value to validate", "hello", 42# => true
+
+
Check is a simple and lightweight wrapper, let your imagination run wild to add your logic around it.
+
+
Using the custom validator with the validation rules:
+
+
require"validator/check"
+
+classArticle
+ # Mixin
+ Check.checkable
+
+ property title : String
+ property content : String
+
+ Check.rules(
+ content: {
+ # Now the custom validator is available
+ check: {
+ my_validator: {"My validator error message"},
+ between: {"The article content must be between 10 and 20 000 characters", 10, 20_000},
+ # ...
+ },
+ },
+ )
+end
+
+# Triggered with all data
+v, article =Article.check(input_data)
+
+# Triggered with one value
+v, content =Article.check_content(input_data["content"]?)
Validates that the value is an email.
+This method is stricter than the standard allows.
+It is subjectively based on the common addresses
+of organisations (@enterprise.ltd, ...)
+and mail services suck as Gmail, Hotmail, Yahoo !, ...
Validates that the value represents a JSON string.
+strict to true (default) to try to parse the JSON,
+returns false if the parsing fails.
+If strict is false, only the first char and the last char are checked.
As a simple validator to check rules (eg: email, url, min, max, presence, in, ...) which return a boolean.
As a more advanced validation system which will check a series of rules and returns all validation errors encountered with custom or standard messages.
As a system of validation rules (inspired by the Laravel framework's Validator)
+ which makes data cleaning and data validation in Crystal very easy!
+ With self-generated granular methods for cleaning and checking data of each field.
+
+
By default the validator module expose only Validator and Valid (alias) in the scope:
An (optional) expressive validation flavor, is available as an alternative.
+Not exposed by default, it must be imported:
+
+
require"validator/is"
+
+is :email?, "contact@example.org"# => true
+is :url?, "https://github.com/Nicolab/crystal-validator"# => true
+is :my_validator?, "value to validate", "hello", 42# => true
+
+
+# raises an error if the email is not valid
+is! :email?, "contact@@example..org"# => Validator::Error
+
+
is is a macro, no overhead during the runtime 🚀
+ By the nature of the macros, you can't pass the validator name dynamically with a variable like that is(validator_name, "my value to validate", arg).
+ But of course you can pass arguments with variables is(:validator_name?, arg1, arg2).
ok is a boolean value that reports whether the cast succeeded. Like the type assertions in Go (lang).
+But the ok value is returned in first (like in Elixir lang) for easy handling of multiple return values (Tuple).
So clean_email cast to String and strip the value " demo@example.org ":
+
+
# Email value with one space before and one space after
+ok, email =User.clean_email(value: " demo@example.org ")
+
+puts email # => "demo@example.org"
+
+
If the email was taken from a union type (json["email"]?), the returned email variable would be a String too.
NOTE: Require more explanations about required, nilable rules.
+> Also about the converters JSON / Crystal Hash: h_from_json, to_json_h, to_crystal_h.
+> In the meantime see the API doc.
To perform a series of validations with error handling, the validator/check module offers this possibility 👍
+
+
A Validation instance provides the means to write sequential checks, fine-tune each micro-validation with their own rules and custom error message, the possibility to retrieve all error messages, etc.
+
+
Validation is also used with Check.rules and Check.checkable
+ that provide a powerful and productive system of validation rules
+ which makes data cleaning and data validation in Crystal very easy.
+ With self-generated granular methods for cleaning and checking data.
+
+
To use the checker (check) includes in the Validation class:
+
+
require"validator/check"
+
+# Validates the *user* data received in the HTTP controller or other.
+defvalidate_user(user : Hash) : Check::Validation
+ v =Check.new_validation
+
+ # -- email
+
+ # Hash key can be a String or a Symbol
+ v.check :email, "The email is required.", is :presence?, :email, user
+
+ v.check "email", "The email is required.", is :presence?, "email", user
+ v.check "email", "#{user["email"]} is an invalid email.", is :email?, user["email"]
+
+ # -- username
+
+ v.check "username", "The username is required.", is :presence?, "username", user
+
+ v.check(
+ "username",
+ "The username must contain at least 2 characters.",
+ is :min?, user["username"], 2
+ )
+
+ v.check(
+ "username",
+ "The username must contain a maximum of 20 characters.",
+ is :max?, user["username"], 20
+ )
+end
+
+v = validate_user user
+
+pp v.valid? # => true (or false)
+
+# Inverse of v.valid?
+if v.errors.empty?
+ return"no error"
+end
+
+# Print all the errors (if any)
+pp v.errors
+
+# It's a Hash of Array
+errors = v.errors
+
+puts errors.size
+puts errors.first_value
+
+errors.each do|key, messages|
+ puts key # => "username"
+ puts messages # => ["The username is required.", "etc..."]
+end
# check(key : Symbol | String, valid : Bool)
+# Using default error message
+v.check(
+ "username",
+ is(:min?, user["username"], 2)
+)
+
+# check(key : Symbol | String, message : String, valid : Bool)
+# Using custom error message
+v.check(
+ "username",
+ "The username must contain at least 2 characters.",
+ is(:min?, user["username"], 2)
+)
+
+# check(key : Symbol | String, valid : Bool, message : String)
+# Using custom error message
+v.check(
+ "username",
+ is(:min?, user["username"], 2),
+ "The username must contain at least 2 characters."
+)
+
+
Check is a simple and lightweight wrapper.
+The Check::Validation is agnostic of the checked data,
+of the context (model, controller, CSV file, HTTP data, socket data, JSON, etc).
+
+
Use case example:
+ Before saving to the database or process user data for a particular task,
+ the custom error messages can be used for the end user response.
+
+
But a Validation instance can be used just to store validation errors:
Just add your own method to register a custom validator or to overload an existing validator.
+
+
moduleValidator
+ # My custom validator
+ defself.my_validator?(value, arg : String, another_arg : Int32) : Bool
+ # write here the logic of your validator...
+ returntrue
+ end
+end
+
+# Call it
+puts Valid.my_validator?("value to validate", "hello", 42) # => true
+
+# or with the `is` flavor
+puts is :my_validator?, "value to validate", "hello", 42# => true
+
+
Using the custom validator with the validation rules:
+
+
require"validator/check"
+
+classArticle
+ # Mixin
+ Check.checkable
+
+ property title : String
+ property content : String
+
+ Check.rules(
+ content: {
+ # Now the custom validator is available
+ check: {
+ my_validator: {"My validator error message"},
+ between: {"The article content must be between 10 and 20 000 characters", 10, 20_000},
+ # ...
+ },
+ },
+ )
+end
+
+# Triggered with all data
+v, article =Article.check(input_data)
+
+# Triggered with one value
+v, content =Article.check_content(input_data["content"]?)
Thanks to ilourt for his great work on checkable mixins (clean_, check_, ...).
+
+
+
diff --git a/docs/index.json b/docs/index.json
new file mode 100644
index 0000000..7a67937
--- /dev/null
+++ b/docs/index.json
@@ -0,0 +1 @@
+{"repository_name":"validator","body":"# validator\n\n[![Build Status](https://travis-ci.com/Nicolab/crystal-validator.svg?branch=master)](https://travis-ci.com/Nicolab/crystal-validator) [![GitHub release](https://img.shields.io/github/release/Nicolab/crystal-validator.svg)](https://github.com/Nicolab/crystal-validator/releases) [![Docs](https://img.shields.io/badge/docs-available-brightgreen.svg)](https://nicolab.github.io/crystal-validator/)\n\n∠(・.-)―〉 →◎ `validator` is a [Crystal](https://crystal-lang.org) data validation module. \nVery simple and efficient, all validations return `true` or `false`.\n\nAlso [validator/check](#check) (not exposed by default) provides:\n\n* Error message handling intended for the end user.\n* Also (optional) a powerful and productive system of validation rules.\n With self-generated granular methods for cleaning and checking data.\n\n**Validator** respects the [KISS principle](https://en.wikipedia.org/wiki/KISS_principle) and the [Unix Philosophy](https://en.wikipedia.org/wiki/Unix_philosophy). It's a great basis tool for doing your own validation logic on top of it.\n\n## Installation\n\n1. Add the dependency to your `shard.yml`:\n\n```yaml\ndependencies:\n validator:\n github: nicolab/crystal-validator\n version: ~> 1.1.0 # Check the latest version!\n```\n\n2. Run `shards install`\n\n## Usage\n\n* [Validator - API docs](https://nicolab.github.io/crystal-validator/)\n\nThere are 3 main ways to use *validator*:\n\n* As a simple validator to check rules (eg: email, url, min, max, presence, in, ...) which return a boolean.\n* As a more advanced validation system which will check a series of rules and returns all validation errors encountered with custom or standard messages.\n* As a system of validation rules (inspired by the _Laravel framework's Validator_)\n which makes data cleaning and data validation in Crystal very easy!\n With self-generated granular methods for cleaning and checking data of each field.\n\nBy default the **validator** module expose only `Validator` and `Valid` (alias) in the scope:\n\n```crystal\nrequire \"validator\"\n\nValid.email? \"contact@example.org\" # => true\nValid.url? \"https://github.com/Nicolab/crystal-validator\" # => true\nValid.my_validator? \"value to validate\", \"hello\", 42 # => true\n```\n\nAn (optional) expressive validation flavor, `is` available as an alternative.\nNot exposed by default, it must be imported:\n\n```crystal\nrequire \"validator/is\"\n\nis :email?, \"contact@example.org\" # => true\nis :url?, \"https://github.com/Nicolab/crystal-validator\" # => true\nis :my_validator?, \"value to validate\", \"hello\", 42 # => true\n\n\n# raises an error if the email is not valid\nis! :email?, \"contact@@example..org\" # => Validator::Error\n```\n\n`is` is a macro, no overhead during the runtime 🚀\n By the nature of the macros, you can't pass the *validator* name dynamically with a variable like that `is(validator_name, \"my value to validate\", arg)`.\n But of course you can pass arguments with variables `is(:validator_name?, arg1, arg2)`.\n\n* [Validator - API docs](https://nicolab.github.io/crystal-validator/)\n\n### Validation rules\n\n```crystal\nrequire \"validator/check\"\n\nclass User\n # Mixin\n Check.checkable\n\n property email : String\n property age : Int32\n property bio : String?\n\n Check.rules(\n # required\n email: {\n required: true,\n\n # Checker (all validators are supported)\n check: {\n not_empty: {\"Email is required\"},\n email: {\"It is not a valid email\"},\n },\n\n # Cleaner\n clean: {\n # Data type\n type: String,\n\n # Converter (if union or other) to the expected value type.\n # Example if the input value is i32, but i64 is expected\n # Here is a String\n to: :to_s,\n\n # Formatter (any Crystal Proc)\n format: ->self.format_email(String),\n\n # Error message\n # Default is \"Wrong type\" but it can be customized\n message: \"Oops! Wrong type.\",\n },\n },\n\n # required\n age: {\n required: true,\n check: {\n min: {\"Age should be more than 18\", 18},\n between: {\"Age should be between 25 and 35\", 25, 35},\n },\n clean: {type: Int32, to: :to_i32, message: \"Unable to cast to Int32\"},\n },\n\n # nilable\n bio: {\n check: {\n between: {\"The user bio must be between 2 and 400 characters.\", 2, 400},\n },\n clean: {\n type: String,\n to: :to_s,\n # `nilable` means omited if not provided,\n # regardless of Crystal type (nilable or not)\n nilable: true\n },\n },\n )\n\n def initialize(@email, @age); end\n\n # ---------------------------------------------------------------------------\n # Lifecycle methods (hooks)\n # ---------------------------------------------------------------------------\n\n # Triggered on instance: `user.check`\n def before_check(v : Check::Validation, required : Bool, format : Bool)\n # Code...\n end\n\n # Triggered on instance: `user.check`\n def after_check(v : Check::Validation, required : Bool, format : Bool)\n # Code...\n end\n\n # Triggered on a static call: `User.check(h)` (with a `Hash` or `JSON::Any`)\n def self.before_check(v : Check::Validation, h, required : Bool, format : Bool)\n # Code...\n pp h\n end\n\n # Triggered on a static call: `User.check(h)` (with a `Hash` or `JSON::Any`)\n def self.after_check(v : Check::Validation, h, cleaned_h, required : Bool, format : Bool)\n # Code...\n pp cleaned_h\n cleaned_h # <= returns cleaned_h!\n end\n\n # --------------------------------------------------------------------------\n # Custom checkers\n # --------------------------------------------------------------------------\n\n # Triggered on instance: `user.check`\n @[Check::Checker]\n def custom_checker(v : Check::Validation, required : Bool, format : Bool)\n self.custom_checker_called = true\n end\n\n # Triggered on a static call: `User.check(h)` (with a `Hash` or `JSON::Any`)\n @[Check::Checker]\n def self.custom_checker(v : Check::Validation, h, cleaned_h, required : Bool, format : Bool)\n @@custom_checker_called = true\n cleaned_h # <= returns cleaned_h!\n end\n\n # --------------------------------------------------------------------------\n # Formatters\n # --------------------------------------------------------------------------\n\n # Format (convert) email.\n def self.format_email(email)\n puts \"mail stripped\"\n email.strip\n end\n\n # --------------------------------------------------------------------------\n # Normal methods\n # --------------------------------------------------------------------------\n\n def foo()\n # Code...\n end\n\n def self.bar(v)\n # Code...\n end\n\n # ...\n end\n```\n\n__Check__ with this example class (`User`):\n\n```crystal\n# Check a Hash (statically)\nv, user_h = User.check(input_h)\n\npp v # => Validation instance\npp v.valid?\npp v.errors\n\npp user_h # => Casted and cleaned Hash\n\n# Check a Hash (on instance)\nuser = user.new(\"demo@example.org\", 38)\n\nv = user.check # => Validation instance\npp v.valid?\npp v.errors\n\n# Check field\nv, email = User.check_email(value: \"demo@example.org\")\nv, age = User.check_age(value: 42)\n\nv, email = User.check_email(value: \"demo@example.org \", format: true)\nv, email = User.check_email(value: \"demo@example.org \", format: false)\n\n# Using an existing Validation instance\nv = Check.new_validation\nv, email = User.check_email(v, value: \"demo@example.org\")\n```\n\n__Clean__ with this example class (`User`):\n\n```crystal\n# `check` method cleans all values of the Hash (or JSON::Any),\n# before executing the validation rules\nv, user_h = User.check(input_h)\n\npp v # => Validation instance\npp v.valid?\npp v.errors\n\npp user_h # => Casted and cleaned Hash\n\n# Cast and clean field\nok, email = User.clean_email(value: \"demo@example.org\")\nok, age = User.clean_age(value: 42)\n\nok, email = User.clean_email(value: \"demo@example.org \", format: true)\nok, email = User.clean_email(value: \"demo@example.org \", format: false)\n\nputs \"${email} is casted and cleaned\" if ok\n# or\nputs \"Email type error\" unless ok\n```\n\n* `clean_*` methods are useful to caste a union value (like `Hash` or `JSON::Any`).\n* Also `clean_*` methods are optional and handy for formatting values, such as the strip on the email in the example `User` class.\n\nMore details about cleaning, casting, formatting and return values:\n\nBy default `format` is `true`, to disable:\n\n```crystal\nok, email = User.clean_email(value: \"demo@example.org\", format: false)\n# or\nok, email = User.clean_email(\"demo@example.org\", false)\n```\n\nAlways use named argument if there is only one (the `value`):\n\n```crystal\nok, email = User.clean_email(value: \"demo@example.org\")\n```\n\n`ok` is a boolean value that reports whether the cast succeeded. Like the type assertions in _Go_ (lang).\nBut the `ok` value is returned in first (like in _Elixir_ lang) for easy handling of multiple return values (`Tuple`).\n\nExample with multiple values returned:\n\n```crystal\nok, value1, value2 = User.clean_my_tuple({1, 2, 3})\n```\n\nConsidering the example class above (`User`).\nAs a reminder, the email field has been defined with the formatter below:\n\n```crystal\nCheck.rules(\n email: {\n clean: {\n type: String,\n to: :to_s,\n format: ->self.format_email(String), # <= Here!\n message: \"Wrong type\",\n },\n },\n)\n\n# ...\n\n# Format (convert) email.\ndef self.format_email(email)\n puts \"mail stripped\"\n email.strip\nend\n```\n\nSo `clean_email` cast to `String` and strip the value `\" demo@example.org \"`:\n\n```crystal\n# Email value with one space before and one space after\nok, email = User.clean_email(value: \" demo@example.org \")\n\nputs email # => \"demo@example.org\"\n```\n\nIf the email was taken from a union type (`json[\"email\"]?`), the returned `email` variable would be a `String` too.\n\nSee [more examples](https://github.com/Nicolab/crystal-validator/tree/master/examples).\n\n> NOTE: Require more explanations about `required`, `nilable` rules.\n> Also about the converters JSON / Crystal Hash: `h_from_json`, `to_json_h`, `to_crystal_h`.\n> In the meantime see the [API doc](https://nicolab.github.io/crystal-validator/Check/Checkable.html).\n\n### Validation#check\n\nTo perform a series of validations with error handling, the [validator/check](https://nicolab.github.io/crystal-validator/Check.html) module offers this possibility 👍\n\nA [Validation](https://nicolab.github.io/crystal-validator/Check/Validation.html) instance provides the means to write sequential checks, fine-tune each micro-validation with their own rules and custom error message, the possibility to retrieve all error messages, etc.\n\n> `Validation` is also used with `Check.rules` and `Check.checkable`\n that provide a powerful and productive system of validation rules\n which makes data cleaning and data validation in Crystal very easy.\n With self-generated granular methods for cleaning and checking data.\n\nTo use the checker (`check`) includes in the `Validation` class:\n\n```crystal\nrequire \"validator/check\"\n\n# Validates the *user* data received in the HTTP controller or other.\ndef validate_user(user : Hash) : Check::Validation\n v = Check.new_validation\n\n # -- email\n\n # Hash key can be a String or a Symbol\n v.check :email, \"The email is required.\", is :presence?, :email, user\n\n v.check \"email\", \"The email is required.\", is :presence?, \"email\", user\n v.check \"email\", \"#{user[\"email\"]} is an invalid email.\", is :email?, user[\"email\"]\n\n # -- username\n\n v.check \"username\", \"The username is required.\", is :presence?, \"username\", user\n\n v.check(\n \"username\",\n \"The username must contain at least 2 characters.\",\n is :min?, user[\"username\"], 2\n )\n\n v.check(\n \"username\",\n \"The username must contain a maximum of 20 characters.\",\n is :max?, user[\"username\"], 20\n )\nend\n\nv = validate_user user\n\npp v.valid? # => true (or false)\n\n# Inverse of v.valid?\nif v.errors.empty?\n return \"no error\"\nend\n\n# Print all the errors (if any)\npp v.errors\n\n# It's a Hash of Array\nerrors = v.errors\n\nputs errors.size\nputs errors.first_value\n\nerrors.each do |key, messages|\n puts key # => \"username\"\n puts messages # => [\"The username is required.\", \"etc...\"]\nend\n```\n\n3 methods [#check](https://nicolab.github.io/crystal-validator/Check/Validation.html#instance-method-summary):\n\n```crystal\n# check(key : Symbol | String, valid : Bool)\n# Using default error message\nv.check(\n \"username\",\n is(:min?, user[\"username\"], 2)\n)\n\n# check(key : Symbol | String, message : String, valid : Bool)\n# Using custom error message\nv.check(\n \"username\",\n \"The username must contain at least 2 characters.\",\n is(:min?, user[\"username\"], 2)\n)\n\n# check(key : Symbol | String, valid : Bool, message : String)\n# Using custom error message\nv.check(\n \"username\",\n is(:min?, user[\"username\"], 2),\n \"The username must contain at least 2 characters.\"\n)\n```\n\n`Check` is a simple and lightweight wrapper.\nThe `Check::Validation` is agnostic of the checked data,\nof the context (model, controller, CSV file, HTTP data, socket data, JSON, etc).\n\n> Use case example:\n Before saving to the database or process user data for a particular task,\n the custom error messages can be used for the end user response.\n\nBut a `Validation` instance can be used just to store validation errors:\n\n```crystal\nv = Check.new_validation\nv.add_error(\"foo\", \"foo error!\")\npp v.errors # => {\"foo\" => [\"foo error!\"]}\n```\n\n> See also `Check.rules` and `Check.checkable`.\n\nLet your imagination run wild to add your logic around it.\n\n### Custom validator\n\nJust add your own method to register a custom *validator* or to overload an existing *validator*.\n\n```crystal\nmodule Validator\n # My custom validator\n def self.my_validator?(value, arg : String, another_arg : Int32) : Bool\n # write here the logic of your validator...\n return true\n end\nend\n\n# Call it\nputs Valid.my_validator?(\"value to validate\", \"hello\", 42) # => true\n\n# or with the `is` flavor\nputs is :my_validator?, \"value to validate\", \"hello\", 42 # => true\n```\n\nUsing the custom validator with the validation rules:\n\n```crystal\nrequire \"validator/check\"\n\nclass Article\n # Mixin\n Check.checkable\n\n property title : String\n property content : String\n\n Check.rules(\n content: {\n # Now the custom validator is available\n check: {\n my_validator: {\"My validator error message\"},\n between: {\"The article content must be between 10 and 20 000 characters\", 10, 20_000},\n # ...\n },\n },\n )\nend\n\n# Triggered with all data\nv, article = Article.check(input_data)\n\n# Triggered with one value\nv, content = Article.check_content(input_data[\"content\"]?)\n```\n\n## Conventions\n\n* The word \"validator\" is the method to make a \"validation\" (value validation).\n* A *validator* returns `true` if the value (or/and the condition) is valid, `false` if not.\n* The first argument(s) is (are) the value(s) to be validated.\n* Always add the `Bool` return type to a *validator*.\n* Always add the suffix `?` to the method name of a *validator*.\n* If possible, indicates the type of the *validator* arguments.\n* Spec: Battle tested.\n* [KISS](https://en.wikipedia.org/wiki/KISS_principle) and [Unix Philosophy](https://en.wikipedia.org/wiki/Unix_philosophy).\n\n## Development\n\n```sh\ncrystal spec\ncrystal tool format\n```\n\n> TODO: add `ameba`?\n\n## Contributing\n\n1. Fork it ()\n2. Create your feature branch (`git checkout -b my-new-feature`)\n3. Commit your changes (`git commit -am 'Add some feature'`)\n4. Push to the branch (`git push origin my-new-feature`)\n5. Create a new Pull Request\n\n## LICENSE\n\n[MIT](https://github.com/Nicolab/crystal-validator/blob/master/LICENSE) (c) 2020, Nicolas Talle.\n\n## Author\n\n| [![Nicolas Tallefourtane - Nicolab.net](https://www.gravatar.com/avatar/d7dd0f4769f3aa48a3ecb308f0b457fc?s=64)](https://github.com/sponsors/Nicolab) |\n|---|\n| [Nicolas Talle](https://github.com/sponsors/Nicolab) |\n| [![Make a donation via Paypal](https://www.paypalobjects.com/en_US/i/btn/btn_donate_SM.gif)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=PGRH4ZXP36GUC) |\n\n> Thanks to [ilourt](https://github.com/ilourt) for his great work on `checkable` mixins (clean_*, check_*, ...).\n","program":{"html_id":"validator/toplevel","path":"toplevel.html","kind":"module","full_name":"Top Level Namespace","name":"Top Level Namespace","abstract":false,"superclass":null,"ancestors":[],"locations":[],"repository_name":"validator","program":true,"enum":false,"alias":false,"aliased":"","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":null,"doc":null,"summary":null,"class_methods":[],"constructors":[],"instance_methods":[],"macros":[{"id":"is(name,*args)-macro","html_id":"is(name,*args)-macro","name":"is","doc":"An (optional) expressive flavor of `Validator` (or `Valid` alias).\nNot exposed by default, must be imported:\n\n```\nrequire \"validator/is\"\n\nis :email?, \"contact@example.org\" # => true\nis \"email?\", \"contact@example.org\" # => true\nis :url?, \"https://github.com/Nicolab/crystal-validator\" # => true\n```","summary":"
An (optional) expressive flavor of Validator (or Valid alias).
","abstract":false,"args":[{"name":"name","doc":null,"default_value":"","external_name":"name","restriction":""},{"name":"args","doc":null,"default_value":"","external_name":"args","restriction":""}],"args_string":"(name, *args)","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/is.cr#L18","def":{"name":"is","args":[{"name":"name","doc":null,"default_value":"","external_name":"name","restriction":""},{"name":"args","doc":null,"default_value":"","external_name":"args","restriction":""}],"double_splat":null,"splat_index":1,"block_arg":null,"visibility":"Public","body":" \n# Symbol ? String\n\n Valid.\n{{ name.id }}\n \n{{ args.splat }}\n\n\n"}},{"id":"is!(name,*args)-macro","html_id":"is!(name,*args)-macro","name":"is!","doc":"Same as `is` but `raise` a `Validator::Error`\ndisplaying an inspection if the validation is `false`.\nUseful for the unit tests :)","summary":"
Same as is but raise a Validator::Error displaying an inspection if the validation is false.
","abstract":false,"args":[{"name":"name","doc":null,"default_value":"","external_name":"name","restriction":""},{"name":"args","doc":null,"default_value":"","external_name":"args","restriction":""}],"args_string":"(name, *args)","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/is.cr#L26","def":{"name":"is!","args":[{"name":"name","doc":null,"default_value":"","external_name":"name","restriction":""},{"name":"args","doc":null,"default_value":"","external_name":"args","restriction":""}],"double_splat":null,"splat_index":1,"block_arg":null,"visibility":"Public","body":" \n# Symbol ? String\n\n valid = Valid.\n{{ name.id }}\n \n{{ args.splat }}\n\n\n if valid == false\n raise Validator::Error.new \"Is not \\\"#{\n{{ name }}\n}\\\":\\n#{\n{{ args.stringify }}\n}\"\n \nend\n\n true\n\n"}}],"types":[{"html_id":"validator/Check","path":"Check.html","kind":"module","full_name":"Check","name":"Check","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/check.cr","line_number":11,"url":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/check.cr#L11"},{"filename":"src/checkable.cr","line_number":9,"url":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/checkable.cr#L9"}],"repository_name":"validator","program":false,"enum":false,"alias":false,"aliased":"","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":null,"doc":"Standalone check module that provides a practical workflow for validations.","summary":"
Standalone check module that provides a practical workflow for validations.
","class_methods":[{"id":"new_validation(errors:Errors)-class-method","html_id":"new_validation(errors:Errors)-class-method","name":"new_validation","doc":"Initializes a new `Validation` instance to combine\na series of checks (`Validation#check`).\nusing an existing *errors* `Hash` (`Check::Errors`).\n\n```\nv = Check.new_validation existing_errors\n```\n\nSame as:\n\n```\nv = Check::Validation.new existing_errors\n```\n\nExample to combine two hashes of validation errors:\n\n```\npreview_validation = Check.new_validation\nv = Check.new_validation preview_validation.errors\n```","summary":"
","abstract":false,"args":[{"name":"errors","doc":null,"default_value":"","external_name":"errors","restriction":"Errors"}],"args_string":"(errors : Errors)","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/check.cr#L359","def":{"name":"new_validation","args":[{"name":"errors","doc":null,"default_value":"","external_name":"errors","restriction":"Errors"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"Validation.new(errors)"}},{"id":"new_validation-class-method","html_id":"new_validation-class-method","name":"new_validation","doc":"Initializes a new `Validation` instance to combine\na series of checks (`Validation#check`).\n\n```\nv = Check.new_validation\n```\n\nSame as:\n\n```\nv = Check::Validation.new\n```","summary":"
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/check.cr#L335","def":{"name":"new_validation","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"Validation.new"}}],"constructors":[],"instance_methods":[],"macros":[{"id":"checkable-macro","html_id":"checkable-macro","name":"checkable","doc":"A mixin to make a class checkable.\nThis mixin includes `Checkable` and `CheckableStatic`.\nIt must be used in conjonction with `Check.rules`.\n\n```\nrequire \"validator/check\"\n\nclass Article\n # Mixin\n Check.checkable\n\n property title : String\n property content : String\n\n Check.rules(\n content: {\n check: {\n not_empty: {\"Article content is required\"},\n between: {\"The article content must be between 10 and 20 000 characters\", 10, 20_000},\n # ...\n },\n clean: {\n type: String,\n to: :to_s,\n format: ->(content : String) { content.strip },\n message: \"Wrong type\",\n },\n },\n )\nend\n\n# Triggered on all data\nv, article = Article.check(input_data)\n\n# Triggered on a value\nv, content = Article.check_content(input_data[\"content\"]?)\n```","summary":"
A mixin to make a class checkable.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/checkable.cr#L67","def":{"name":"checkable","args":[],"double_splat":null,"splat_index":null,"block_arg":null,"visibility":"Public","body":" include Check::Checkable\n \nextend Check::CheckableStatic\n \n"}},{"id":"rules(**fields)-macro","html_id":"rules(**fields)-macro","name":"rules","doc":"Generates `check`, `check_{{field}}` and `clean_{{field}}` methods for *fields* (class variables).\n\n```\nrequire \"validator/check\"\n\nclass Article\n # Mixin\n Check.checkable\n\n property title : String\n property content : String\n property url : String?\n\n Check.rules(\n content: {\n required: true,\n check: {\n not_empty: {\"Article content is required\"},\n between: {\"The article content must be between 10 and 20 000 characters\", 10, 20_000},\n # ...\n },\n clean: {\n type: String,\n to: :to_s,\n format: ->(content : String) { content.strip },\n message: \"Wrong type\",\n },\n },\n url: {\n check: {\n url: {\"Article URL is invalid\"},\n },\n clean: {\n # `nilable` means omited if not provided,\n # regardless of Crystal type (nilable or not)\n nilable: true,\n # Crystal type\n type: String,\n # Converter to the expected typed value\n to: :to_s,\n },\n },\n # ...\n)\nend\n\n# Triggered on all data\nv, article = Article.check(input_data)\n\n# Triggered on all fields of an instance\narticle = Article.new(title: \"foo\", content: \"bar\")\nv = article.check\n\n# Triggered on a value\nv, content = Article.check_content(input_data[\"content\"]?)\n\n# Cast and clean a value\nok, content = Article.clean_content(input_data[\"content\"]?)\n```\n\nSee also `Check.checkable`.","summary":"
Generates check, check_{{field}} and clean_{{field}} methods for fields (class variables).
","abstract":false,"args":[],"args_string":"(**fields)","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/checkable.cr#L133","def":{"name":"rules","args":[],"double_splat":{"name":"fields","doc":null,"default_value":"","external_name":"fields","restriction":""},"splat_index":null,"block_arg":null,"visibility":"Public","body":" private def self.validation_rules\n \n{{ fields }}\n\n \nend\n\n private def self.validation_required?(field) : Bool\n fields = self.validation_rules\n return false if fields[field].nil?\n fields[field].fetch(\"required\", false).as(Bool)\n \nend\n\n private def self.validation_nilable?(field) : Bool\n fields = self.validation_rules\n return false if fields[field].nil? || fields[field][\"clean\"].nil?\n fields[field][\"clean\"].fetch(\"nilable\", false).as(Bool)\n \nend\n\n \n{% for field, rules in fields %}\n {% clean = rules[\"clean\"] %}\n {% check = rules[\"check\"] %}\n {% type = clean[\"type\"] %}\n {% nilable = clean[\"nilable\"] %}\n\n # Returns *{{ field }}* with the good type and formatted if *format* is `true`.\n # The return type is a tuple with a bool as a first argument indicating\n # that the clean has been processed successfully or not and the 2nd\n # argument is the *value* cleaned.\n #\n # ```\n # ok, email = Checkable.clean_email(user_input[\"email\"]) # => true, user@example.com\n # ```\n def self.clean_{{ field }}(value, format = true) : Tuple(Bool, {{ type }} | Nil)\n # force real Nil type (hack for JSON::Any and equivalent)\n value = nil if value == nil\n\n {% if to = clean[\"to\"] %}\n # Check if the *value* has the method `{{ to }}` and execute it if\n # exists to cast the value in the good type (except if the value is nil and nilable).\n if value.responds_to? {{ to }} {% if nilable %} && !value.nil?{% end %}\n begin\n value = value.{{ to.id }}\n rescue\n return false, nil\n end\n end\n {% end %}\n\n # Format if the value as the correct (Crystal) type.\n # `| Nil` allows to format in the case of a nilable value (example `String?`)\n # where the `type` option of `clean` rules has been defined on the precise\n # Crystal type (example `String`).\n if value.is_a? {{ type }} | Nil\n {% if format = clean[\"format\"] %}\n # If *format* is true then call it to format *value*.\n if format\n begin\n return true, {{ format }}.call(value)\n rescue\n return false, nil\n end\n else\n return true, value\n end\n {% else %}\n return true, value\n {% end %}\n end\n\n {false, nil}\n end\n\n # Create a new `Check::Validation` and checks *{{ field }}*.\n # For more infos check `.check_{{ field }}(v : Check::Validation, value, format : Bool = true)`\n def self.check_{{ field }}(\n *,\n value,\n required : Bool = true,\n format : Bool = true\n ) : Tuple(Check::Validation, {{ type }} | Nil)\n v = Check.new_validation\n self.check_{{ field }}(v, value, required, format)\n end\n\n # Cleans and check *value*.\n # If *format* is `true` it tells `.clean_{{ field }}` to execute the `format` function\n # for this field if it has been defined with `Check.rules`.\n def self.check_{{ field }}(\n v : Check::Validation,\n value,\n required : Bool = true,\n format : Bool = true\n ) : Tuple(Check::Validation, {{ type }} | Nil)\n # Cleans and formats the *value*\n ok, value = self.clean_{{ field }}(value, format)\n\n # If clean has encountered an error, add error message and stop check here.\n if ok == false\n {% msg = clean[\"message\"] || \"Wrong type\" %}\n v.add_error {{ field.stringify }}, {{ msg }} {% if nilable || (check[\"not_null\"].nil? && check[\"not_empty\"].nil?) %}unless value.nil?{% end %}\n return v, value\n end\n\n # Check against each rule provided.\n # Each rule is executed if *value* is not `nil` except for `not_null` and `not_empty`\n # which is executed even if the *value* is `nil`\n {% for name, args in check %}\n v.check(\n {{ field.stringify }},\n {{ args[0] }},\n {% if args.size <= 1 %}\n Valid.{{ name.id }}? value\n {% else %}\n Valid.{{ name.id }}? value, {{ args[1..-1].splat }}\n {% end %}\n ) {% if (nilable || (check[\"not_null\"].nil? && check[\"not_empty\"].nil?)) || ((name != \"not_null\") && (name != \"not_empty\")) %}unless value.nil?{% end %}\n {% end %}\n\n {v, value}\n end\n {% end %}\n\n \n"}}],"types":[{"html_id":"validator/Check/Checkable","path":"Check/Checkable.html","kind":"module","full_name":"Check::Checkable","name":"Checkable","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/checkable.cr","line_number":411,"url":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/checkable.cr#L411"}],"repository_name":"validator","program":false,"enum":false,"alias":false,"aliased":"","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"validator/Check","kind":"module","full_name":"Check","name":"Check"},"doc":"Mixin that adds `#check` method to be used with variables of an instance of the class including it.\nThe idea is to check the instance variables of the class extending it\nagainst rules defined with `Check.rules` plus executing custom checkers defined with `Checker`.","summary":"
Mixin that adds #check method to be used with variables of an instance of the class including it.
","class_methods":[],"constructors":[],"instance_methods":[{"id":"after_check(v:Check::Validation,required:Bool=true,format:Bool=true)-instance-method","html_id":"after_check(v:Check::Validation,required:Bool=true,format:Bool=true)-instance-method","name":"after_check","doc":"Lifecycle method triggered after each call of `#check`.\n\n```\n# Triggered on instance: `user.check`\ndef after_check(v : Check::Validation, required : Bool = true, format : Bool = true)\n # Code...\nend\n```","summary":"
Lifecycle method triggered after each call of #check.
","abstract":false,"args":[{"name":"v","doc":null,"default_value":"","external_name":"v","restriction":"Check::Validation"},{"name":"required","doc":null,"default_value":"true","external_name":"required","restriction":"Bool"},{"name":"format","doc":null,"default_value":"true","external_name":"format","restriction":"Bool"}],"args_string":"(v : Check::Validation, required : Bool = true, format : Bool = true)","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/checkable.cr#L434","def":{"name":"after_check","args":[{"name":"v","doc":null,"default_value":"","external_name":"v","restriction":"Check::Validation"},{"name":"required","doc":null,"default_value":"true","external_name":"required","restriction":"Bool"},{"name":"format","doc":null,"default_value":"true","external_name":"format","restriction":"Bool"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":""}},{"id":"before_check(v:Check::Validation,required:Bool=true,format:Bool=true)-instance-method","html_id":"before_check(v:Check::Validation,required:Bool=true,format:Bool=true)-instance-method","name":"before_check","doc":"Lifecycle method triggered before each call of `#check`.\n\n```\n# Triggered on instance: `user.check`\ndef before_check(v : Check::Validation, required : Bool = true, format : Bool = true)\n # Code...\nend\n```","summary":"
Lifecycle method triggered before each call of #check.
","abstract":false,"args":[{"name":"v","doc":null,"default_value":"","external_name":"v","restriction":"Check::Validation"},{"name":"required","doc":null,"default_value":"true","external_name":"required","restriction":"Bool"},{"name":"format","doc":null,"default_value":"true","external_name":"format","restriction":"Bool"}],"args_string":"(v : Check::Validation, required : Bool = true, format : Bool = true)","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/checkable.cr#L420","def":{"name":"before_check","args":[{"name":"v","doc":null,"default_value":"","external_name":"v","restriction":"Check::Validation"},{"name":"required","doc":null,"default_value":"true","external_name":"required","restriction":"Bool"},{"name":"format","doc":null,"default_value":"true","external_name":"format","restriction":"Bool"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":""}},{"id":"check(required:Bool=true,format:Bool=true):Validation-instance-method","html_id":"check(required:Bool=true,format:Bool=true):Validation-instance-method","name":"check","doc":"Checks the instance fields and clean them.\n\nIt instantiates a `Check::Validation` (if not provided) and calls all methods\nrelated to rules and then methods defined with annotation `Checker`.\n\nLifecycle methods `#before_check` and `#after_check` that are triggered\nrespectively at the beginning and at the end of the process.\n\n*format* is used to tell cleaners generated by `Check.rules`\nto execute format method if it has been defined.","summary":"
Checks the instance fields and clean them.
","abstract":false,"args":[{"name":"required","doc":null,"default_value":"true","external_name":"required","restriction":"Bool"},{"name":"format","doc":null,"default_value":"true","external_name":"format","restriction":"Bool"}],"args_string":"(required : Bool = true, format : Bool = true) : Validation","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/checkable.cr#L480","def":{"name":"check","args":[{"name":"required","doc":null,"default_value":"true","external_name":"required","restriction":"Bool"},{"name":"format","doc":null,"default_value":"true","external_name":"format","restriction":"Bool"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Validation","visibility":"Public","body":"v = Check.new_validation\ncheck(v, required, format)\n"}},{"id":"check(v:Check::Validation,required:Bool=true,format:Bool=true):Validation-instance-method","html_id":"check(v:Check::Validation,required:Bool=true,format:Bool=true):Validation-instance-method","name":"check","doc":"Checks the instance fields and clean them.\n\nIt instantiates a `Check::Validation` (if not provided) and calls all methods\nrelated to rules and then methods defined with annotation `Checker`.\n\nLifecycle methods `#before_check` and `#after_check` that are triggered\nrespectively at the beginning and at the end of the process.\n\n*format* is used to tell cleaners generated by `Check.rules`\nto execute format method if it has been defined.","summary":"
Checks the instance fields and clean them.
","abstract":false,"args":[{"name":"v","doc":null,"default_value":"","external_name":"v","restriction":"Check::Validation"},{"name":"required","doc":null,"default_value":"true","external_name":"required","restriction":"Bool"},{"name":"format","doc":null,"default_value":"true","external_name":"format","restriction":"Bool"}],"args_string":"(v : Check::Validation, required : Bool = true, format : Bool = true) : Validation","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/checkable.cr#L450","def":{"name":"check","args":[{"name":"v","doc":null,"default_value":"","external_name":"v","restriction":"Check::Validation"},{"name":"required","doc":null,"default_value":"true","external_name":"required","restriction":"Bool"},{"name":"format","doc":null,"default_value":"true","external_name":"format","restriction":"Bool"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Validation","visibility":"Public","body":"{% if true %}\n\n # Call lifecycle method before check\n before_check v, required, format\n\n # Check all fields that have a method `#check_{field}`\n {% for ivar in @type.instance_vars.select do |ivar|\n @type.class.has_method?(\"check_#{ivar}\")\nend %}\n v, value = self.class.check_{{ ivar.name }}(v, {{ ivar.name }}, required, format)\n\n # If the field is not nilable and the value is nil,\n # it means that the clean method has failed\n # (to cast or an exception has been raised (and catched) in the formatter)\n # So ignore the nil value if the field is not nilable\n @{{ ivar.name }} = value.as({{ ivar.type }}) {% if !ivar.type.nilable? %} unless value.nil? {% end %}\n {% end %}\n\n # Check methods with `Check::Checker` annotation\n {% for method in @type.methods.select do |method|\n method.annotation(Checker)\nend %}\n {{ method.name }} v, required, format\n {% end %}\n\n # Call lifecycle method `#after_check`\n after_check v, required, format\n\n v\n {% end %}"}}],"macros":[],"types":[]},{"html_id":"validator/Check/CheckableStatic","path":"Check/CheckableStatic.html","kind":"module","full_name":"Check::CheckableStatic","name":"CheckableStatic","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/checkable.cr","line_number":261,"url":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/checkable.cr#L261"}],"repository_name":"validator","program":false,"enum":false,"alias":false,"aliased":"","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"validator/Check","kind":"module","full_name":"Check","name":"Check"},"doc":"Mixin that adds `.check` method to be used with a `Hash`.\nThe idea is to check a `Hash` against rules defined with `Check.rules`\nplus executing custom checkers defined with `Checker` annotation.","summary":"
Mixin that adds .check method to be used with a Hash.
","class_methods":[],"constructors":[],"instance_methods":[{"id":"after_check(v:Check::Validation,h:Hash,cleaned_h:Hash,required:Bool=true,format:Bool=true):Hash-instance-method","html_id":"after_check(v:Check::Validation,h:Hash,cleaned_h:Hash,required:Bool=true,format:Bool=true):Hash-instance-method","name":"after_check","doc":"Lifecycle method triggered after each call of `.check`.\n\nThis method (in static call) must returns the cleaned `Hash`\nwhich is provided in the third argument.\nYou can update this cleaned hash but you have to return it.\n\n```\n# Triggered on a static call: `User.check(h)` (with a `Hash` or `JSON::Any`)\ndef self.after_check(v : Check::Validation, h, cleaned_h, required : Bool = true, format : Bool = true) : Hash\n # Code...\n pp cleaned_h\n cleaned_h # <= returns cleaned_h!\nend\n```","summary":"
Lifecycle method triggered after each call of .check.
","abstract":false,"args":[{"name":"v","doc":null,"default_value":"","external_name":"v","restriction":"Check::Validation"},{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"Hash"},{"name":"cleaned_h","doc":null,"default_value":"","external_name":"cleaned_h","restriction":"Hash"},{"name":"required","doc":null,"default_value":"true","external_name":"required","restriction":"Bool"},{"name":"format","doc":null,"default_value":"true","external_name":"format","restriction":"Bool"}],"args_string":"(v : Check::Validation, h : Hash, cleaned_h : Hash, required : Bool = true, format : Bool = true) : Hash","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/checkable.cr#L341","def":{"name":"after_check","args":[{"name":"v","doc":null,"default_value":"","external_name":"v","restriction":"Check::Validation"},{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"Hash"},{"name":"cleaned_h","doc":null,"default_value":"","external_name":"cleaned_h","restriction":"Hash"},{"name":"required","doc":null,"default_value":"true","external_name":"required","restriction":"Bool"},{"name":"format","doc":null,"default_value":"true","external_name":"format","restriction":"Bool"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Hash","visibility":"Public","body":"cleaned_h"}},{"id":"before_check(v:Check::Validation,h:Hash,required:Bool=true,format:Bool=true)-instance-method","html_id":"before_check(v:Check::Validation,h:Hash,required:Bool=true,format:Bool=true)-instance-method","name":"before_check","doc":"Lifecycle method triggered before each call of `.check`.\n\n```\n# Triggered on a static call: `User.check(h)` (with a `Hash` or `JSON::Any`)\ndef self.before_check(v : Check::Validation, h, required : Bool = true, format : Bool = true)\n # Code...\n pp h\nend\n```","summary":"
Lifecycle method triggered before each call of .check.
","abstract":false,"args":[{"name":"v","doc":null,"default_value":"","external_name":"v","restriction":"Check::Validation"},{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"Hash"},{"name":"required","doc":null,"default_value":"true","external_name":"required","restriction":"Bool"},{"name":"format","doc":null,"default_value":"true","external_name":"format","restriction":"Bool"}],"args_string":"(v : Check::Validation, h : Hash, required : Bool = true, format : Bool = true)","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/checkable.cr#L320","def":{"name":"before_check","args":[{"name":"v","doc":null,"default_value":"","external_name":"v","restriction":"Check::Validation"},{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"Hash"},{"name":"required","doc":null,"default_value":"true","external_name":"required","restriction":"Bool"},{"name":"format","doc":null,"default_value":"true","external_name":"format","restriction":"Bool"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":""}},{"id":"check(v:Check::Validation,h:Hash,required:Bool=true,format:Bool=true)-instance-method","html_id":"check(v:Check::Validation,h:Hash,required:Bool=true,format:Bool=true)-instance-method","name":"check","doc":"Checks and clean the `Hash` for its fields corresponding\nto class variables that have a `.check_{{field}}` method.\n\nIt instantiates a `Check::Validation` (if not provided) and calls all methods\nrelated to `.rules` and then methods defined with annotation `Checker`.\n\nLifecycle methods `.before_check` and `.after_check` that are called\nrespectively at the beginning and at the end of the process.\n\n*format* is used to tell cleaners generated by `Check.rules`\nto execute format method if it has been defined.","summary":"
Checks and clean the Hash for its fields corresponding to class variables that have a .check_{{field}} method.
","abstract":false,"args":[{"name":"v","doc":null,"default_value":"","external_name":"v","restriction":"Check::Validation"},{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"Hash"},{"name":"required","doc":null,"default_value":"true","external_name":"required","restriction":"Bool"},{"name":"format","doc":null,"default_value":"true","external_name":"format","restriction":"Bool"}],"args_string":"(v : Check::Validation, h : Hash, required : Bool = true, format : Bool = true)","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/checkable.cr#L361","def":{"name":"check","args":[{"name":"v","doc":null,"default_value":"","external_name":"v","restriction":"Check::Validation"},{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"Hash"},{"name":"required","doc":null,"default_value":"true","external_name":"required","restriction":"Bool"},{"name":"format","doc":null,"default_value":"true","external_name":"format","restriction":"Bool"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"{% if true %}\n {% types = [] of Type %}\n {% fields = [] of String %}\n\n {% for ivar in @type.instance_vars.select do |ivar|\n @type.class.has_method?(\"check_#{ivar}\")\nend %}\n {% types << ivar.type %}\n {% fields << ivar.name %}\n {% end %}\n\n # Instantiate a `Hash` with keys as `String` and values as a union of\n # all types of fields which have a method `.check_{field}`\n cleaned_h = Hash(String, {{ (types.join(\"|\")).id }}).new\n\n # Call lifecycle method before check\n self.before_check v, h, required, format\n\n # Call check methods for fields that are present in *h*\n # and populate `cleaned_h`\n {% for field, i in fields %}\n {% field_name = field.stringify %}\n # if hash has the field or this field MUST be checked when required is `true`\n if h.has_key?({{ field_name }}) || (required && self.validation_required?({{ field_name }}))\n v, value = self.check_{{ field }}(v, h[{{ field_name }}]?, required, format)\n cleaned_h[{{ field_name }}] = value.as({{ types[i] }})\n end\n {% end %}\n\n # Check methods with `Check::Checker` annotation\n {% for method in @type.class.methods.select do |method|\n method.annotation(Checker)\nend %}\n cleaned_h = {{ method.name }} v, h, cleaned_h, required, format\n {% end %}\n\n # Call lifecycle method `.after_check`\n cleaned_h = self.after_check v, h, cleaned_h, required, format\n\n {v, cleaned_h}\n {% end %}"}},{"id":"check(h:Hash,required:Bool=true,format:Bool=true)-instance-method","html_id":"check(h:Hash,required:Bool=true,format:Bool=true)-instance-method","name":"check","doc":"Checks and clean the `Hash` for its fields corresponding\nto class variables that have a `.check_{{field}}` method.\n\nIt instantiates a `Check::Validation` (if not provided) and calls all methods\nrelated to `.rules` and then methods defined with annotation `Checker`.\n\nLifecycle methods `.before_check` and `.after_check` that are called\nrespectively at the beginning and at the end of the process.\n\n*format* is used to tell cleaners generated by `Check.rules`\nto execute format method if it has been defined.","summary":"
Checks and clean the Hash for its fields corresponding to class variables that have a .check_{{field}} method.
","abstract":false,"args":[{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"Hash"},{"name":"required","doc":null,"default_value":"true","external_name":"required","restriction":"Bool"},{"name":"format","doc":null,"default_value":"true","external_name":"format","restriction":"Bool"}],"args_string":"(h : Hash, required : Bool = true, format : Bool = true)","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/checkable.cr#L402","def":{"name":"check","args":[{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"Hash"},{"name":"required","doc":null,"default_value":"true","external_name":"required","restriction":"Bool"},{"name":"format","doc":null,"default_value":"true","external_name":"format","restriction":"Bool"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"v = Check.new_validation\ncheck(v, h, required, format)\n"}},{"id":"h_from_json(json:String|IO)-instance-method","html_id":"h_from_json(json:String|IO)-instance-method","name":"h_from_json","doc":"Returns a `Hash` from a JSON input.\nThe return type is a tuple with a bool as a first argument indicating\nthat the `JSON.parse` has been processed successfully or not and the 2nd\nargument is the *json* Hash.\n\n```\nok, user_h = User.h_from_json(json) # => true, {\"username\" => \"Bob\", \"email\" => \"user@example.com\"}\n```","summary":"
Returns a Hash from a JSON input.
","abstract":false,"args":[{"name":"json","doc":null,"default_value":"","external_name":"json","restriction":"String | IO"}],"args_string":"(json : String | IO)","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/checkable.cr#L305","def":{"name":"h_from_json","args":[{"name":"json","doc":null,"default_value":"","external_name":"json","restriction":"String | IO"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"begin\n return {true, self.to_crystal_h((JSON.parse(json)).as_h)}\nrescue\n return {false, nil}\nend"}},{"id":"map_json_keys:Hash(String,String)-instance-method","html_id":"map_json_keys:Hash(String,String)-instance-method","name":"map_json_keys","doc":"Macro that returns the mapping of the JSON fields","summary":"
Macro that returns the mapping of the JSON fields
","abstract":false,"args":[],"args_string":" : Hash(String, String)","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/checkable.cr#L263","def":{"name":"map_json_keys","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Hash(String, String)","visibility":"Public","body":"map = {} of String => String\n{% if true %}\n {% for ivar in @type.instance_vars %}\n {% ann = ivar.annotation(::JSON::Field) %}\n {% if ann && ann[:ignore] %}{% else %}\n map[{{ ((ann && ann[:key]) || ivar).id.stringify }}] = {{ ivar.id.stringify }}\n {% end %}\n {% end %}\n {% end %}\nmap\n"}},{"id":"to_crystal_h(h:Hash):Hash-instance-method","html_id":"to_crystal_h(h:Hash):Hash-instance-method","name":"to_crystal_h","doc":"Returns a new `Hash` with all JSON keys converted to Crystal keys.","summary":"
Returns a new Hash with all JSON keys converted to Crystal keys.
","abstract":false,"args":[{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"Hash"}],"args_string":"(h : Hash) : Hash","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/checkable.cr#L278","def":{"name":"to_crystal_h","args":[{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"Hash"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Hash","visibility":"Public","body":"cr_keys = map_json_keys\nh.transform_keys do |cr_k|\n cr_keys[cr_k]? || cr_k\nend\n"}},{"id":"to_json_h(h:Hash):Hash-instance-method","html_id":"to_json_h(h:Hash):Hash-instance-method","name":"to_json_h","doc":"Returns a new `Hash` with all Crystal keys converted to JSON keys.","summary":"
Returns a new Hash with all Crystal keys converted to JSON keys.
","abstract":false,"args":[{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"Hash"}],"args_string":"(h : Hash) : Hash","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/checkable.cr#L288","def":{"name":"to_json_h","args":[{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"Hash"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Hash","visibility":"Public","body":"cr_keys = map_json_keys\nh.transform_keys do |json_k|\n cr_keys.key_for?(json_k || json_k)\nend\n"}}],"macros":[],"types":[]},{"html_id":"validator/Check/Checker","path":"Check/Checker.html","kind":"annotation","full_name":"Check::Checker","name":"Checker","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/checkable.cr","line_number":28,"url":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/checkable.cr#L28"}],"repository_name":"validator","program":false,"enum":false,"alias":false,"aliased":"","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"validator/Check","kind":"module","full_name":"Check","name":"Check"},"doc":"Declare a method as a checker.\n\n```\n# Triggered by the instance.\n@[Check::Checker]\ndef custom_checker(v : Check::Validation, required : Bool, format : Bool)\n puts \"custom checker triggered on instance\"\nend\n\n# Triggered statically.\n@[Check::Checker]\ndef self.custom_checker(v : Check::Validation, h, cleaned_h, required : Bool, format : Bool)\n puts \"custom checker triggered statically\"\n cleaned_h\nend\n```\n\nWhen `.check` and `#check` are called, the custom checkers are triggered respectively.","summary":"
Declare a method as a checker.
","class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[]},{"html_id":"validator/Check/Errors","path":"Check/Errors.html","kind":"alias","full_name":"Check::Errors","name":"Errors","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/check.cr","line_number":19,"url":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/check.cr#L19"}],"repository_name":"validator","program":false,"enum":false,"alias":true,"aliased":"Hash(String | Symbol, Array(String))","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"validator/Check","kind":"module","full_name":"Check","name":"Check"},"doc":"Validation errors.\nIt's a `Hash` used as a container of errors, in order to handle them easily.\n\n```\nv = Check.new_validation\npp v.errors\n```","summary":"
Validation errors.
","class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[]},{"html_id":"validator/Check/Validation","path":"Check/Validation.html","kind":"class","full_name":"Check::Validation","name":"Validation","abstract":false,"superclass":{"html_id":"validator/Reference","kind":"class","full_name":"Reference","name":"Reference"},"ancestors":[{"html_id":"validator/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"validator/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"src/check.cr","line_number":139,"url":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/check.cr#L139"}],"repository_name":"validator","program":false,"enum":false,"alias":false,"aliased":"","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"validator/Check","kind":"module","full_name":"Check","name":"Check"},"doc":"Combines a series of checks into one validation instance,\nwith a customized error message for each case.\n\nA `Validation` instance provides the means to write sequential checks,\nfine-tune each micro-validation with their own rules and custom error message,\nthe possibility to retrieve all error messages, etc.\n\n> `Validation` is also used with `Check.rules` and `Check.checkable`\nthat provide a powerful and productive system of validation rules\nwhich makes data cleaning and data validation in Crystal very easy.\nWith self-generated granular methods for cleaning and checking data.\n\n\nTo use the checker (`check`) includes in the `Validation` class:\n\n```\nrequire \"validator/check\"\n\n# Validates the *user* data received in the HTTP controller or other.\ndef validate_user(user : Hash) : Check::Validation\n v = Check.new_validation\n\n # -- email\n\n # Hash key can be a String or a Symbol\n v.check :email, \"The email is required.\", is :presence?, :email, user\n\n v.check \"email\", \"The email is required.\", is :presence?, \"email\", user\n v.check \"email\", \"#{user[\"email\"]} is an invalid email.\", is :email?, user[\"email\"]\n\n # -- username\n\n v.check \"username\", \"The username is required.\", is :presence?, \"username\", user\n\n v.check(\n \"username\",\n \"The username must contain at least 2 characters.\",\n is :min?, user[\"username\"], 2\n )\n\n v.check(\n \"username\",\n \"The username must contain a maximum of 20 characters.\",\n is :max?, user[\"username\"], 20\n )\nend\n\nv = validate_user user\n\npp v.valid? # => true (or false)\n\n# Inverse of v.valid?\nif v.errors.empty?\n return \"no error\"\nend\n\n# display all the errors (if any)\npp v.errors\n\n# It's a Hash of Array\nerrors = v.errors\n\nputs errors.size\nputs errors.first_value\n\nerrors.each do |key, messages|\n puts key # => \"username\"\n puts messages # => [\"The username is required.\", \"etc...\"]\nend\n```\n\n3 methods [#check](https://nicolab.github.io/crystal-validator/Check/Validation.html#instance-method-summary):\n\n```\n# check(key : Symbol | String, valid : Bool)\n# Using default standard error message\nv.check(\n \"username\",\n is(:min?, user[\"username\"], 2)\n)\n\n# check(key : Symbol | String, message : String, valid : Bool)\n# Using custom error message\nv.check(\n \"username\",\n \"The username must contain at least 2 characters.\",\n is(:min?, user[\"username\"], 2)\n)\n\n# check(key : Symbol | String, valid : Bool, message : String)\n# Using custom error message\nv.check(\n \"username\",\n is(:min?, user[\"username\"], 2),\n \"The username must contain at least 2 characters.\"\n)\n```\n\n`Check` is a simple and lightweight wrapper.\n`Check::Validation` is agnostic of the checked data,\nof the context (model, controller, CSV file, HTTP data, socket data, JSON, etc).\n\n> Use case example:\n Before saving to the database or process user data for a particular task,\n the custom error messages can be used for the end user response.\n\nBut a `Validation` instance can be used just to store validation errors:\n\n```\nv = Check.new_validation\nv.add_error(\"foo\", \"foo error!\")\npp v.errors # => {\"foo\" => [\"foo error!\"]}\n```\n\n> See also `Check.rules` and `Check.checkable`.\n\nLet your imagination run wild to add your logic around it.\n","summary":"
Combines a series of checks into one validation instance, with a customized error message for each case.
","class_methods":[],"constructors":[{"id":"new(errors:Errors)-class-method","html_id":"new(errors:Errors)-class-method","name":"new","doc":"Initializes a validation using an existing *errors* `Hash` (`Check::Errors`).\n\n```\nv = Check::Validation.new\n```\n\nSame as:\n\n```\nv = Check.new_validation\n```","summary":"
Initializes a validation using an existing errorsHash (Check::Errors).
","abstract":false,"args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"Symbol | String"},{"name":"message","doc":null,"default_value":"","external_name":"message","restriction":"String"}],"args_string":"(key : Symbol | String, message : String) : Validation","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/check.cr#L191","def":{"name":"add_error","args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"Symbol | String"},{"name":"message","doc":null,"default_value":"","external_name":"message","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Validation","visibility":"Public","body":"if message.blank?\n message = \"\\\"#{key}\\\" is not valid.\"\nend\nif @errors.has_key?(key)\nelse\n @errors[key] = Array(String).new\nend\n@errors[key] << message\nself\n"}},{"id":"add_error(key:Symbol|String):Validation-instance-method","html_id":"add_error(key:Symbol|String):Validation-instance-method","name":"add_error","doc":"Add a validation error.\n\n> By default a standard message is used.\n\n```\nv = Check.new_validation\nv.add_error(:foo)\npp v.errors # => {:foo => [\"\\\"foo\\\" is not valid.\"]}\n```\n\nSee also: `Errors`","summary":"
Add a validation error.
","abstract":false,"args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"Symbol | String"}],"args_string":"(key : Symbol | String) : Validation","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/check.cr#L211","def":{"name":"add_error","args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"Symbol | String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Validation","visibility":"Public","body":"add_error(key, \"\")\nself\n"}},{"id":"check(key:Symbol|String,message:String,valid:Bool):Validation-instance-method","html_id":"check(key:Symbol|String,message:String,valid:Bool):Validation-instance-method","name":"check","doc":"Checks a validation, often used in sequence.\n\nIf *valid* is `false`, the error *message* is added in the `errors`.\nNothing if *valid* is `true`.\n\n```\nv = Check.new_validation\n\n# -- email\n\nv.check :email, \"The email is required.\", is :presence?, :email, user\nv.check :email, \"#{user[:email]} is an invalid email.\", is :email?, user[:email]?\n\n# -- username\n\nv.check :username, \"The username is required.\", is :presence?, :username, user\n\nv.check(\n :username,\n \"The username must contain at least 2 characters.\",\n is :min?, user[:username]?, 2\n)\n\nv.check(\n :username,\n \"The username must contain a maximum of 20 characters.\",\n is :max?, user[:username]?, 20\n)\n\n# Print all errors\npp v.errors\n```","summary":"
Checks a validation, often used in sequence.
","abstract":false,"args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"Symbol | String"},{"name":"message","doc":null,"default_value":"","external_name":"message","restriction":"String"},{"name":"valid","doc":null,"default_value":"","external_name":"valid","restriction":"Bool"}],"args_string":"(key : Symbol | String, message : String, valid : Bool) : Validation","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/check.cr#L259","def":{"name":"check","args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"Symbol | String"},{"name":"message","doc":null,"default_value":"","external_name":"message","restriction":"String"},{"name":"valid","doc":null,"default_value":"","external_name":"valid","restriction":"Bool"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Validation","visibility":"Public","body":"if valid\nelse\n add_error(key, message)\nend\nself\n"}},{"id":"check(key:Symbol|String,valid:Bool,message:String):Validation-instance-method","html_id":"check(key:Symbol|String,valid:Bool,message:String):Validation-instance-method","name":"check","doc":"Checks a validation, often used in sequence.\n\nIf *valid* is `false`, the error *message* is added in the `errors`.\nNothing if *valid* is `true`.\n\n```\nv = Check.new_validation\n\n# -- email\n\nv.check(:email, is(:presence?, :email, user), \"The email is required.\")\nv.check(:email, is(:email?, user[:email]?), \"#{user[:email]} is an invalid email.\")\n\n# -- username\n\nv.check(:username, is(:presence?, :username, user), \"The username is required.\")\n\nv.check(\n :username,\n is :min?, user[:username]?, 2,\n \"The username must contain at least 2 characters.\"\n)\n\nv.check(\n :username,\n is :max?, user[:username]?, 20,\n \"The username must contain a maximum of 20 characters.\"\n)\n\n# Print all errors\npp v.errors\n```","summary":"
Checks a validation, often used in sequence.
","abstract":false,"args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"Symbol | String"},{"name":"valid","doc":null,"default_value":"","external_name":"valid","restriction":"Bool"},{"name":"message","doc":null,"default_value":"","external_name":"message","restriction":"String"}],"args_string":"(key : Symbol | String, valid : Bool, message : String) : Validation","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/check.cr#L296","def":{"name":"check","args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"Symbol | String"},{"name":"valid","doc":null,"default_value":"","external_name":"valid","restriction":"Bool"},{"name":"message","doc":null,"default_value":"","external_name":"message","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Validation","visibility":"Public","body":"if valid\nelse\n add_error(key, message)\nend\nself\n"}},{"id":"check(key:Symbol|String,valid:Bool):Validation-instance-method","html_id":"check(key:Symbol|String,valid:Bool):Validation-instance-method","name":"check","doc":"Checks a validation, often used in sequence.\n\nIf *valid* is `false`, an error message is added in the `errors`.\nNothing if *valid* is `true`.\n\n> Unlike other `check` methods, with this one a default standard message is used.\n\n```\nv = Check.new_validation\n\nv.check(\"email\", Valid.presence?(\"email\", user))\nv.check(\"email\", Valid.email?(user[\"email\"]?))\n\n# Print all errors\npp v.errors\n```","summary":"
","abstract":false,"args":[],"args_string":" : Errors","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/check.cr#L178","def":{"name":"errors","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Errors","visibility":"Public","body":"@errors"}},{"id":"valid?-instance-method","html_id":"valid?-instance-method","name":"valid?","doc":"Returns `true` if there is no error, `false` if there is one or more errors.\n\n```\npp v.errors if !v.valid?\n# or with another flavor ;-)\npp v.errors unless v.valid?\n```","summary":"
Returns true if there is no error, false if there is one or more errors.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/check.cr#L223","def":{"name":"valid?","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@errors.empty?"}}],"macros":[],"types":[]}]},{"html_id":"validator/Valid","path":"Valid.html","kind":"alias","full_name":"Valid","name":"Valid","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/validator.cr","line_number":124,"url":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validator.cr#L124"}],"repository_name":"validator","program":false,"enum":false,"alias":true,"aliased":"Validator","const":false,"constants":[{"id":"VERSION","name":"VERSION","value":"{{ (`shards version \\\"/media/data/lab/dev/work/projects/nicolab/crystal/crystal-validator/src\\\"`).chomp.stringify.downcase }}","doc":null,"summary":null}],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":null,"doc":"Alias of `Validator`","summary":"
","class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[]},{"html_id":"validator/Validator","path":"Validator.html","kind":"module","full_name":"Validator","name":"Validator","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/validator.cr","line_number":116,"url":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validator.cr#L116"},{"filename":"src/validators/alpha_num.cr","line_number":8,"url":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/alpha_num.cr#L8"},{"filename":"src/validators/case_sensitive.cr","line_number":8,"url":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/case_sensitive.cr#L8"},{"filename":"src/validators/comparisons.cr","line_number":8,"url":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/comparisons.cr#L8"},{"filename":"src/validators/format.cr","line_number":8,"url":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/format.cr#L8"},{"filename":"src/validators/geo.cr","line_number":8,"url":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/geo.cr#L8"},{"filename":"src/validators/presence.cr","line_number":8,"url":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/presence.cr#L8"},{"filename":"src/validators/uri.cr","line_number":8,"url":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/uri.cr#L8"}],"repository_name":"validator","program":false,"enum":false,"alias":false,"aliased":"","const":false,"constants":[{"id":"VERSION","name":"VERSION","value":"{{ (`shards version \\\"/media/data/lab/dev/work/projects/nicolab/crystal/crystal-validator/src\\\"`).chomp.stringify.downcase }}","doc":null,"summary":null}],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":null,"doc":"∠(・.-)―〉 →◎ `validator` is a [Crystal](https://crystal-lang.org) data validation module.\nVery simple and efficient, all validations return `true` or `false`.\n\nAlso [validator/check](https://nicolab.github.io/crystal-validator/Check.html)\n(not exposed by default) provides error message handling intended for the end user.\n\nThere are 2 main ways to use *validator*:\n\n- As a simple validator to check rules (eg: email, url, min, max, presence, in, ...) which return a boolean.\n- As a more advanced validation system which will check a series of rules\n and returns all validation errors encountered with custom or standard messages.\n\nBy default the **validator** module expose only `Validator` and `Valid` (alias) in the scope:\n\n```\nrequire \"validator\"\n\nValid.email? \"contact@example.org\" # => true\nValid.url? \"https://github.com/Nicolab/crystal-validator\" # => true\nValid.my_validator? \"value to validate\", \"hello\", 42 # => true\n```\n\nAn (optional) expressive validation flavor, `is` available as an alternative. \\\nNot exposed by default, it must be imported:\n\n```\nrequire \"validator/is\"\n\nis :email?, \"contact@example.org\" # => true\nis :url?, \"https://github.com/Nicolab/crystal-validator\" # => true\nis :my_validator?, \"value to validate\", \"hello\", 42 # => true\n\n# raises an error if the email is not valid\nis! :email?, \"contact@@example..org\" # => Validator::Error\n```\n\n`is` is a macro, no overhead during the runtime 🚀\n By the nature of the macros, you can't pass the *validator* name dynamically\n with a variable like that `is(validator_name, \"my value to validate\", arg)`.\n But of course you can pass arguments with variables `is(:validator_name?, arg1, arg2)`.\n\n\n## Check\n\nMake a series of checks, with a customized error message for each case.\n\n```crystal\nrequire \"validator/check\"\n\ncheck = Check.new\n\ncheck(\"email\", \"The email is required.\", is :absence?, \"email\", user)\n```\n## Custom validator\n\nJust add your own method to register a custom *validator* or to overload an existing *validator*.\n\n```crystal\nmodule Validator\n # My custom validator\n def self.my_validator?(value, arg : String, another_arg : Int32) : Bool\n # write here the logic of your validator...\n return true\n end\nend\n\n# Call it\nputs Valid.my_validator?(\"value to validate\", \"hello\", 42) # => true\n\n# or with the `is` flavor\nputs is :my_validator?, \"value to validate\", \"hello\", 42 # => true\n```\n\n`Check` is a simple and lightweight wrapper, let your imagination run wild to add your logic around it.\n\nUsing the custom validator with the validation rules:\n\n```\nrequire \"validator/check\"\n\nclass Article\n # Mixin\n Check.checkable\n\n property title : String\n property content : String\n\n Check.rules(\n content: {\n # Now the custom validator is available\n check: {\n my_validator: {\"My validator error message\"},\n between: {\"The article content must be between 10 and 20 000 characters\", 10, 20_000},\n # ...\n },\n },\n )\nend\n\n# Triggered with all data\nv, article = Article.check(input_data)\n\n# Triggered with one value\nv, content = Article.check_content(input_data[\"content\"]?)\n```","summary":"
∠(・.-)―〉 →◎ validator is a Crystal data validation module.
","class_methods":[{"id":"absence?(key:String|Symbol,list:NamedTuple):Bool-class-method","html_id":"absence?(key:String|Symbol,list:NamedTuple):Bool-class-method","name":"absence?","doc":"Validates the absence of the value.\n- See also `#not_in?`.\n- See also `#empty?`.","summary":"
Validates the absence of the value.
","abstract":false,"args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"String | Symbol"},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"NamedTuple"}],"args_string":"(key : String | Symbol, list : NamedTuple) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/presence.cr#L47","def":{"name":"absence?","args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"String | Symbol"},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"NamedTuple"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"self.empty?(list[key]?)"}},{"id":"absence?(key:String|Symbol|Number,list:Hash):Bool-class-method","html_id":"absence?(key:String|Symbol|Number,list:Hash):Bool-class-method","name":"absence?","doc":"Validates the absence of the value.\n- See also `#not_in?`.\n- See also `#empty?`.","summary":"
Validates the absence of the value.
","abstract":false,"args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"String | Symbol | Number"},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Hash"}],"args_string":"(key : String | Symbol | Number, list : Hash) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/presence.cr#L42","def":{"name":"absence?","args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"String | Symbol | Number"},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Hash"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"self.empty?(list[key]?)"}},{"id":"accepted?(value:String):Bool-class-method","html_id":"accepted?(value:String):Bool-class-method","name":"accepted?","doc":"Validates that the *value* `String` is the representation of an acceptance.\n> One of: \"yes\", \"y\", \"on\", \"o\", \"ok\", \"1\", \"true\"\n- See also `#refused?`.","summary":"
Validates that the valueString is the representation of an acceptance.
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/presence.cr#L180","def":{"name":"accepted?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"self.in?(value.downcase, [\"yes\", \"y\", \"on\", \"o\", \"ok\", \"1\", \"true\"])"}},{"id":"accepted?(value):Bool-class-method","html_id":"accepted?(value):Bool-class-method","name":"accepted?","doc":"Validates that the *value* is the representation of an acceptance.\n> One of: \"yes\", \"y\", \"on\", \"o\", \"ok\", \"1\", \"true\"\n\n*value* must implements *#to_s* method.\n- See also `#refused?`.","summary":"
Validates that the value is the representation of an acceptance.
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"args_string":"(value) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/presence.cr#L189","def":{"name":"accepted?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"self.accepted?(value.to_s)"}},{"id":"ascii_only?(value:String):Bool-class-method","html_id":"ascii_only?(value:String):Bool-class-method","name":"ascii_only?","doc":"Validates that the *value* `String`\nis comprised in its entirety by ASCII characters.","summary":"
Validates that the valueString is comprised in its entirety by ASCII characters.
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/format.cr#L41","def":{"name":"ascii_only?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value.ascii_only?"}},{"id":"ascii_only?(values:Array(String)):Bool-class-method","html_id":"ascii_only?(values:Array(String)):Bool-class-method","name":"ascii_only?","doc":"Validates that all the `String` in the *values* `Array`\nare comprised in their entirety by ASCII characters.","summary":"
Validates that all the String in the valuesArray are comprised in their entirety by ASCII characters.
","abstract":false,"args":[{"name":"values","doc":null,"default_value":"","external_name":"values","restriction":"Array(String)"}],"args_string":"(values : Array(String)) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/format.cr#L47","def":{"name":"ascii_only?","args":[{"name":"values","doc":null,"default_value":"","external_name":"values","restriction":"Array(String)"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"size = value.size\nwhile size\n size = size - 1\n if value.ascii_only?(values[i])\n else\n return false\n end\nend\ntrue\n"}},{"id":"base64?(value:String):Bool-class-method","html_id":"base64?(value:String):Bool-class-method","name":"base64?","doc":"Validates that the *value* has the format *base64*.","summary":"
Validates that the value has the format base64.
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/format.cr#L87","def":{"name":"base64?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"if (value.match(@@rx_base64)) && ((value.size % 4) === 0)\n return true\nend\nfalse\n"}},{"id":"between?(value,min,max):Bool-class-method","html_id":"between?(value,min,max):Bool-class-method","name":"between?","doc":"Validates that the *value* is between (inclusive) *min* and *max*.","summary":"
Validates that the value is between (inclusive) min and max.
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"min","doc":null,"default_value":"","external_name":"min","restriction":""},{"name":"max","doc":null,"default_value":"","external_name":"max","restriction":""}],"args_string":"(value, min, max) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/comparisons.cr#L87","def":{"name":"between?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"min","doc":null,"default_value":"","external_name":"min","restriction":""},{"name":"max","doc":null,"default_value":"","external_name":"max","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value >= min && value <= max"}},{"id":"between?(value:String|Array,min:Int,max:Int):Bool-class-method","html_id":"between?(value:String|Array,min:Int,max:Int):Bool-class-method","name":"between?","doc":"Validates that the size of the *value* (`String` or `Array`) is between\n(inclusive) *min* and *max*.\n- See also `#size?`.","summary":"
Validates that the size of the value (String or Array) is between (inclusive) min and max.
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String | Array"},{"name":"min","doc":null,"default_value":"","external_name":"min","restriction":"Int"},{"name":"max","doc":null,"default_value":"","external_name":"max","restriction":"Int"}],"args_string":"(value : String | Array, min : Int, max : Int) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/comparisons.cr#L94","def":{"name":"between?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String | Array"},{"name":"min","doc":null,"default_value":"","external_name":"min","restriction":"Int"},{"name":"max","doc":null,"default_value":"","external_name":"max","restriction":"Int"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"size = value.size\nsize >= min && size <= max\n"}},{"id":"domain?(value:String):Bool-class-method","html_id":"domain?(value:String):Bool-class-method","name":"domain?","doc":null,"summary":null,"abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/uri.cr#L23","def":{"name":"domain?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"size = value.size\nif size > 75 || size < 4\n return false\nend\nif value.includes?(\"..\")\n return false\nend\nif m = value.match(@@rx_domain)\nelse\n return false\nend\next_size = m[\"ext\"].size\nif ext_size < 2 || ext_size > 12\n return false\nend\ntrue\n"}},{"id":"email?(value:String):Bool-class-method","html_id":"email?(value:String):Bool-class-method","name":"email?","doc":"Validates that the *value* is an email.\nThis method is stricter than the standard allows.\nIt is subjectively based on the common addresses\nof organisations (@enterprise.ltd, ...)\nand mail services suck as Gmail, Hotmail, Yahoo !, ...","summary":"
Validates that the value is an email.
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/uri.cr#L158","def":{"name":"email?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"size = value.size\nif size > 60 || size < 7\n return false\nend\nif value.includes?(\"..\")\n return false\nend\nif value.includes?(\"--\")\n return false\nend\nif value.includes?(\"___\")\n return false\nend\nif m = value.match(@@rx_email)\nelse\n return false\nend\nself.domain?(\"#{m[\"name\"]}.#{m[\"ext\"]}\")\n"}},{"id":"empty?(value):Bool-class-method","html_id":"empty?(value):Bool-class-method","name":"empty?","doc":"Validates that the *value* is empty.\n- See also `#absence?`.\n- See also `#not_in?`.","summary":"
Validates that the value is empty.
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"args_string":"(value) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/presence.cr#L58","def":{"name":"empty?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"case value\nwhen .nil?\n true\nwhen .is_a?(String)\n value.presence.nil?\nwhen .is_a?(Number)\n value == 0\nwhen .responds_to?(:size)\n value.size == 0\nelse\n false\nend"}},{"id":"ends?(value:String,search:String):Bool-class-method","html_id":"ends?(value:String,search:String):Bool-class-method","name":"ends?","doc":"Validates that the `String` *value* ends with *search*.\n- See also `#starts?`.\n- See also `#match?`.\n- See also `#in?`.","summary":"
Validates that the Stringvalue ends with search.
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"search","doc":null,"default_value":"","external_name":"search","restriction":"String"}],"args_string":"(value : String, search : String) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/presence.cr#L243","def":{"name":"ends?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"search","doc":null,"default_value":"","external_name":"search","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value.ends_with?(search)"}},{"id":"ends?(value:String,search:Char):Bool-class-method","html_id":"ends?(value:String,search:Char):Bool-class-method","name":"ends?","doc":"Validates that the `String` *value* ends with *search*.\n- See also `#starts?`.\n- See also `#match?`.\n- See also `#in?`.","summary":"
Validates that the Stringvalue ends with search.
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"search","doc":null,"default_value":"","external_name":"search","restriction":"Char"}],"args_string":"(value : String, search : Char) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/presence.cr#L248","def":{"name":"ends?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"search","doc":null,"default_value":"","external_name":"search","restriction":"Char"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value.ends_with?(search)"}},{"id":"ends?(value:String,search:Regex):Bool-class-method","html_id":"ends?(value:String,search:Regex):Bool-class-method","name":"ends?","doc":"Validates that the `String` *value* ends with *search*.\n- See also `#starts?`.\n- See also `#match?`.\n- See also `#in?`.","summary":"
Validates that the Stringvalue ends with search.
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"search","doc":null,"default_value":"","external_name":"search","restriction":"Regex"}],"args_string":"(value : String, search : Regex) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/presence.cr#L253","def":{"name":"ends?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"search","doc":null,"default_value":"","external_name":"search","restriction":"Regex"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value.ends_with?(search)"}},{"id":"eq?(value,another_value):Bool-class-method","html_id":"eq?(value,another_value):Bool-class-method","name":"eq?","doc":"Validates that the *value* is equal to *another_value*.","summary":"
Validates that the value is equal to another_value.
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"another_value","doc":null,"default_value":"","external_name":"another_value","restriction":""}],"args_string":"(value, another_value) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/comparisons.cr#L10","def":{"name":"eq?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"another_value","doc":null,"default_value":"","external_name":"another_value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value == another_value"}},{"id":"gt?(value,another_value):Bool-class-method","html_id":"gt?(value,another_value):Bool-class-method","name":"gt?","doc":"Validates that the *value* is greater than *another_value*.","summary":"
Validates that the value is greater than another_value.
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"another_value","doc":null,"default_value":"","external_name":"another_value","restriction":""}],"args_string":"(value, another_value) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/comparisons.cr#L15","def":{"name":"gt?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"another_value","doc":null,"default_value":"","external_name":"another_value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value > another_value"}},{"id":"gt?(value:String|Array,limit:Int):Bool-class-method","html_id":"gt?(value:String|Array,limit:Int):Bool-class-method","name":"gt?","doc":"Validates that the size of the *value* (`String` or `Array`)\nis greater than *limit* number.","summary":"
Validates that the size of the value (String or Array) is greater than limit number.
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String | Array"},{"name":"limit","doc":null,"default_value":"","external_name":"limit","restriction":"Int"}],"args_string":"(value : String | Array, limit : Int) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/comparisons.cr#L21","def":{"name":"gt?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String | Array"},{"name":"limit","doc":null,"default_value":"","external_name":"limit","restriction":"Int"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value.size > limit"}},{"id":"gte?(value,another_value):Bool-class-method","html_id":"gte?(value,another_value):Bool-class-method","name":"gte?","doc":"Validates that the *value* is equal to or greater than *another_value*.\n> Similar to `#min`.","summary":"
Validates that the value is equal to or greater than another_value.
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"another_value","doc":null,"default_value":"","external_name":"another_value","restriction":""}],"args_string":"(value, another_value) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/comparisons.cr#L27","def":{"name":"gte?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"another_value","doc":null,"default_value":"","external_name":"another_value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value >= another_value"}},{"id":"gte?(value:String|Array,min:Int):Bool-class-method","html_id":"gte?(value:String|Array,min:Int):Bool-class-method","name":"gte?","doc":"Validates that the size of the *value* (`String` or `Array`)\nis greater than *min* number.\n> Similar to `#min`.","summary":"
Validates that the size of the value (String or Array) is greater than min number.
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String | Array"},{"name":"min","doc":null,"default_value":"","external_name":"min","restriction":"Int"}],"args_string":"(value : String | Array, min : Int) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/comparisons.cr#L34","def":{"name":"gte?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String | Array"},{"name":"min","doc":null,"default_value":"","external_name":"min","restriction":"Int"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value.size >= min"}},{"id":"hex?(value:String):Bool-class-method","html_id":"hex?(value:String):Bool-class-method","name":"hex?","doc":"Validates that the `String` *value* does denote\na representation of a hexadecimal string.","summary":"
Validates that the Stringvalue does denote a representation of a hexadecimal string.
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/format.cr#L112","def":{"name":"hex?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!value.match(@@rx_hex).nil?"}},{"id":"hex?(value:Bytes):Bool-class-method","html_id":"hex?(value:Bytes):Bool-class-method","name":"hex?","doc":"Validates that the `Bytes` *value* does denote\na representation of a hexadecimal slice of Bytes.","summary":"
Validates that the Bytesvalue does denote a representation of a hexadecimal slice of Bytes.
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"Bytes"}],"args_string":"(value : Bytes) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/format.cr#L118","def":{"name":"hex?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"Bytes"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!(String.new(value)).match(@@rx_hex).nil?"}},{"id":"hex_color?(value:String):Bool-class-method","html_id":"hex_color?(value:String):Bool-class-method","name":"hex_color?","doc":"Validates that the `String` *value* does denote\na representation of a hexadecimal color.\n\n```\nValid.hex_color? \"#fff\" => true\nValid.hex_color? \"#ffffff\" => true\n```","summary":"
Validates that the Stringvalue does denote a representation of a hexadecimal color.
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/format.cr#L129","def":{"name":"hex_color?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!value.match(@@rx_hex_color).nil?"}},{"id":"in?(value,list:Array):Bool-class-method","html_id":"in?(value,list:Array):Bool-class-method","name":"in?","doc":"Validates that the (*list*) contains the *value*.\n- See also `#presence?`.\n- See also `#not_in?`.\n- See also `#not_empty?`.","summary":"
Validates that the (list) contains the value.
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Array"}],"args_string":"(value, list : Array) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/presence.cr#L109","def":{"name":"in?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Array"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"list.includes?(value)"}},{"id":"in?(value:String,str:String):Bool-class-method","html_id":"in?(value:String,str:String):Bool-class-method","name":"in?","doc":"Validates that the (*str*) `String` contains the *value*.\n- See also `#presence?`.\n- See also `#not_in?`.\n- See also `#not_empty?`.","summary":"
Validates that the (str) String contains the value.
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"str","doc":null,"default_value":"","external_name":"str","restriction":"String"}],"args_string":"(value : String, str : String) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/presence.cr#L101","def":{"name":"in?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"str","doc":null,"default_value":"","external_name":"str","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"str.includes?(value)"}},{"id":"in?(key:Symbol|String,list:Hash):Bool-class-method","html_id":"in?(key:Symbol|String,list:Hash):Bool-class-method","name":"in?","doc":"Validates that the (*list*) contains the *value*.\n- See also `#presence?`.\n- See also `#not_in?`.\n- See also `#not_empty?`.","summary":"
Validates that the (list) contains the value.
","abstract":false,"args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"Symbol | String"},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Hash"}],"args_string":"(key : Symbol | String, list : Hash) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/presence.cr#L129","def":{"name":"in?","args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"Symbol | String"},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Hash"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"list.has_key?(key)"}},{"id":"in?(key:Symbol|String,list:NamedTuple):Bool-class-method","html_id":"in?(key:Symbol|String,list:NamedTuple):Bool-class-method","name":"in?","doc":"Validates that the (*list*) contains the *value*.\n- See also `#presence?`.\n- See also `#not_in?`.\n- See also `#not_empty?`.","summary":"
Validates that the (list) contains the value.
","abstract":false,"args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"Symbol | String"},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"NamedTuple"}],"args_string":"(key : Symbol | String, list : NamedTuple) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/presence.cr#L124","def":{"name":"in?","args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"Symbol | String"},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"NamedTuple"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"list.has_key?(key)"}},{"id":"in?(value,list:Range):Bool-class-method","html_id":"in?(value,list:Range):Bool-class-method","name":"in?","doc":"Validates that the (*list*) contains the *value*.\n- See also `#presence?`.\n- See also `#not_in?`.\n- See also `#not_empty?`.","summary":"
Validates that the (list) contains the value.
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Range"}],"args_string":"(value, list : Range) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/presence.cr#L119","def":{"name":"in?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Range"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"list.includes?(value)"}},{"id":"in?(value,list:Tuple):Bool-class-method","html_id":"in?(value,list:Tuple):Bool-class-method","name":"in?","doc":"Validates that the (*list*) contains the *value*.\n- See also `#presence?`.\n- See also `#not_in?`.\n- See also `#not_empty?`.","summary":"
Validates that the (list) contains the value.
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Tuple"}],"args_string":"(value, list : Tuple) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/presence.cr#L114","def":{"name":"in?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Tuple"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"list.includes?(value)"}},{"id":"ip?(value:String):Bool-class-method","html_id":"ip?(value:String):Bool-class-method","name":"ip?","doc":"Validates that the *value* is an IP (IPv4 or IPv6).","summary":"
Validates that the value is an IP (IPv4 or IPv6).
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/uri.cr#L77","def":{"name":"ip?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"(self.ipv4?(value)) || (self.ipv6?(value))"}},{"id":"ipv4?(value:String):Bool-class-method","html_id":"ipv4?(value:String):Bool-class-method","name":"ipv4?","doc":"Validates that the *value* is an IPv4.","summary":"
Validates that the value is an IPv4.
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/uri.cr#L82","def":{"name":"ipv4?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!value.match(@@rx_ipv4).nil?"}},{"id":"ipv6?(value:String):Bool-class-method","html_id":"ipv6?(value:String):Bool-class-method","name":"ipv6?","doc":"Validates that the *value* is an IPv6.","summary":"
Validates that the value is an IPv6.
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/uri.cr#L87","def":{"name":"ipv6?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"addr_and_zone = [value]\nif value.includes?('%')\n addr_and_zone = value.split('%')\n if addr_and_zone.size == 2\n else\n return false\n end\n if addr_and_zone[0].includes?(':')\n else\n return false\n end\n if addr_and_zone[1] == \"\"\n return false\n end\nend\nblocks = addr_and_zone[0].split(':')\nfound_omission_block = false\nfound_ipv4_transition_block = self.ipv4?(blocks[blocks.size - 1])\nexpected_number_of_blocks = found_ipv4_transition_block ? 7 : 8\nif blocks.size > expected_number_of_blocks\n return false\nend\nif value == \"::\"\n return true\nend\nif value[0...2] == \"::\"\n blocks.shift(2)\n found_omission_block = true\nelse\n if value[(value.size - 2)..] == \"::\"\n blocks.pop(2)\n found_omission_block = true\n end\nend\ni = 0\nwhile i < blocks.size\n if ((blocks[i] === \"\") && i > 0) && i < (blocks.size - 1)\n if found_omission_block\n return false\n end\n found_omission_block = true\n else\n if (!(found_ipv4_transition_block && (i == (blocks.size - 1)))) && blocks[i].match(@@rx_ipv6_block).nil?\n return false\n end\n end\n i = i + 1\nend\nif found_omission_block\n return blocks.size >= 1\nend\nblocks.size == expected_number_of_blocks\n"}},{"id":"json?(value:String,strict:Bool=true):Bool-class-method","html_id":"json?(value:String,strict:Bool=true):Bool-class-method","name":"json?","doc":"Validates that the *value* represents a JSON string.\n*strict* to `true` (default) to try to parse the JSON,\nreturns `false` if the parsing fails.\nIf *strict* is `false`, only the first char and the last char are checked.","summary":"
Validates that the value represents a JSON string.
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"strict","doc":null,"default_value":"true","external_name":"strict","restriction":"Bool"}],"args_string":"(value : String, strict : Bool = true) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/format.cr#L64","def":{"name":"json?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"strict","doc":null,"default_value":"true","external_name":"strict","restriction":"Bool"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"if strict\n begin\n JSON.parse(value)\n rescue err\n return false\n else\n return true\n end\nend\n((self.starts?(value, \"{\")) && (self.ends?(value, \"}\"))) || ((self.starts?(value, \"[\")) && (self.ends?(value, \"]\")))\n"}},{"id":"jwt?(value:String):Bool-class-method","html_id":"jwt?(value:String):Bool-class-method","name":"jwt?","doc":"Validates that the *value* is a *JSON Web Token*.","summary":"
Validates that the value is a JSON Web Token.
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/format.cr#L95","def":{"name":"jwt?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!value.match(@@rx_jwt).nil?"}},{"id":"lat?(value:String|Float):Bool-class-method","html_id":"lat?(value:String|Float):Bool-class-method","name":"lat?","doc":"Validates that the *value* is a valid format representation of a geographical latitude.\n- See also `#lng?`.\n- See also `#lat_lng?`.","summary":"
Validates that the value is a valid format representation of a geographical latitude.
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String | Float"}],"args_string":"(value : String | Float) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/geo.cr#L31","def":{"name":"lat?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String | Float"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!value.to_s.match(@@rx_geo_lat).nil?"}},{"id":"lat_lng?(value:String):Bool-class-method","html_id":"lat_lng?(value:String):Bool-class-method","name":"lat_lng?","doc":"Validates that the *value* is a valid format representation of\na geographical position (given in latitude and longitude).\n- See also `#lat?`.\n- See also `#lng?`.","summary":"
Validates that the value is a valid format representation of a geographical position (given in latitude and longitude).
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/geo.cr#L16","def":{"name":"lat_lng?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"if !(value.includes?(\",\"))\n return false\nend\nlat, lng = value.split(\",\")\nif lat && lng\nelse\n return false\nend\nif ((lat.starts_with?('(')) && (!(lng.ends_with?(')'))))\n return false\nend\nif ((lng.ends_with?(')')) && (!(lat.starts_with?('('))))\n return false\nend\nif (lat.match(@@rx_geo_lat)) && (lng.match(@@rx_geo_lng))\n return true\nend\nfalse\n"}},{"id":"lng?(value:String|Float):Bool-class-method","html_id":"lng?(value:String|Float):Bool-class-method","name":"lng?","doc":"Validates that the *value* is a valid format representation of a geographical longitude.\n- See also `#lat?`.\n- See also `#lat_lng?`.","summary":"
Validates that the value is a valid format representation of a geographical longitude.
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String | Float"}],"args_string":"(value : String | Float) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/geo.cr#L38","def":{"name":"lng?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String | Float"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!value.to_s.match(@@rx_geo_lng).nil?"}},{"id":"lower?(value:String):Bool-class-method","html_id":"lower?(value:String):Bool-class-method","name":"lower?","doc":"Validates that the *value* is in lower case.","summary":"
Validates that the value is in lower case.
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/case_sensitive.cr#L10","def":{"name":"lower?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"(!value.blank?) && (value.downcase === value)"}},{"id":"lt?(value:String|Array,limit:Int):Bool-class-method","html_id":"lt?(value:String|Array,limit:Int):Bool-class-method","name":"lt?","doc":"Validates that the size of the *value* (`String` or `Array`)\nis lesser than *limit* number.","summary":"
Validates that the size of the value (String or Array) is lesser than limit number.
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String | Array"},{"name":"limit","doc":null,"default_value":"","external_name":"limit","restriction":"Int"}],"args_string":"(value : String | Array, limit : Int) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/comparisons.cr#L45","def":{"name":"lt?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String | Array"},{"name":"limit","doc":null,"default_value":"","external_name":"limit","restriction":"Int"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value.size < limit"}},{"id":"lt?(value,another_value):Bool-class-method","html_id":"lt?(value,another_value):Bool-class-method","name":"lt?","doc":"Validates that the *value* is lesser than *another_value*.","summary":"
Validates that the value is lesser than another_value.
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"another_value","doc":null,"default_value":"","external_name":"another_value","restriction":""}],"args_string":"(value, another_value) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/comparisons.cr#L39","def":{"name":"lt?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"another_value","doc":null,"default_value":"","external_name":"another_value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value < another_value"}},{"id":"lte?(value:String|Array,max:Int):Bool-class-method","html_id":"lte?(value:String|Array,max:Int):Bool-class-method","name":"lte?","doc":"Validates that the size of the *value* (`String` or `Array`)\nis equal or lesser than *max* number.\n> Similar to `#max`.","summary":"
Validates that the size of the value (String or Array) is equal or lesser than max number.
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String | Array"},{"name":"max","doc":null,"default_value":"","external_name":"max","restriction":"Int"}],"args_string":"(value : String | Array, max : Int) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/comparisons.cr#L58","def":{"name":"lte?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String | Array"},{"name":"max","doc":null,"default_value":"","external_name":"max","restriction":"Int"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value.size <= max"}},{"id":"lte?(value,another_value):Bool-class-method","html_id":"lte?(value,another_value):Bool-class-method","name":"lte?","doc":"Validates that the *value* is equal to or lesser than *another_value*.\n> Similar to `#max`.","summary":"
Validates that the value is equal to or lesser than another_value.
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"another_value","doc":null,"default_value":"","external_name":"another_value","restriction":""}],"args_string":"(value, another_value) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/comparisons.cr#L51","def":{"name":"lte?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"another_value","doc":null,"default_value":"","external_name":"another_value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value <= another_value"}},{"id":"mac_addr?(value:String,no_colons:Bool=false):Bool-class-method","html_id":"mac_addr?(value:String,no_colons:Bool=false):Bool-class-method","name":"mac_addr?","doc":"Validates that the *value* is a MAC address.","summary":"
Validates that the value is a MAC address.
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"no_colons","doc":null,"default_value":"false","external_name":"no_colons","restriction":"Bool"}],"args_string":"(value : String, no_colons : Bool = false) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/uri.cr#L176","def":{"name":"mac_addr?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"no_colons","doc":null,"default_value":"false","external_name":"no_colons","restriction":"Bool"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"if no_colons\n return !value.match(@@rx_mac_addr_no_colons).nil?\nend\n(((!value.match(@@rx_mac_addr).nil?) || (!value.match(@@rx_mac_addr_with_hyphen).nil?)) || (!value.match(@@rx_mac_addr_with_spaces).nil?)) || (!value.match(@@rx_mac_addr_with_dots).nil?)\n"}},{"id":"magnet_uri?(value:String):Bool-class-method","html_id":"magnet_uri?(value:String):Bool-class-method","name":"magnet_uri?","doc":"Validates that the *value* is a Magnet URI.","summary":"
Validates that the value is a Magnet URI.
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/uri.cr#L186","def":{"name":"magnet_uri?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!value.match(@@rx_magnet_uri).nil?"}},{"id":"match?(value:Number,pattern:Regex):Bool-class-method","html_id":"match?(value:Number,pattern:Regex):Bool-class-method","name":"match?","doc":"Validates that the *value* matches the *pattern*.","summary":"
Validates that the value matches the pattern.
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"Number"},{"name":"pattern","doc":null,"default_value":"","external_name":"pattern","restriction":"Regex"}],"args_string":"(value : Number, pattern : Regex) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/presence.cr#L15","def":{"name":"match?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"Number"},{"name":"pattern","doc":null,"default_value":"","external_name":"pattern","restriction":"Regex"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!value.to_s.match(pattern).nil?"}},{"id":"match?(value:String,pattern:Regex):Bool-class-method","html_id":"match?(value:String,pattern:Regex):Bool-class-method","name":"match?","doc":"Validates that the *value* matches the *pattern*.","summary":"
Validates that the value matches the pattern.
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"pattern","doc":null,"default_value":"","external_name":"pattern","restriction":"Regex"}],"args_string":"(value : String, pattern : Regex) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/presence.cr#L10","def":{"name":"match?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"pattern","doc":null,"default_value":"","external_name":"pattern","restriction":"Regex"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!value.match(pattern).nil?"}},{"id":"max?(value,max):Bool-class-method","html_id":"max?(value,max):Bool-class-method","name":"max?","doc":"Validates that the *value* is equal to or lesser than *max* (inclusive).\n> Similar to `#lte`.","summary":"
Validates that the value is equal to or lesser than max (inclusive).
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"max","doc":null,"default_value":"","external_name":"max","restriction":""}],"args_string":"(value, max) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/comparisons.cr#L76","def":{"name":"max?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"max","doc":null,"default_value":"","external_name":"max","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value <= max"}},{"id":"max?(value:String|Array,max:Int):Bool-class-method","html_id":"max?(value:String|Array,max:Int):Bool-class-method","name":"max?","doc":":ditto:\n> Based on the size of the `String`.","summary":"
:ditto: > Based on the size of the String.
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String | Array"},{"name":"max","doc":null,"default_value":"","external_name":"max","restriction":"Int"}],"args_string":"(value : String | Array, max : Int) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/comparisons.cr#L82","def":{"name":"max?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String | Array"},{"name":"max","doc":null,"default_value":"","external_name":"max","restriction":"Int"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value.size <= max"}},{"id":"md5?(value:String):Bool-class-method","html_id":"md5?(value:String):Bool-class-method","name":"md5?","doc":"Validates that the *value* has the format *md5*.","summary":"
Validates that the value has the format md5.
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/format.cr#L82","def":{"name":"md5?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!value.match(@@rx_md5).nil?"}},{"id":"min?(value,min):Bool-class-method","html_id":"min?(value,min):Bool-class-method","name":"min?","doc":"Validates that the *value* is equal to or greater than *min* (inclusive).\n> Similar to `#gte`.","summary":"
Validates that the value is equal to or greater than min (inclusive).
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"min","doc":null,"default_value":"","external_name":"min","restriction":""}],"args_string":"(value, min) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/comparisons.cr#L64","def":{"name":"min?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"min","doc":null,"default_value":"","external_name":"min","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value >= min"}},{"id":"min?(value:String|Array,min:Int):Bool-class-method","html_id":"min?(value:String|Array,min:Int):Bool-class-method","name":"min?","doc":":ditto:\n> Based on the size of the `String`.","summary":"
:ditto: > Based on the size of the String.
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String | Array"},{"name":"min","doc":null,"default_value":"","external_name":"min","restriction":"Int"}],"args_string":"(value : String | Array, min : Int) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/comparisons.cr#L70","def":{"name":"min?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String | Array"},{"name":"min","doc":null,"default_value":"","external_name":"min","restriction":"Int"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value.size >= min"}},{"id":"mongo_id?(value:Bytes):Bool-class-method","html_id":"mongo_id?(value:Bytes):Bool-class-method","name":"mongo_id?","doc":"Validates that the `Bytes` *value* does denote\na representation of a *MongoID* slice of Bytes.","summary":"
Validates that the Bytesvalue does denote a representation of a MongoID slice of Bytes.
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"Bytes"}],"args_string":"(value : Bytes) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/format.cr#L143","def":{"name":"mongo_id?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"Bytes"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"(self.hex?(value)) && (value.size == 24)"}},{"id":"mongo_id?(value:String):Bool-class-method","html_id":"mongo_id?(value:String):Bool-class-method","name":"mongo_id?","doc":"Validates that the `String` *value* does denote\na representation of a *MongoID* string.","summary":"
Validates that the Stringvalue does denote a representation of a MongoID string.
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/format.cr#L137","def":{"name":"mongo_id?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"(self.hex?(value)) && (value.size == 24)"}},{"id":"not_empty?(value):Bool-class-method","html_id":"not_empty?(value):Bool-class-method","name":"not_empty?","doc":"Validates that the *value* is not empty.\n- See also `#presence?`.\n- See also `#in?`.","summary":"
Validates that the value is not empty.
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"args_string":"(value) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/presence.cr#L71","def":{"name":"not_empty?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"(self.empty?(value)) == false"}},{"id":"not_in?(value:String,str:String):Bool-class-method","html_id":"not_in?(value:String,str:String):Bool-class-method","name":"not_in?","doc":"Validates that the (*str*) `String` does not contain the *value*.\n- See also `#absence?`.\n- See also `#in?`.\n- See also `#empty?`.","summary":"
Validates that the (str) String does not contain the value.
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"str","doc":null,"default_value":"","external_name":"str","restriction":"String"}],"args_string":"(value : String, str : String) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/presence.cr#L141","def":{"name":"not_in?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"str","doc":null,"default_value":"","external_name":"str","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!(str.includes?(value))"}},{"id":"not_in?(value,list:Array):Bool-class-method","html_id":"not_in?(value,list:Array):Bool-class-method","name":"not_in?","doc":"Validates that the (*list*) does not contain the *value*.\n- See also `#absence?`.\n- See also `#in?`.\n- See also `#empty?`.","summary":"
Validates that the (list) does not contain the value.
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Array"}],"args_string":"(value, list : Array) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/presence.cr#L149","def":{"name":"not_in?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Array"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!(list.includes?(value))"}},{"id":"not_in?(value,list:Tuple):Bool-class-method","html_id":"not_in?(value,list:Tuple):Bool-class-method","name":"not_in?","doc":"Validates that the (*list*) does not contain the *value*.\n- See also `#absence?`.\n- See also `#in?`.\n- See also `#empty?`.","summary":"
Validates that the (list) does not contain the value.
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Tuple"}],"args_string":"(value, list : Tuple) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/presence.cr#L154","def":{"name":"not_in?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Tuple"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!(list.includes?(value))"}},{"id":"not_in?(value,list:Range):Bool-class-method","html_id":"not_in?(value,list:Range):Bool-class-method","name":"not_in?","doc":"Validates that the (*list*) does not contain the *value*.\n- See also `#absence?`.\n- See also `#in?`.\n- See also `#empty?`.","summary":"
Validates that the (list) does not contain the value.
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Range"}],"args_string":"(value, list : Range) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/presence.cr#L159","def":{"name":"not_in?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Range"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!(list.includes?(value))"}},{"id":"not_in?(key:Symbol|String,list:NamedTuple):Bool-class-method","html_id":"not_in?(key:Symbol|String,list:NamedTuple):Bool-class-method","name":"not_in?","doc":"Validates that the (*list*) does not contain the *value*.\n- See also `#absence?`.\n- See also `#in?`.\n- See also `#empty?`.","summary":"
Validates that the (list) does not contain the value.
","abstract":false,"args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"Symbol | String"},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"NamedTuple"}],"args_string":"(key : Symbol | String, list : NamedTuple) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/presence.cr#L164","def":{"name":"not_in?","args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"Symbol | String"},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"NamedTuple"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!(list.has_key?(key))"}},{"id":"not_in?(key:Symbol|String,list:Hash):Bool-class-method","html_id":"not_in?(key:Symbol|String,list:Hash):Bool-class-method","name":"not_in?","doc":"Validates that the (*list*) does not contain the *value*.\n- See also `#absence?`.\n- See also `#in?`.\n- See also `#empty?`.","summary":"
Validates that the (list) does not contain the value.
","abstract":false,"args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"Symbol | String"},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Hash"}],"args_string":"(key : Symbol | String, list : Hash) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/presence.cr#L169","def":{"name":"not_in?","args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"Symbol | String"},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Hash"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!(list.has_key?(key))"}},{"id":"not_null?(value):Bool-class-method","html_id":"not_null?(value):Bool-class-method","name":"not_null?","doc":"Validates that the *value* is not null (`nil`).\n- See also `#null?`.\n- See also `#not_empty?`.","summary":"
Validates that the value is not null (nil).
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"args_string":"(value) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/presence.cr#L89","def":{"name":"not_null?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!value.nil?"}},{"id":"null?(value):Bool-class-method","html_id":"null?(value):Bool-class-method","name":"null?","doc":"Validates that the *value* is null (`nil`).\n- See also `#empty?`.\n- See also `#not_null?`.","summary":"
Validates that the value is null (nil).
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"args_string":"(value) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/presence.cr#L82","def":{"name":"null?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value.nil?"}},{"id":"number?(value:String):Bool-class-method","html_id":"number?(value:String):Bool-class-method","name":"number?","doc":"Validates that the *value* is a numeric `String` representation.","summary":"
Validates that the value is a numeric String representation.
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/alpha_num.cr#L12","def":{"name":"number?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"(!value.blank?) && (!value.match(@@rx_number).nil?)"}},{"id":"port?(value:String="0",min:String="1",max:String="65535"):Bool-class-method","html_id":"port?(value:String="0",min:String="1",max:String="65535"):Bool-class-method","name":"port?","doc":"Validates that the *value* is in a valid port range,\nbetween (inclusive) 1 / *min* and 65535 / *max*.","summary":"
Validates that the value is in a valid port range, between (inclusive) 1 / min and 65535 / max.
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"\"0\"","external_name":"value","restriction":"String"},{"name":"min","doc":null,"default_value":"\"1\"","external_name":"min","restriction":"String"},{"name":"max","doc":null,"default_value":"\"65535\"","external_name":"max","restriction":"String"}],"args_string":"(value : String = "0", min : String = "1", max : String = "65535") : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/uri.cr#L44","def":{"name":"port?","args":[{"name":"value","doc":null,"default_value":"\"0\"","external_name":"value","restriction":"String"},{"name":"min","doc":null,"default_value":"\"1\"","external_name":"min","restriction":"String"},{"name":"max","doc":null,"default_value":"\"65535\"","external_name":"max","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"if (self.number?(min)) && (self.number?(max))\nelse\n return false\nend\nself.port?(value.to_i, min.to_i, max.to_i)\n"}},{"id":"port?(value=0,min=1,max=65535):Bool-class-method","html_id":"port?(value=0,min=1,max=65535):Bool-class-method","name":"port?","doc":"Validates that the *value* is in a valid port range,\nbetween (inclusive) 1 / *min* and 65535 / *max*.","summary":"
Validates that the value is in a valid port range, between (inclusive) 1 / min and 65535 / max.
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"0","external_name":"value","restriction":""},{"name":"min","doc":null,"default_value":"1","external_name":"min","restriction":""},{"name":"max","doc":null,"default_value":"65535","external_name":"max","restriction":""}],"args_string":"(value = 0, min = 1, max = 65535) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/uri.cr#L38","def":{"name":"port?","args":[{"name":"value","doc":null,"default_value":"0","external_name":"value","restriction":""},{"name":"min","doc":null,"default_value":"1","external_name":"min","restriction":""},{"name":"max","doc":null,"default_value":"65535","external_name":"max","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"if self.between?(value, 1, 65535)\nelse\n return false\nend\nself.between?(value, min, max)\n"}},{"id":"presence?(key:String|Symbol,list:NamedTuple):Bool-class-method","html_id":"presence?(key:String|Symbol,list:NamedTuple):Bool-class-method","name":"presence?","doc":"Validates the presence of the value.\n- See also `#in?`.\n- See also `#not_empty?`.","summary":"
Validates the presence of the value.
","abstract":false,"args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"String | Symbol"},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"NamedTuple"}],"args_string":"(key : String | Symbol, list : NamedTuple) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/presence.cr#L31","def":{"name":"presence?","args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"String | Symbol"},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"NamedTuple"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"self.not_empty?(list[key]?)"}},{"id":"presence?(key:String|Symbol|Number,list:Hash):Bool-class-method","html_id":"presence?(key:String|Symbol|Number,list:Hash):Bool-class-method","name":"presence?","doc":"Validates the presence of the value.\n- See also `#in?`.\n- See also `#not_empty?`.","summary":"
Validates the presence of the value.
","abstract":false,"args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"String | Symbol | Number"},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Hash"}],"args_string":"(key : String | Symbol | Number, list : Hash) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/presence.cr#L26","def":{"name":"presence?","args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"String | Symbol | Number"},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Hash"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"self.not_empty?(list[key]?)"}},{"id":"refused?(value):Bool-class-method","html_id":"refused?(value):Bool-class-method","name":"refused?","doc":"Returns `true` if the *value* is the representation of a refusal.\n> One of: \"no\", \"n\", \"off\", \"0\", \"false\"\n\n*value* must implements *#to_s* method.\n- See also `#accepted?`.","summary":"
Returns true if the value is the representation of a refusal.
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"args_string":"(value) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/presence.cr#L209","def":{"name":"refused?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"self.refused?(value.to_s)"}},{"id":"refused?(value:String):Bool-class-method","html_id":"refused?(value:String):Bool-class-method","name":"refused?","doc":"Validates that the *value* `String` is the representation of a refusal.\n> One of: \"no\", \"n\", \"off\", \"0\", \"false\"\n- See also `#accepted?`.","summary":"
Validates that the valueString is the representation of a refusal.
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/presence.cr#L200","def":{"name":"refused?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"self.in?(value.downcase, [\"no\", \"n\", \"off\", \"0\", \"false\"])"}},{"id":"size?(value,size:Array(String))-class-method","html_id":"size?(value,size:Array(String))-class-method","name":"size?","doc":"Validates that the *value* is in the *size* array.\n- See also `#between?`.","summary":"
Validates that the value is in the size array.
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"size","doc":null,"default_value":"","external_name":"size","restriction":"Array(String)"}],"args_string":"(value, size : Array(String))","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/comparisons.cr#L122","def":{"name":"size?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"size","doc":null,"default_value":"","external_name":"size","restriction":"Array(String)"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"size.includes?(value.size.to_s)"}},{"id":"size?(value,size:Array(Int))-class-method","html_id":"size?(value,size:Array(Int))-class-method","name":"size?","doc":"Validates that the *value* is in the *size* array.\n- See also `#between?`.","summary":"
Validates that the value is in the size array.
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"size","doc":null,"default_value":"","external_name":"size","restriction":"Array(Int)"}],"args_string":"(value, size : Array(Int))","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/comparisons.cr#L117","def":{"name":"size?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"size","doc":null,"default_value":"","external_name":"size","restriction":"Array(Int)"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"size.includes?(value.size)"}},{"id":"size?(value,size:Range)-class-method","html_id":"size?(value,size:Range)-class-method","name":"size?","doc":"Validates that the *value* is in the *size* range.\n- See also `#between?`.","summary":"
Validates that the value is in the size range.
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"size","doc":null,"default_value":"","external_name":"size","restriction":"Range"}],"args_string":"(value, size : Range)","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/comparisons.cr#L111","def":{"name":"size?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"size","doc":null,"default_value":"","external_name":"size","restriction":"Range"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"size.includes?(value.size)"}},{"id":"size?(value,size:String)-class-method","html_id":"size?(value,size:String)-class-method","name":"size?","doc":"Validates that the *value* is equal to the *size*.","summary":"
Validates that the value is equal to the size.
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"size","doc":null,"default_value":"","external_name":"size","restriction":"String"}],"args_string":"(value, size : String)","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/comparisons.cr#L105","def":{"name":"size?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"size","doc":null,"default_value":"","external_name":"size","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"value.size.to_s == size"}},{"id":"size?(value,size:Int)-class-method","html_id":"size?(value,size:Int)-class-method","name":"size?","doc":"Validates that the *value* is equal to the *size*.","summary":"
Validates that the value is equal to the size.
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"size","doc":null,"default_value":"","external_name":"size","restriction":"Int"}],"args_string":"(value, size : Int)","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/comparisons.cr#L100","def":{"name":"size?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"size","doc":null,"default_value":"","external_name":"size","restriction":"Int"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"value.size == size"}},{"id":"slug?(value:String,min=1,max=100):Bool-class-method","html_id":"slug?(value:String,min=1,max=100):Bool-class-method","name":"slug?","doc":"Validates that the *value* is a slug.","summary":"
Validates that the value is a slug.
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"min","doc":null,"default_value":"1","external_name":"min","restriction":""},{"name":"max","doc":null,"default_value":"100","external_name":"max","restriction":""}],"args_string":"(value : String, min = 1, max = 100) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/uri.cr#L171","def":{"name":"slug?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"min","doc":null,"default_value":"1","external_name":"min","restriction":""},{"name":"max","doc":null,"default_value":"100","external_name":"max","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!value.match(/^([a-zA-Z0-9_-]{#{min},#{max}})$/).nil?"}},{"id":"starts?(value:String,search:Char):Bool-class-method","html_id":"starts?(value:String,search:Char):Bool-class-method","name":"starts?","doc":"Validates that the `String` *value* starts with *search*.\n- See also `#ends?`.\n- See also `#match?`.\n- See also `#in?`.","summary":"
Validates that the Stringvalue starts with search.
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"search","doc":null,"default_value":"","external_name":"search","restriction":"Char"}],"args_string":"(value : String, search : Char) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/presence.cr#L226","def":{"name":"starts?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"search","doc":null,"default_value":"","external_name":"search","restriction":"Char"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value.starts_with?(search)"}},{"id":"starts?(value:String,search:Regex):Bool-class-method","html_id":"starts?(value:String,search:Regex):Bool-class-method","name":"starts?","doc":"Validates that the `String` *value* starts with *search*.\n- See also `#ends?`.\n- See also `#match?`.\n- See also `#in?`.","summary":"
Validates that the Stringvalue starts with search.
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"search","doc":null,"default_value":"","external_name":"search","restriction":"Regex"}],"args_string":"(value : String, search : Regex) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/presence.cr#L231","def":{"name":"starts?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"search","doc":null,"default_value":"","external_name":"search","restriction":"Regex"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value.starts_with?(search)"}},{"id":"starts?(value:String,search:String):Bool-class-method","html_id":"starts?(value:String,search:String):Bool-class-method","name":"starts?","doc":"Validates that the `String` *value* starts with *search*.\n- See also `#ends?`.\n- See also `#match?`.\n- See also `#in?`.","summary":"
Validates that the Stringvalue starts with search.
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"search","doc":null,"default_value":"","external_name":"search","restriction":"String"}],"args_string":"(value : String, search : String) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/presence.cr#L221","def":{"name":"starts?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"search","doc":null,"default_value":"","external_name":"search","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value.starts_with?(search)"}},{"id":"time?(value:String):Bool-class-method","html_id":"time?(value:String):Bool-class-method","name":"time?","doc":"Validates that the *value* is a time `String` representation.","summary":"
Validates that the value is a time String representation.
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/format.cr#L31","def":{"name":"time?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"(!value.blank?) && (!value.match(@@rx_time).nil?)"}},{"id":"upper?(value:String):Bool-class-method","html_id":"upper?(value:String):Bool-class-method","name":"upper?","doc":"Validates that the *value* is in upper case.","summary":"
Validates that the value is in upper case.
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/case_sensitive.cr#L15","def":{"name":"upper?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"(!value.blank?) && (value.upcase === value)"}},{"id":"url?(value:String):Bool-class-method","html_id":"url?(value:String):Bool-class-method","name":"url?","doc":"Validates that the *value* is a URL.","summary":"
Validates that the value is a URL.
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/uri.cr#L52","def":{"name":"url?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"size = value.size\nif ((size >= 2083 || size < 11) || (value.match(/[\\s<>]/))) || (value.starts_with?(\"mailto:\"))\n return false\nend\nif m = value.match(@@rx_url)\nelse\n return false\nend\nif self.domain?(\"#{m[\"name\"]}.#{m[\"ext\"]}\")\nelse\n return false\nend\nsp = (value.gsub(/^http(?:s)?:\\/\\//, \"\")).split(\":\")\nif sp.size > 1\n if m_port = sp[1].match(/^[0-9]+/)\n else\n return true\n end\n return self.port?(m_port[0])\nend\ntrue\n"}},{"id":"uuid?(value:String,version=0):Bool-class-method","html_id":"uuid?(value:String,version=0):Bool-class-method","name":"uuid?","doc":"Validates that the *value* is a *UUID*\nVersions: 0 (all), 3, 4 and 5. *version* by default is 0 (all).","summary":"
Validates that the value is a UUID Versions: 0 (all), 3, 4 and 5.
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"version","doc":null,"default_value":"0","external_name":"version","restriction":""}],"args_string":"(value : String, version = 0) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/format.cr#L103","def":{"name":"uuid?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"version","doc":null,"default_value":"0","external_name":"version","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"if @@rx_uuid.has_key?(version)\nelse\n return false\nend\n!value.match(@@rx_uuid[version]).nil?\n"}}],"constructors":[],"instance_methods":[],"macros":[],"types":[{"html_id":"validator/Validator/Error","path":"Validator/Error.html","kind":"class","full_name":"Validator::Error","name":"Error","abstract":false,"superclass":{"html_id":"validator/Exception","kind":"class","full_name":"Exception","name":"Exception"},"ancestors":[{"html_id":"validator/Exception","kind":"class","full_name":"Exception","name":"Exception"},{"html_id":"validator/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"validator/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"src/validator.cr","line_number":120,"url":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validator.cr#L120"}],"repository_name":"validator","program":false,"enum":false,"alias":false,"aliased":"","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"validator/Validator","kind":"module","full_name":"Validator","name":"Validator"},"doc":"Used by `is!` when a validation is not `true`.","summary":"
'
+ );
+
+ function handleShortkeys(event) {
+ var element = event.target || event.srcElement;
+
+ if(element.tagName == "INPUT" || element.tagName == "TEXTAREA" || element.parentElement.tagName == "TEXTAREA"){
+ return;
+ }
+
+ switch(event.key) {
+ case "?":
+ usageModal.show();
+ break;
+
+ case "Escape":
+ usageModal.hide();
+ break;
+
+ case "s":
+ case "/":
+ if(usageModal.isVisible()) {
+ return;
+ }
+ event.stopPropagation();
+ navigator.focus();
+ performSearch();
+ break;
+ }
+ }
+
+ document.addEventListener('keyup', handleShortkeys);
+
+ var scrollToEntryFromLocationHash = function() {
+ var hash = window.location.hash;
+ if (hash) {
+ var targetAnchor = decodeURI(hash.substr(1));
+ var targetEl = document.getElementById(targetAnchor)
+ if (targetEl) {
+ targetEl.offsetParent.scrollTop = targetEl.offsetTop;
+ }
+ }
+ };
+ window.addEventListener("hashchange", scrollToEntryFromLocationHash, false);
+ scrollToEntryFromLocationHash();
+});
diff --git a/docs/search-index.js b/docs/search-index.js
new file mode 100644
index 0000000..ef8c4cc
--- /dev/null
+++ b/docs/search-index.js
@@ -0,0 +1 @@
+crystal_doc_search_index_callback({"repository_name":"validator","body":"# validator\n\n[![Build Status](https://travis-ci.com/Nicolab/crystal-validator.svg?branch=master)](https://travis-ci.com/Nicolab/crystal-validator) [![GitHub release](https://img.shields.io/github/release/Nicolab/crystal-validator.svg)](https://github.com/Nicolab/crystal-validator/releases) [![Docs](https://img.shields.io/badge/docs-available-brightgreen.svg)](https://nicolab.github.io/crystal-validator/)\n\n∠(・.-)―〉 →◎ `validator` is a [Crystal](https://crystal-lang.org) data validation module. \nVery simple and efficient, all validations return `true` or `false`.\n\nAlso [validator/check](#check) (not exposed by default) provides:\n\n* Error message handling intended for the end user.\n* Also (optional) a powerful and productive system of validation rules.\n With self-generated granular methods for cleaning and checking data.\n\n**Validator** respects the [KISS principle](https://en.wikipedia.org/wiki/KISS_principle) and the [Unix Philosophy](https://en.wikipedia.org/wiki/Unix_philosophy). It's a great basis tool for doing your own validation logic on top of it.\n\n## Installation\n\n1. Add the dependency to your `shard.yml`:\n\n```yaml\ndependencies:\n validator:\n github: nicolab/crystal-validator\n version: ~> 1.1.0 # Check the latest version!\n```\n\n2. Run `shards install`\n\n## Usage\n\n* [Validator - API docs](https://nicolab.github.io/crystal-validator/)\n\nThere are 3 main ways to use *validator*:\n\n* As a simple validator to check rules (eg: email, url, min, max, presence, in, ...) which return a boolean.\n* As a more advanced validation system which will check a series of rules and returns all validation errors encountered with custom or standard messages.\n* As a system of validation rules (inspired by the _Laravel framework's Validator_)\n which makes data cleaning and data validation in Crystal very easy!\n With self-generated granular methods for cleaning and checking data of each field.\n\nBy default the **validator** module expose only `Validator` and `Valid` (alias) in the scope:\n\n```crystal\nrequire \"validator\"\n\nValid.email? \"contact@example.org\" # => true\nValid.url? \"https://github.com/Nicolab/crystal-validator\" # => true\nValid.my_validator? \"value to validate\", \"hello\", 42 # => true\n```\n\nAn (optional) expressive validation flavor, `is` available as an alternative.\nNot exposed by default, it must be imported:\n\n```crystal\nrequire \"validator/is\"\n\nis :email?, \"contact@example.org\" # => true\nis :url?, \"https://github.com/Nicolab/crystal-validator\" # => true\nis :my_validator?, \"value to validate\", \"hello\", 42 # => true\n\n\n# raises an error if the email is not valid\nis! :email?, \"contact@@example..org\" # => Validator::Error\n```\n\n`is` is a macro, no overhead during the runtime 🚀\n By the nature of the macros, you can't pass the *validator* name dynamically with a variable like that `is(validator_name, \"my value to validate\", arg)`.\n But of course you can pass arguments with variables `is(:validator_name?, arg1, arg2)`.\n\n* [Validator - API docs](https://nicolab.github.io/crystal-validator/)\n\n### Validation rules\n\n```crystal\nrequire \"validator/check\"\n\nclass User\n # Mixin\n Check.checkable\n\n property email : String\n property age : Int32\n property bio : String?\n\n Check.rules(\n # required\n email: {\n required: true,\n\n # Checker (all validators are supported)\n check: {\n not_empty: {\"Email is required\"},\n email: {\"It is not a valid email\"},\n },\n\n # Cleaner\n clean: {\n # Data type\n type: String,\n\n # Converter (if union or other) to the expected value type.\n # Example if the input value is i32, but i64 is expected\n # Here is a String\n to: :to_s,\n\n # Formatter (any Crystal Proc)\n format: ->self.format_email(String),\n\n # Error message\n # Default is \"Wrong type\" but it can be customized\n message: \"Oops! Wrong type.\",\n },\n },\n\n # required\n age: {\n required: true,\n check: {\n min: {\"Age should be more than 18\", 18},\n between: {\"Age should be between 25 and 35\", 25, 35},\n },\n clean: {type: Int32, to: :to_i32, message: \"Unable to cast to Int32\"},\n },\n\n # nilable\n bio: {\n check: {\n between: {\"The user bio must be between 2 and 400 characters.\", 2, 400},\n },\n clean: {\n type: String,\n to: :to_s,\n # `nilable` means omited if not provided,\n # regardless of Crystal type (nilable or not)\n nilable: true\n },\n },\n )\n\n def initialize(@email, @age); end\n\n # ---------------------------------------------------------------------------\n # Lifecycle methods (hooks)\n # ---------------------------------------------------------------------------\n\n # Triggered on instance: `user.check`\n def before_check(v : Check::Validation, required : Bool, format : Bool)\n # Code...\n end\n\n # Triggered on instance: `user.check`\n def after_check(v : Check::Validation, required : Bool, format : Bool)\n # Code...\n end\n\n # Triggered on a static call: `User.check(h)` (with a `Hash` or `JSON::Any`)\n def self.before_check(v : Check::Validation, h, required : Bool, format : Bool)\n # Code...\n pp h\n end\n\n # Triggered on a static call: `User.check(h)` (with a `Hash` or `JSON::Any`)\n def self.after_check(v : Check::Validation, h, cleaned_h, required : Bool, format : Bool)\n # Code...\n pp cleaned_h\n cleaned_h # <= returns cleaned_h!\n end\n\n # --------------------------------------------------------------------------\n # Custom checkers\n # --------------------------------------------------------------------------\n\n # Triggered on instance: `user.check`\n @[Check::Checker]\n def custom_checker(v : Check::Validation, required : Bool, format : Bool)\n self.custom_checker_called = true\n end\n\n # Triggered on a static call: `User.check(h)` (with a `Hash` or `JSON::Any`)\n @[Check::Checker]\n def self.custom_checker(v : Check::Validation, h, cleaned_h, required : Bool, format : Bool)\n @@custom_checker_called = true\n cleaned_h # <= returns cleaned_h!\n end\n\n # --------------------------------------------------------------------------\n # Formatters\n # --------------------------------------------------------------------------\n\n # Format (convert) email.\n def self.format_email(email)\n puts \"mail stripped\"\n email.strip\n end\n\n # --------------------------------------------------------------------------\n # Normal methods\n # --------------------------------------------------------------------------\n\n def foo()\n # Code...\n end\n\n def self.bar(v)\n # Code...\n end\n\n # ...\n end\n```\n\n__Check__ with this example class (`User`):\n\n```crystal\n# Check a Hash (statically)\nv, user_h = User.check(input_h)\n\npp v # => Validation instance\npp v.valid?\npp v.errors\n\npp user_h # => Casted and cleaned Hash\n\n# Check a Hash (on instance)\nuser = user.new(\"demo@example.org\", 38)\n\nv = user.check # => Validation instance\npp v.valid?\npp v.errors\n\n# Check field\nv, email = User.check_email(value: \"demo@example.org\")\nv, age = User.check_age(value: 42)\n\nv, email = User.check_email(value: \"demo@example.org \", format: true)\nv, email = User.check_email(value: \"demo@example.org \", format: false)\n\n# Using an existing Validation instance\nv = Check.new_validation\nv, email = User.check_email(v, value: \"demo@example.org\")\n```\n\n__Clean__ with this example class (`User`):\n\n```crystal\n# `check` method cleans all values of the Hash (or JSON::Any),\n# before executing the validation rules\nv, user_h = User.check(input_h)\n\npp v # => Validation instance\npp v.valid?\npp v.errors\n\npp user_h # => Casted and cleaned Hash\n\n# Cast and clean field\nok, email = User.clean_email(value: \"demo@example.org\")\nok, age = User.clean_age(value: 42)\n\nok, email = User.clean_email(value: \"demo@example.org \", format: true)\nok, email = User.clean_email(value: \"demo@example.org \", format: false)\n\nputs \"${email} is casted and cleaned\" if ok\n# or\nputs \"Email type error\" unless ok\n```\n\n* `clean_*` methods are useful to caste a union value (like `Hash` or `JSON::Any`).\n* Also `clean_*` methods are optional and handy for formatting values, such as the strip on the email in the example `User` class.\n\nMore details about cleaning, casting, formatting and return values:\n\nBy default `format` is `true`, to disable:\n\n```crystal\nok, email = User.clean_email(value: \"demo@example.org\", format: false)\n# or\nok, email = User.clean_email(\"demo@example.org\", false)\n```\n\nAlways use named argument if there is only one (the `value`):\n\n```crystal\nok, email = User.clean_email(value: \"demo@example.org\")\n```\n\n`ok` is a boolean value that reports whether the cast succeeded. Like the type assertions in _Go_ (lang).\nBut the `ok` value is returned in first (like in _Elixir_ lang) for easy handling of multiple return values (`Tuple`).\n\nExample with multiple values returned:\n\n```crystal\nok, value1, value2 = User.clean_my_tuple({1, 2, 3})\n```\n\nConsidering the example class above (`User`).\nAs a reminder, the email field has been defined with the formatter below:\n\n```crystal\nCheck.rules(\n email: {\n clean: {\n type: String,\n to: :to_s,\n format: ->self.format_email(String), # <= Here!\n message: \"Wrong type\",\n },\n },\n)\n\n# ...\n\n# Format (convert) email.\ndef self.format_email(email)\n puts \"mail stripped\"\n email.strip\nend\n```\n\nSo `clean_email` cast to `String` and strip the value `\" demo@example.org \"`:\n\n```crystal\n# Email value with one space before and one space after\nok, email = User.clean_email(value: \" demo@example.org \")\n\nputs email # => \"demo@example.org\"\n```\n\nIf the email was taken from a union type (`json[\"email\"]?`), the returned `email` variable would be a `String` too.\n\nSee [more examples](https://github.com/Nicolab/crystal-validator/tree/master/examples).\n\n> NOTE: Require more explanations about `required`, `nilable` rules.\n> Also about the converters JSON / Crystal Hash: `h_from_json`, `to_json_h`, `to_crystal_h`.\n> In the meantime see the [API doc](https://nicolab.github.io/crystal-validator/Check/Checkable.html).\n\n### Validation#check\n\nTo perform a series of validations with error handling, the [validator/check](https://nicolab.github.io/crystal-validator/Check.html) module offers this possibility 👍\n\nA [Validation](https://nicolab.github.io/crystal-validator/Check/Validation.html) instance provides the means to write sequential checks, fine-tune each micro-validation with their own rules and custom error message, the possibility to retrieve all error messages, etc.\n\n> `Validation` is also used with `Check.rules` and `Check.checkable`\n that provide a powerful and productive system of validation rules\n which makes data cleaning and data validation in Crystal very easy.\n With self-generated granular methods for cleaning and checking data.\n\nTo use the checker (`check`) includes in the `Validation` class:\n\n```crystal\nrequire \"validator/check\"\n\n# Validates the *user* data received in the HTTP controller or other.\ndef validate_user(user : Hash) : Check::Validation\n v = Check.new_validation\n\n # -- email\n\n # Hash key can be a String or a Symbol\n v.check :email, \"The email is required.\", is :presence?, :email, user\n\n v.check \"email\", \"The email is required.\", is :presence?, \"email\", user\n v.check \"email\", \"#{user[\"email\"]} is an invalid email.\", is :email?, user[\"email\"]\n\n # -- username\n\n v.check \"username\", \"The username is required.\", is :presence?, \"username\", user\n\n v.check(\n \"username\",\n \"The username must contain at least 2 characters.\",\n is :min?, user[\"username\"], 2\n )\n\n v.check(\n \"username\",\n \"The username must contain a maximum of 20 characters.\",\n is :max?, user[\"username\"], 20\n )\nend\n\nv = validate_user user\n\npp v.valid? # => true (or false)\n\n# Inverse of v.valid?\nif v.errors.empty?\n return \"no error\"\nend\n\n# Print all the errors (if any)\npp v.errors\n\n# It's a Hash of Array\nerrors = v.errors\n\nputs errors.size\nputs errors.first_value\n\nerrors.each do |key, messages|\n puts key # => \"username\"\n puts messages # => [\"The username is required.\", \"etc...\"]\nend\n```\n\n3 methods [#check](https://nicolab.github.io/crystal-validator/Check/Validation.html#instance-method-summary):\n\n```crystal\n# check(key : Symbol | String, valid : Bool)\n# Using default error message\nv.check(\n \"username\",\n is(:min?, user[\"username\"], 2)\n)\n\n# check(key : Symbol | String, message : String, valid : Bool)\n# Using custom error message\nv.check(\n \"username\",\n \"The username must contain at least 2 characters.\",\n is(:min?, user[\"username\"], 2)\n)\n\n# check(key : Symbol | String, valid : Bool, message : String)\n# Using custom error message\nv.check(\n \"username\",\n is(:min?, user[\"username\"], 2),\n \"The username must contain at least 2 characters.\"\n)\n```\n\n`Check` is a simple and lightweight wrapper.\nThe `Check::Validation` is agnostic of the checked data,\nof the context (model, controller, CSV file, HTTP data, socket data, JSON, etc).\n\n> Use case example:\n Before saving to the database or process user data for a particular task,\n the custom error messages can be used for the end user response.\n\nBut a `Validation` instance can be used just to store validation errors:\n\n```crystal\nv = Check.new_validation\nv.add_error(\"foo\", \"foo error!\")\npp v.errors # => {\"foo\" => [\"foo error!\"]}\n```\n\n> See also `Check.rules` and `Check.checkable`.\n\nLet your imagination run wild to add your logic around it.\n\n### Custom validator\n\nJust add your own method to register a custom *validator* or to overload an existing *validator*.\n\n```crystal\nmodule Validator\n # My custom validator\n def self.my_validator?(value, arg : String, another_arg : Int32) : Bool\n # write here the logic of your validator...\n return true\n end\nend\n\n# Call it\nputs Valid.my_validator?(\"value to validate\", \"hello\", 42) # => true\n\n# or with the `is` flavor\nputs is :my_validator?, \"value to validate\", \"hello\", 42 # => true\n```\n\nUsing the custom validator with the validation rules:\n\n```crystal\nrequire \"validator/check\"\n\nclass Article\n # Mixin\n Check.checkable\n\n property title : String\n property content : String\n\n Check.rules(\n content: {\n # Now the custom validator is available\n check: {\n my_validator: {\"My validator error message\"},\n between: {\"The article content must be between 10 and 20 000 characters\", 10, 20_000},\n # ...\n },\n },\n )\nend\n\n# Triggered with all data\nv, article = Article.check(input_data)\n\n# Triggered with one value\nv, content = Article.check_content(input_data[\"content\"]?)\n```\n\n## Conventions\n\n* The word \"validator\" is the method to make a \"validation\" (value validation).\n* A *validator* returns `true` if the value (or/and the condition) is valid, `false` if not.\n* The first argument(s) is (are) the value(s) to be validated.\n* Always add the `Bool` return type to a *validator*.\n* Always add the suffix `?` to the method name of a *validator*.\n* If possible, indicates the type of the *validator* arguments.\n* Spec: Battle tested.\n* [KISS](https://en.wikipedia.org/wiki/KISS_principle) and [Unix Philosophy](https://en.wikipedia.org/wiki/Unix_philosophy).\n\n## Development\n\n```sh\ncrystal spec\ncrystal tool format\n```\n\n> TODO: add `ameba`?\n\n## Contributing\n\n1. Fork it ()\n2. Create your feature branch (`git checkout -b my-new-feature`)\n3. Commit your changes (`git commit -am 'Add some feature'`)\n4. Push to the branch (`git push origin my-new-feature`)\n5. Create a new Pull Request\n\n## LICENSE\n\n[MIT](https://github.com/Nicolab/crystal-validator/blob/master/LICENSE) (c) 2020, Nicolas Talle.\n\n## Author\n\n| [![Nicolas Tallefourtane - Nicolab.net](https://www.gravatar.com/avatar/d7dd0f4769f3aa48a3ecb308f0b457fc?s=64)](https://github.com/sponsors/Nicolab) |\n|---|\n| [Nicolas Talle](https://github.com/sponsors/Nicolab) |\n| [![Make a donation via Paypal](https://www.paypalobjects.com/en_US/i/btn/btn_donate_SM.gif)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=PGRH4ZXP36GUC) |\n\n> Thanks to [ilourt](https://github.com/ilourt) for his great work on `checkable` mixins (clean_*, check_*, ...).\n","program":{"html_id":"validator/toplevel","path":"toplevel.html","kind":"module","full_name":"Top Level Namespace","name":"Top Level Namespace","abstract":false,"superclass":null,"ancestors":[],"locations":[],"repository_name":"validator","program":true,"enum":false,"alias":false,"aliased":"","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":null,"doc":null,"summary":null,"class_methods":[],"constructors":[],"instance_methods":[],"macros":[{"id":"is(name,*args)-macro","html_id":"is(name,*args)-macro","name":"is","doc":"An (optional) expressive flavor of `Validator` (or `Valid` alias).\nNot exposed by default, must be imported:\n\n```\nrequire \"validator/is\"\n\nis :email?, \"contact@example.org\" # => true\nis \"email?\", \"contact@example.org\" # => true\nis :url?, \"https://github.com/Nicolab/crystal-validator\" # => true\n```","summary":"
An (optional) expressive flavor of Validator (or Valid alias).
","abstract":false,"args":[{"name":"name","doc":null,"default_value":"","external_name":"name","restriction":""},{"name":"args","doc":null,"default_value":"","external_name":"args","restriction":""}],"args_string":"(name, *args)","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/is.cr#L18","def":{"name":"is","args":[{"name":"name","doc":null,"default_value":"","external_name":"name","restriction":""},{"name":"args","doc":null,"default_value":"","external_name":"args","restriction":""}],"double_splat":null,"splat_index":1,"block_arg":null,"visibility":"Public","body":" \n# Symbol ? String\n\n Valid.\n{{ name.id }}\n \n{{ args.splat }}\n\n\n"}},{"id":"is!(name,*args)-macro","html_id":"is!(name,*args)-macro","name":"is!","doc":"Same as `is` but `raise` a `Validator::Error`\ndisplaying an inspection if the validation is `false`.\nUseful for the unit tests :)","summary":"
Same as is but raise a Validator::Error displaying an inspection if the validation is false.
","abstract":false,"args":[{"name":"name","doc":null,"default_value":"","external_name":"name","restriction":""},{"name":"args","doc":null,"default_value":"","external_name":"args","restriction":""}],"args_string":"(name, *args)","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/is.cr#L26","def":{"name":"is!","args":[{"name":"name","doc":null,"default_value":"","external_name":"name","restriction":""},{"name":"args","doc":null,"default_value":"","external_name":"args","restriction":""}],"double_splat":null,"splat_index":1,"block_arg":null,"visibility":"Public","body":" \n# Symbol ? String\n\n valid = Valid.\n{{ name.id }}\n \n{{ args.splat }}\n\n\n if valid == false\n raise Validator::Error.new \"Is not \\\"#{\n{{ name }}\n}\\\":\\n#{\n{{ args.stringify }}\n}\"\n \nend\n\n true\n\n"}}],"types":[{"html_id":"validator/Check","path":"Check.html","kind":"module","full_name":"Check","name":"Check","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/check.cr","line_number":11,"url":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/check.cr#L11"},{"filename":"src/checkable.cr","line_number":9,"url":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/checkable.cr#L9"}],"repository_name":"validator","program":false,"enum":false,"alias":false,"aliased":"","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":null,"doc":"Standalone check module that provides a practical workflow for validations.","summary":"
Standalone check module that provides a practical workflow for validations.
","class_methods":[{"id":"new_validation(errors:Errors)-class-method","html_id":"new_validation(errors:Errors)-class-method","name":"new_validation","doc":"Initializes a new `Validation` instance to combine\na series of checks (`Validation#check`).\nusing an existing *errors* `Hash` (`Check::Errors`).\n\n```\nv = Check.new_validation existing_errors\n```\n\nSame as:\n\n```\nv = Check::Validation.new existing_errors\n```\n\nExample to combine two hashes of validation errors:\n\n```\npreview_validation = Check.new_validation\nv = Check.new_validation preview_validation.errors\n```","summary":"
","abstract":false,"args":[{"name":"errors","doc":null,"default_value":"","external_name":"errors","restriction":"Errors"}],"args_string":"(errors : Errors)","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/check.cr#L359","def":{"name":"new_validation","args":[{"name":"errors","doc":null,"default_value":"","external_name":"errors","restriction":"Errors"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"Validation.new(errors)"}},{"id":"new_validation-class-method","html_id":"new_validation-class-method","name":"new_validation","doc":"Initializes a new `Validation` instance to combine\na series of checks (`Validation#check`).\n\n```\nv = Check.new_validation\n```\n\nSame as:\n\n```\nv = Check::Validation.new\n```","summary":"
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/check.cr#L335","def":{"name":"new_validation","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"Validation.new"}}],"constructors":[],"instance_methods":[],"macros":[{"id":"checkable-macro","html_id":"checkable-macro","name":"checkable","doc":"A mixin to make a class checkable.\nThis mixin includes `Checkable` and `CheckableStatic`.\nIt must be used in conjonction with `Check.rules`.\n\n```\nrequire \"validator/check\"\n\nclass Article\n # Mixin\n Check.checkable\n\n property title : String\n property content : String\n\n Check.rules(\n content: {\n check: {\n not_empty: {\"Article content is required\"},\n between: {\"The article content must be between 10 and 20 000 characters\", 10, 20_000},\n # ...\n },\n clean: {\n type: String,\n to: :to_s,\n format: ->(content : String) { content.strip },\n message: \"Wrong type\",\n },\n },\n )\nend\n\n# Triggered on all data\nv, article = Article.check(input_data)\n\n# Triggered on a value\nv, content = Article.check_content(input_data[\"content\"]?)\n```","summary":"
A mixin to make a class checkable.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/checkable.cr#L67","def":{"name":"checkable","args":[],"double_splat":null,"splat_index":null,"block_arg":null,"visibility":"Public","body":" include Check::Checkable\n \nextend Check::CheckableStatic\n \n"}},{"id":"rules(**fields)-macro","html_id":"rules(**fields)-macro","name":"rules","doc":"Generates `check`, `check_{{field}}` and `clean_{{field}}` methods for *fields* (class variables).\n\n```\nrequire \"validator/check\"\n\nclass Article\n # Mixin\n Check.checkable\n\n property title : String\n property content : String\n property url : String?\n\n Check.rules(\n content: {\n required: true,\n check: {\n not_empty: {\"Article content is required\"},\n between: {\"The article content must be between 10 and 20 000 characters\", 10, 20_000},\n # ...\n },\n clean: {\n type: String,\n to: :to_s,\n format: ->(content : String) { content.strip },\n message: \"Wrong type\",\n },\n },\n url: {\n check: {\n url: {\"Article URL is invalid\"},\n },\n clean: {\n # `nilable` means omited if not provided,\n # regardless of Crystal type (nilable or not)\n nilable: true,\n # Crystal type\n type: String,\n # Converter to the expected typed value\n to: :to_s,\n },\n },\n # ...\n)\nend\n\n# Triggered on all data\nv, article = Article.check(input_data)\n\n# Triggered on all fields of an instance\narticle = Article.new(title: \"foo\", content: \"bar\")\nv = article.check\n\n# Triggered on a value\nv, content = Article.check_content(input_data[\"content\"]?)\n\n# Cast and clean a value\nok, content = Article.clean_content(input_data[\"content\"]?)\n```\n\nSee also `Check.checkable`.","summary":"
Generates check, check_{{field}} and clean_{{field}} methods for fields (class variables).
","abstract":false,"args":[],"args_string":"(**fields)","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/checkable.cr#L133","def":{"name":"rules","args":[],"double_splat":{"name":"fields","doc":null,"default_value":"","external_name":"fields","restriction":""},"splat_index":null,"block_arg":null,"visibility":"Public","body":" private def self.validation_rules\n \n{{ fields }}\n\n \nend\n\n private def self.validation_required?(field) : Bool\n fields = self.validation_rules\n return false if fields[field].nil?\n fields[field].fetch(\"required\", false).as(Bool)\n \nend\n\n private def self.validation_nilable?(field) : Bool\n fields = self.validation_rules\n return false if fields[field].nil? || fields[field][\"clean\"].nil?\n fields[field][\"clean\"].fetch(\"nilable\", false).as(Bool)\n \nend\n\n \n{% for field, rules in fields %}\n {% clean = rules[\"clean\"] %}\n {% check = rules[\"check\"] %}\n {% type = clean[\"type\"] %}\n {% nilable = clean[\"nilable\"] %}\n\n # Returns *{{ field }}* with the good type and formatted if *format* is `true`.\n # The return type is a tuple with a bool as a first argument indicating\n # that the clean has been processed successfully or not and the 2nd\n # argument is the *value* cleaned.\n #\n # ```\n # ok, email = Checkable.clean_email(user_input[\"email\"]) # => true, user@example.com\n # ```\n def self.clean_{{ field }}(value, format = true) : Tuple(Bool, {{ type }} | Nil)\n # force real Nil type (hack for JSON::Any and equivalent)\n value = nil if value == nil\n\n {% if to = clean[\"to\"] %}\n # Check if the *value* has the method `{{ to }}` and execute it if\n # exists to cast the value in the good type (except if the value is nil and nilable).\n if value.responds_to? {{ to }} {% if nilable %} && !value.nil?{% end %}\n begin\n value = value.{{ to.id }}\n rescue\n return false, nil\n end\n end\n {% end %}\n\n # Format if the value as the correct (Crystal) type.\n # `| Nil` allows to format in the case of a nilable value (example `String?`)\n # where the `type` option of `clean` rules has been defined on the precise\n # Crystal type (example `String`).\n if value.is_a? {{ type }} | Nil\n {% if format = clean[\"format\"] %}\n # If *format* is true then call it to format *value*.\n if format\n begin\n return true, {{ format }}.call(value)\n rescue\n return false, nil\n end\n else\n return true, value\n end\n {% else %}\n return true, value\n {% end %}\n end\n\n {false, nil}\n end\n\n # Create a new `Check::Validation` and checks *{{ field }}*.\n # For more infos check `.check_{{ field }}(v : Check::Validation, value, format : Bool = true)`\n def self.check_{{ field }}(\n *,\n value,\n required : Bool = true,\n format : Bool = true\n ) : Tuple(Check::Validation, {{ type }} | Nil)\n v = Check.new_validation\n self.check_{{ field }}(v, value, required, format)\n end\n\n # Cleans and check *value*.\n # If *format* is `true` it tells `.clean_{{ field }}` to execute the `format` function\n # for this field if it has been defined with `Check.rules`.\n def self.check_{{ field }}(\n v : Check::Validation,\n value,\n required : Bool = true,\n format : Bool = true\n ) : Tuple(Check::Validation, {{ type }} | Nil)\n # Cleans and formats the *value*\n ok, value = self.clean_{{ field }}(value, format)\n\n # If clean has encountered an error, add error message and stop check here.\n if ok == false\n {% msg = clean[\"message\"] || \"Wrong type\" %}\n v.add_error {{ field.stringify }}, {{ msg }} {% if nilable || (check[\"not_null\"].nil? && check[\"not_empty\"].nil?) %}unless value.nil?{% end %}\n return v, value\n end\n\n # Check against each rule provided.\n # Each rule is executed if *value* is not `nil` except for `not_null` and `not_empty`\n # which is executed even if the *value* is `nil`\n {% for name, args in check %}\n v.check(\n {{ field.stringify }},\n {{ args[0] }},\n {% if args.size <= 1 %}\n Valid.{{ name.id }}? value\n {% else %}\n Valid.{{ name.id }}? value, {{ args[1..-1].splat }}\n {% end %}\n ) {% if (nilable || (check[\"not_null\"].nil? && check[\"not_empty\"].nil?)) || ((name != \"not_null\") && (name != \"not_empty\")) %}unless value.nil?{% end %}\n {% end %}\n\n {v, value}\n end\n {% end %}\n\n \n"}}],"types":[{"html_id":"validator/Check/Checkable","path":"Check/Checkable.html","kind":"module","full_name":"Check::Checkable","name":"Checkable","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/checkable.cr","line_number":411,"url":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/checkable.cr#L411"}],"repository_name":"validator","program":false,"enum":false,"alias":false,"aliased":"","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"validator/Check","kind":"module","full_name":"Check","name":"Check"},"doc":"Mixin that adds `#check` method to be used with variables of an instance of the class including it.\nThe idea is to check the instance variables of the class extending it\nagainst rules defined with `Check.rules` plus executing custom checkers defined with `Checker`.","summary":"
Mixin that adds #check method to be used with variables of an instance of the class including it.
","class_methods":[],"constructors":[],"instance_methods":[{"id":"after_check(v:Check::Validation,required:Bool=true,format:Bool=true)-instance-method","html_id":"after_check(v:Check::Validation,required:Bool=true,format:Bool=true)-instance-method","name":"after_check","doc":"Lifecycle method triggered after each call of `#check`.\n\n```\n# Triggered on instance: `user.check`\ndef after_check(v : Check::Validation, required : Bool = true, format : Bool = true)\n # Code...\nend\n```","summary":"
Lifecycle method triggered after each call of #check.
","abstract":false,"args":[{"name":"v","doc":null,"default_value":"","external_name":"v","restriction":"Check::Validation"},{"name":"required","doc":null,"default_value":"true","external_name":"required","restriction":"Bool"},{"name":"format","doc":null,"default_value":"true","external_name":"format","restriction":"Bool"}],"args_string":"(v : Check::Validation, required : Bool = true, format : Bool = true)","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/checkable.cr#L434","def":{"name":"after_check","args":[{"name":"v","doc":null,"default_value":"","external_name":"v","restriction":"Check::Validation"},{"name":"required","doc":null,"default_value":"true","external_name":"required","restriction":"Bool"},{"name":"format","doc":null,"default_value":"true","external_name":"format","restriction":"Bool"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":""}},{"id":"before_check(v:Check::Validation,required:Bool=true,format:Bool=true)-instance-method","html_id":"before_check(v:Check::Validation,required:Bool=true,format:Bool=true)-instance-method","name":"before_check","doc":"Lifecycle method triggered before each call of `#check`.\n\n```\n# Triggered on instance: `user.check`\ndef before_check(v : Check::Validation, required : Bool = true, format : Bool = true)\n # Code...\nend\n```","summary":"
Lifecycle method triggered before each call of #check.
","abstract":false,"args":[{"name":"v","doc":null,"default_value":"","external_name":"v","restriction":"Check::Validation"},{"name":"required","doc":null,"default_value":"true","external_name":"required","restriction":"Bool"},{"name":"format","doc":null,"default_value":"true","external_name":"format","restriction":"Bool"}],"args_string":"(v : Check::Validation, required : Bool = true, format : Bool = true)","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/checkable.cr#L420","def":{"name":"before_check","args":[{"name":"v","doc":null,"default_value":"","external_name":"v","restriction":"Check::Validation"},{"name":"required","doc":null,"default_value":"true","external_name":"required","restriction":"Bool"},{"name":"format","doc":null,"default_value":"true","external_name":"format","restriction":"Bool"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":""}},{"id":"check(required:Bool=true,format:Bool=true):Validation-instance-method","html_id":"check(required:Bool=true,format:Bool=true):Validation-instance-method","name":"check","doc":"Checks the instance fields and clean them.\n\nIt instantiates a `Check::Validation` (if not provided) and calls all methods\nrelated to rules and then methods defined with annotation `Checker`.\n\nLifecycle methods `#before_check` and `#after_check` that are triggered\nrespectively at the beginning and at the end of the process.\n\n*format* is used to tell cleaners generated by `Check.rules`\nto execute format method if it has been defined.","summary":"
Checks the instance fields and clean them.
","abstract":false,"args":[{"name":"required","doc":null,"default_value":"true","external_name":"required","restriction":"Bool"},{"name":"format","doc":null,"default_value":"true","external_name":"format","restriction":"Bool"}],"args_string":"(required : Bool = true, format : Bool = true) : Validation","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/checkable.cr#L480","def":{"name":"check","args":[{"name":"required","doc":null,"default_value":"true","external_name":"required","restriction":"Bool"},{"name":"format","doc":null,"default_value":"true","external_name":"format","restriction":"Bool"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Validation","visibility":"Public","body":"v = Check.new_validation\ncheck(v, required, format)\n"}},{"id":"check(v:Check::Validation,required:Bool=true,format:Bool=true):Validation-instance-method","html_id":"check(v:Check::Validation,required:Bool=true,format:Bool=true):Validation-instance-method","name":"check","doc":"Checks the instance fields and clean them.\n\nIt instantiates a `Check::Validation` (if not provided) and calls all methods\nrelated to rules and then methods defined with annotation `Checker`.\n\nLifecycle methods `#before_check` and `#after_check` that are triggered\nrespectively at the beginning and at the end of the process.\n\n*format* is used to tell cleaners generated by `Check.rules`\nto execute format method if it has been defined.","summary":"
Checks the instance fields and clean them.
","abstract":false,"args":[{"name":"v","doc":null,"default_value":"","external_name":"v","restriction":"Check::Validation"},{"name":"required","doc":null,"default_value":"true","external_name":"required","restriction":"Bool"},{"name":"format","doc":null,"default_value":"true","external_name":"format","restriction":"Bool"}],"args_string":"(v : Check::Validation, required : Bool = true, format : Bool = true) : Validation","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/checkable.cr#L450","def":{"name":"check","args":[{"name":"v","doc":null,"default_value":"","external_name":"v","restriction":"Check::Validation"},{"name":"required","doc":null,"default_value":"true","external_name":"required","restriction":"Bool"},{"name":"format","doc":null,"default_value":"true","external_name":"format","restriction":"Bool"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Validation","visibility":"Public","body":"{% if true %}\n\n # Call lifecycle method before check\n before_check v, required, format\n\n # Check all fields that have a method `#check_{field}`\n {% for ivar in @type.instance_vars.select do |ivar|\n @type.class.has_method?(\"check_#{ivar}\")\nend %}\n v, value = self.class.check_{{ ivar.name }}(v, {{ ivar.name }}, required, format)\n\n # If the field is not nilable and the value is nil,\n # it means that the clean method has failed\n # (to cast or an exception has been raised (and catched) in the formatter)\n # So ignore the nil value if the field is not nilable\n @{{ ivar.name }} = value.as({{ ivar.type }}) {% if !ivar.type.nilable? %} unless value.nil? {% end %}\n {% end %}\n\n # Check methods with `Check::Checker` annotation\n {% for method in @type.methods.select do |method|\n method.annotation(Checker)\nend %}\n {{ method.name }} v, required, format\n {% end %}\n\n # Call lifecycle method `#after_check`\n after_check v, required, format\n\n v\n {% end %}"}}],"macros":[],"types":[]},{"html_id":"validator/Check/CheckableStatic","path":"Check/CheckableStatic.html","kind":"module","full_name":"Check::CheckableStatic","name":"CheckableStatic","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/checkable.cr","line_number":261,"url":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/checkable.cr#L261"}],"repository_name":"validator","program":false,"enum":false,"alias":false,"aliased":"","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"validator/Check","kind":"module","full_name":"Check","name":"Check"},"doc":"Mixin that adds `.check` method to be used with a `Hash`.\nThe idea is to check a `Hash` against rules defined with `Check.rules`\nplus executing custom checkers defined with `Checker` annotation.","summary":"
Mixin that adds .check method to be used with a Hash.
","class_methods":[],"constructors":[],"instance_methods":[{"id":"after_check(v:Check::Validation,h:Hash,cleaned_h:Hash,required:Bool=true,format:Bool=true):Hash-instance-method","html_id":"after_check(v:Check::Validation,h:Hash,cleaned_h:Hash,required:Bool=true,format:Bool=true):Hash-instance-method","name":"after_check","doc":"Lifecycle method triggered after each call of `.check`.\n\nThis method (in static call) must returns the cleaned `Hash`\nwhich is provided in the third argument.\nYou can update this cleaned hash but you have to return it.\n\n```\n# Triggered on a static call: `User.check(h)` (with a `Hash` or `JSON::Any`)\ndef self.after_check(v : Check::Validation, h, cleaned_h, required : Bool = true, format : Bool = true) : Hash\n # Code...\n pp cleaned_h\n cleaned_h # <= returns cleaned_h!\nend\n```","summary":"
Lifecycle method triggered after each call of .check.
","abstract":false,"args":[{"name":"v","doc":null,"default_value":"","external_name":"v","restriction":"Check::Validation"},{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"Hash"},{"name":"cleaned_h","doc":null,"default_value":"","external_name":"cleaned_h","restriction":"Hash"},{"name":"required","doc":null,"default_value":"true","external_name":"required","restriction":"Bool"},{"name":"format","doc":null,"default_value":"true","external_name":"format","restriction":"Bool"}],"args_string":"(v : Check::Validation, h : Hash, cleaned_h : Hash, required : Bool = true, format : Bool = true) : Hash","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/checkable.cr#L341","def":{"name":"after_check","args":[{"name":"v","doc":null,"default_value":"","external_name":"v","restriction":"Check::Validation"},{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"Hash"},{"name":"cleaned_h","doc":null,"default_value":"","external_name":"cleaned_h","restriction":"Hash"},{"name":"required","doc":null,"default_value":"true","external_name":"required","restriction":"Bool"},{"name":"format","doc":null,"default_value":"true","external_name":"format","restriction":"Bool"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Hash","visibility":"Public","body":"cleaned_h"}},{"id":"before_check(v:Check::Validation,h:Hash,required:Bool=true,format:Bool=true)-instance-method","html_id":"before_check(v:Check::Validation,h:Hash,required:Bool=true,format:Bool=true)-instance-method","name":"before_check","doc":"Lifecycle method triggered before each call of `.check`.\n\n```\n# Triggered on a static call: `User.check(h)` (with a `Hash` or `JSON::Any`)\ndef self.before_check(v : Check::Validation, h, required : Bool = true, format : Bool = true)\n # Code...\n pp h\nend\n```","summary":"
Lifecycle method triggered before each call of .check.
","abstract":false,"args":[{"name":"v","doc":null,"default_value":"","external_name":"v","restriction":"Check::Validation"},{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"Hash"},{"name":"required","doc":null,"default_value":"true","external_name":"required","restriction":"Bool"},{"name":"format","doc":null,"default_value":"true","external_name":"format","restriction":"Bool"}],"args_string":"(v : Check::Validation, h : Hash, required : Bool = true, format : Bool = true)","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/checkable.cr#L320","def":{"name":"before_check","args":[{"name":"v","doc":null,"default_value":"","external_name":"v","restriction":"Check::Validation"},{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"Hash"},{"name":"required","doc":null,"default_value":"true","external_name":"required","restriction":"Bool"},{"name":"format","doc":null,"default_value":"true","external_name":"format","restriction":"Bool"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":""}},{"id":"check(v:Check::Validation,h:Hash,required:Bool=true,format:Bool=true)-instance-method","html_id":"check(v:Check::Validation,h:Hash,required:Bool=true,format:Bool=true)-instance-method","name":"check","doc":"Checks and clean the `Hash` for its fields corresponding\nto class variables that have a `.check_{{field}}` method.\n\nIt instantiates a `Check::Validation` (if not provided) and calls all methods\nrelated to `.rules` and then methods defined with annotation `Checker`.\n\nLifecycle methods `.before_check` and `.after_check` that are called\nrespectively at the beginning and at the end of the process.\n\n*format* is used to tell cleaners generated by `Check.rules`\nto execute format method if it has been defined.","summary":"
Checks and clean the Hash for its fields corresponding to class variables that have a .check_{{field}} method.
","abstract":false,"args":[{"name":"v","doc":null,"default_value":"","external_name":"v","restriction":"Check::Validation"},{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"Hash"},{"name":"required","doc":null,"default_value":"true","external_name":"required","restriction":"Bool"},{"name":"format","doc":null,"default_value":"true","external_name":"format","restriction":"Bool"}],"args_string":"(v : Check::Validation, h : Hash, required : Bool = true, format : Bool = true)","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/checkable.cr#L361","def":{"name":"check","args":[{"name":"v","doc":null,"default_value":"","external_name":"v","restriction":"Check::Validation"},{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"Hash"},{"name":"required","doc":null,"default_value":"true","external_name":"required","restriction":"Bool"},{"name":"format","doc":null,"default_value":"true","external_name":"format","restriction":"Bool"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"{% if true %}\n {% types = [] of Type %}\n {% fields = [] of String %}\n\n {% for ivar in @type.instance_vars.select do |ivar|\n @type.class.has_method?(\"check_#{ivar}\")\nend %}\n {% types << ivar.type %}\n {% fields << ivar.name %}\n {% end %}\n\n # Instantiate a `Hash` with keys as `String` and values as a union of\n # all types of fields which have a method `.check_{field}`\n cleaned_h = Hash(String, {{ (types.join(\"|\")).id }}).new\n\n # Call lifecycle method before check\n self.before_check v, h, required, format\n\n # Call check methods for fields that are present in *h*\n # and populate `cleaned_h`\n {% for field, i in fields %}\n {% field_name = field.stringify %}\n # if hash has the field or this field MUST be checked when required is `true`\n if h.has_key?({{ field_name }}) || (required && self.validation_required?({{ field_name }}))\n v, value = self.check_{{ field }}(v, h[{{ field_name }}]?, required, format)\n cleaned_h[{{ field_name }}] = value.as({{ types[i] }})\n end\n {% end %}\n\n # Check methods with `Check::Checker` annotation\n {% for method in @type.class.methods.select do |method|\n method.annotation(Checker)\nend %}\n cleaned_h = {{ method.name }} v, h, cleaned_h, required, format\n {% end %}\n\n # Call lifecycle method `.after_check`\n cleaned_h = self.after_check v, h, cleaned_h, required, format\n\n {v, cleaned_h}\n {% end %}"}},{"id":"check(h:Hash,required:Bool=true,format:Bool=true)-instance-method","html_id":"check(h:Hash,required:Bool=true,format:Bool=true)-instance-method","name":"check","doc":"Checks and clean the `Hash` for its fields corresponding\nto class variables that have a `.check_{{field}}` method.\n\nIt instantiates a `Check::Validation` (if not provided) and calls all methods\nrelated to `.rules` and then methods defined with annotation `Checker`.\n\nLifecycle methods `.before_check` and `.after_check` that are called\nrespectively at the beginning and at the end of the process.\n\n*format* is used to tell cleaners generated by `Check.rules`\nto execute format method if it has been defined.","summary":"
Checks and clean the Hash for its fields corresponding to class variables that have a .check_{{field}} method.
","abstract":false,"args":[{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"Hash"},{"name":"required","doc":null,"default_value":"true","external_name":"required","restriction":"Bool"},{"name":"format","doc":null,"default_value":"true","external_name":"format","restriction":"Bool"}],"args_string":"(h : Hash, required : Bool = true, format : Bool = true)","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/checkable.cr#L402","def":{"name":"check","args":[{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"Hash"},{"name":"required","doc":null,"default_value":"true","external_name":"required","restriction":"Bool"},{"name":"format","doc":null,"default_value":"true","external_name":"format","restriction":"Bool"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"v = Check.new_validation\ncheck(v, h, required, format)\n"}},{"id":"h_from_json(json:String|IO)-instance-method","html_id":"h_from_json(json:String|IO)-instance-method","name":"h_from_json","doc":"Returns a `Hash` from a JSON input.\nThe return type is a tuple with a bool as a first argument indicating\nthat the `JSON.parse` has been processed successfully or not and the 2nd\nargument is the *json* Hash.\n\n```\nok, user_h = User.h_from_json(json) # => true, {\"username\" => \"Bob\", \"email\" => \"user@example.com\"}\n```","summary":"
Returns a Hash from a JSON input.
","abstract":false,"args":[{"name":"json","doc":null,"default_value":"","external_name":"json","restriction":"String | IO"}],"args_string":"(json : String | IO)","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/checkable.cr#L305","def":{"name":"h_from_json","args":[{"name":"json","doc":null,"default_value":"","external_name":"json","restriction":"String | IO"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"begin\n return {true, self.to_crystal_h((JSON.parse(json)).as_h)}\nrescue\n return {false, nil}\nend"}},{"id":"map_json_keys:Hash(String,String)-instance-method","html_id":"map_json_keys:Hash(String,String)-instance-method","name":"map_json_keys","doc":"Macro that returns the mapping of the JSON fields","summary":"
Macro that returns the mapping of the JSON fields
","abstract":false,"args":[],"args_string":" : Hash(String, String)","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/checkable.cr#L263","def":{"name":"map_json_keys","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Hash(String, String)","visibility":"Public","body":"map = {} of String => String\n{% if true %}\n {% for ivar in @type.instance_vars %}\n {% ann = ivar.annotation(::JSON::Field) %}\n {% if ann && ann[:ignore] %}{% else %}\n map[{{ ((ann && ann[:key]) || ivar).id.stringify }}] = {{ ivar.id.stringify }}\n {% end %}\n {% end %}\n {% end %}\nmap\n"}},{"id":"to_crystal_h(h:Hash):Hash-instance-method","html_id":"to_crystal_h(h:Hash):Hash-instance-method","name":"to_crystal_h","doc":"Returns a new `Hash` with all JSON keys converted to Crystal keys.","summary":"
Returns a new Hash with all JSON keys converted to Crystal keys.
","abstract":false,"args":[{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"Hash"}],"args_string":"(h : Hash) : Hash","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/checkable.cr#L278","def":{"name":"to_crystal_h","args":[{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"Hash"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Hash","visibility":"Public","body":"cr_keys = map_json_keys\nh.transform_keys do |cr_k|\n cr_keys[cr_k]? || cr_k\nend\n"}},{"id":"to_json_h(h:Hash):Hash-instance-method","html_id":"to_json_h(h:Hash):Hash-instance-method","name":"to_json_h","doc":"Returns a new `Hash` with all Crystal keys converted to JSON keys.","summary":"
Returns a new Hash with all Crystal keys converted to JSON keys.
","abstract":false,"args":[{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"Hash"}],"args_string":"(h : Hash) : Hash","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/checkable.cr#L288","def":{"name":"to_json_h","args":[{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"Hash"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Hash","visibility":"Public","body":"cr_keys = map_json_keys\nh.transform_keys do |json_k|\n cr_keys.key_for?(json_k || json_k)\nend\n"}}],"macros":[],"types":[]},{"html_id":"validator/Check/Checker","path":"Check/Checker.html","kind":"annotation","full_name":"Check::Checker","name":"Checker","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/checkable.cr","line_number":28,"url":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/checkable.cr#L28"}],"repository_name":"validator","program":false,"enum":false,"alias":false,"aliased":"","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"validator/Check","kind":"module","full_name":"Check","name":"Check"},"doc":"Declare a method as a checker.\n\n```\n# Triggered by the instance.\n@[Check::Checker]\ndef custom_checker(v : Check::Validation, required : Bool, format : Bool)\n puts \"custom checker triggered on instance\"\nend\n\n# Triggered statically.\n@[Check::Checker]\ndef self.custom_checker(v : Check::Validation, h, cleaned_h, required : Bool, format : Bool)\n puts \"custom checker triggered statically\"\n cleaned_h\nend\n```\n\nWhen `.check` and `#check` are called, the custom checkers are triggered respectively.","summary":"
Declare a method as a checker.
","class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[]},{"html_id":"validator/Check/Errors","path":"Check/Errors.html","kind":"alias","full_name":"Check::Errors","name":"Errors","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/check.cr","line_number":19,"url":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/check.cr#L19"}],"repository_name":"validator","program":false,"enum":false,"alias":true,"aliased":"Hash(String | Symbol, Array(String))","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"validator/Check","kind":"module","full_name":"Check","name":"Check"},"doc":"Validation errors.\nIt's a `Hash` used as a container of errors, in order to handle them easily.\n\n```\nv = Check.new_validation\npp v.errors\n```","summary":"
Validation errors.
","class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[]},{"html_id":"validator/Check/Validation","path":"Check/Validation.html","kind":"class","full_name":"Check::Validation","name":"Validation","abstract":false,"superclass":{"html_id":"validator/Reference","kind":"class","full_name":"Reference","name":"Reference"},"ancestors":[{"html_id":"validator/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"validator/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"src/check.cr","line_number":139,"url":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/check.cr#L139"}],"repository_name":"validator","program":false,"enum":false,"alias":false,"aliased":"","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"validator/Check","kind":"module","full_name":"Check","name":"Check"},"doc":"Combines a series of checks into one validation instance,\nwith a customized error message for each case.\n\nA `Validation` instance provides the means to write sequential checks,\nfine-tune each micro-validation with their own rules and custom error message,\nthe possibility to retrieve all error messages, etc.\n\n> `Validation` is also used with `Check.rules` and `Check.checkable`\nthat provide a powerful and productive system of validation rules\nwhich makes data cleaning and data validation in Crystal very easy.\nWith self-generated granular methods for cleaning and checking data.\n\n\nTo use the checker (`check`) includes in the `Validation` class:\n\n```\nrequire \"validator/check\"\n\n# Validates the *user* data received in the HTTP controller or other.\ndef validate_user(user : Hash) : Check::Validation\n v = Check.new_validation\n\n # -- email\n\n # Hash key can be a String or a Symbol\n v.check :email, \"The email is required.\", is :presence?, :email, user\n\n v.check \"email\", \"The email is required.\", is :presence?, \"email\", user\n v.check \"email\", \"#{user[\"email\"]} is an invalid email.\", is :email?, user[\"email\"]\n\n # -- username\n\n v.check \"username\", \"The username is required.\", is :presence?, \"username\", user\n\n v.check(\n \"username\",\n \"The username must contain at least 2 characters.\",\n is :min?, user[\"username\"], 2\n )\n\n v.check(\n \"username\",\n \"The username must contain a maximum of 20 characters.\",\n is :max?, user[\"username\"], 20\n )\nend\n\nv = validate_user user\n\npp v.valid? # => true (or false)\n\n# Inverse of v.valid?\nif v.errors.empty?\n return \"no error\"\nend\n\n# display all the errors (if any)\npp v.errors\n\n# It's a Hash of Array\nerrors = v.errors\n\nputs errors.size\nputs errors.first_value\n\nerrors.each do |key, messages|\n puts key # => \"username\"\n puts messages # => [\"The username is required.\", \"etc...\"]\nend\n```\n\n3 methods [#check](https://nicolab.github.io/crystal-validator/Check/Validation.html#instance-method-summary):\n\n```\n# check(key : Symbol | String, valid : Bool)\n# Using default standard error message\nv.check(\n \"username\",\n is(:min?, user[\"username\"], 2)\n)\n\n# check(key : Symbol | String, message : String, valid : Bool)\n# Using custom error message\nv.check(\n \"username\",\n \"The username must contain at least 2 characters.\",\n is(:min?, user[\"username\"], 2)\n)\n\n# check(key : Symbol | String, valid : Bool, message : String)\n# Using custom error message\nv.check(\n \"username\",\n is(:min?, user[\"username\"], 2),\n \"The username must contain at least 2 characters.\"\n)\n```\n\n`Check` is a simple and lightweight wrapper.\n`Check::Validation` is agnostic of the checked data,\nof the context (model, controller, CSV file, HTTP data, socket data, JSON, etc).\n\n> Use case example:\n Before saving to the database or process user data for a particular task,\n the custom error messages can be used for the end user response.\n\nBut a `Validation` instance can be used just to store validation errors:\n\n```\nv = Check.new_validation\nv.add_error(\"foo\", \"foo error!\")\npp v.errors # => {\"foo\" => [\"foo error!\"]}\n```\n\n> See also `Check.rules` and `Check.checkable`.\n\nLet your imagination run wild to add your logic around it.\n","summary":"
Combines a series of checks into one validation instance, with a customized error message for each case.
","class_methods":[],"constructors":[{"id":"new(errors:Errors)-class-method","html_id":"new(errors:Errors)-class-method","name":"new","doc":"Initializes a validation using an existing *errors* `Hash` (`Check::Errors`).\n\n```\nv = Check::Validation.new\n```\n\nSame as:\n\n```\nv = Check.new_validation\n```","summary":"
Initializes a validation using an existing errorsHash (Check::Errors).
","abstract":false,"args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"Symbol | String"},{"name":"message","doc":null,"default_value":"","external_name":"message","restriction":"String"}],"args_string":"(key : Symbol | String, message : String) : Validation","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/check.cr#L191","def":{"name":"add_error","args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"Symbol | String"},{"name":"message","doc":null,"default_value":"","external_name":"message","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Validation","visibility":"Public","body":"if message.blank?\n message = \"\\\"#{key}\\\" is not valid.\"\nend\nif @errors.has_key?(key)\nelse\n @errors[key] = Array(String).new\nend\n@errors[key] << message\nself\n"}},{"id":"add_error(key:Symbol|String):Validation-instance-method","html_id":"add_error(key:Symbol|String):Validation-instance-method","name":"add_error","doc":"Add a validation error.\n\n> By default a standard message is used.\n\n```\nv = Check.new_validation\nv.add_error(:foo)\npp v.errors # => {:foo => [\"\\\"foo\\\" is not valid.\"]}\n```\n\nSee also: `Errors`","summary":"
Add a validation error.
","abstract":false,"args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"Symbol | String"}],"args_string":"(key : Symbol | String) : Validation","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/check.cr#L211","def":{"name":"add_error","args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"Symbol | String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Validation","visibility":"Public","body":"add_error(key, \"\")\nself\n"}},{"id":"check(key:Symbol|String,message:String,valid:Bool):Validation-instance-method","html_id":"check(key:Symbol|String,message:String,valid:Bool):Validation-instance-method","name":"check","doc":"Checks a validation, often used in sequence.\n\nIf *valid* is `false`, the error *message* is added in the `errors`.\nNothing if *valid* is `true`.\n\n```\nv = Check.new_validation\n\n# -- email\n\nv.check :email, \"The email is required.\", is :presence?, :email, user\nv.check :email, \"#{user[:email]} is an invalid email.\", is :email?, user[:email]?\n\n# -- username\n\nv.check :username, \"The username is required.\", is :presence?, :username, user\n\nv.check(\n :username,\n \"The username must contain at least 2 characters.\",\n is :min?, user[:username]?, 2\n)\n\nv.check(\n :username,\n \"The username must contain a maximum of 20 characters.\",\n is :max?, user[:username]?, 20\n)\n\n# Print all errors\npp v.errors\n```","summary":"
Checks a validation, often used in sequence.
","abstract":false,"args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"Symbol | String"},{"name":"message","doc":null,"default_value":"","external_name":"message","restriction":"String"},{"name":"valid","doc":null,"default_value":"","external_name":"valid","restriction":"Bool"}],"args_string":"(key : Symbol | String, message : String, valid : Bool) : Validation","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/check.cr#L259","def":{"name":"check","args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"Symbol | String"},{"name":"message","doc":null,"default_value":"","external_name":"message","restriction":"String"},{"name":"valid","doc":null,"default_value":"","external_name":"valid","restriction":"Bool"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Validation","visibility":"Public","body":"if valid\nelse\n add_error(key, message)\nend\nself\n"}},{"id":"check(key:Symbol|String,valid:Bool,message:String):Validation-instance-method","html_id":"check(key:Symbol|String,valid:Bool,message:String):Validation-instance-method","name":"check","doc":"Checks a validation, often used in sequence.\n\nIf *valid* is `false`, the error *message* is added in the `errors`.\nNothing if *valid* is `true`.\n\n```\nv = Check.new_validation\n\n# -- email\n\nv.check(:email, is(:presence?, :email, user), \"The email is required.\")\nv.check(:email, is(:email?, user[:email]?), \"#{user[:email]} is an invalid email.\")\n\n# -- username\n\nv.check(:username, is(:presence?, :username, user), \"The username is required.\")\n\nv.check(\n :username,\n is :min?, user[:username]?, 2,\n \"The username must contain at least 2 characters.\"\n)\n\nv.check(\n :username,\n is :max?, user[:username]?, 20,\n \"The username must contain a maximum of 20 characters.\"\n)\n\n# Print all errors\npp v.errors\n```","summary":"
Checks a validation, often used in sequence.
","abstract":false,"args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"Symbol | String"},{"name":"valid","doc":null,"default_value":"","external_name":"valid","restriction":"Bool"},{"name":"message","doc":null,"default_value":"","external_name":"message","restriction":"String"}],"args_string":"(key : Symbol | String, valid : Bool, message : String) : Validation","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/check.cr#L296","def":{"name":"check","args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"Symbol | String"},{"name":"valid","doc":null,"default_value":"","external_name":"valid","restriction":"Bool"},{"name":"message","doc":null,"default_value":"","external_name":"message","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Validation","visibility":"Public","body":"if valid\nelse\n add_error(key, message)\nend\nself\n"}},{"id":"check(key:Symbol|String,valid:Bool):Validation-instance-method","html_id":"check(key:Symbol|String,valid:Bool):Validation-instance-method","name":"check","doc":"Checks a validation, often used in sequence.\n\nIf *valid* is `false`, an error message is added in the `errors`.\nNothing if *valid* is `true`.\n\n> Unlike other `check` methods, with this one a default standard message is used.\n\n```\nv = Check.new_validation\n\nv.check(\"email\", Valid.presence?(\"email\", user))\nv.check(\"email\", Valid.email?(user[\"email\"]?))\n\n# Print all errors\npp v.errors\n```","summary":"
","abstract":false,"args":[],"args_string":" : Errors","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/check.cr#L178","def":{"name":"errors","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Errors","visibility":"Public","body":"@errors"}},{"id":"valid?-instance-method","html_id":"valid?-instance-method","name":"valid?","doc":"Returns `true` if there is no error, `false` if there is one or more errors.\n\n```\npp v.errors if !v.valid?\n# or with another flavor ;-)\npp v.errors unless v.valid?\n```","summary":"
Returns true if there is no error, false if there is one or more errors.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/check.cr#L223","def":{"name":"valid?","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@errors.empty?"}}],"macros":[],"types":[]}]},{"html_id":"validator/Valid","path":"Valid.html","kind":"alias","full_name":"Valid","name":"Valid","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/validator.cr","line_number":124,"url":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validator.cr#L124"}],"repository_name":"validator","program":false,"enum":false,"alias":true,"aliased":"Validator","const":false,"constants":[{"id":"VERSION","name":"VERSION","value":"{{ (`shards version \\\"/media/data/lab/dev/work/projects/nicolab/crystal/crystal-validator/src\\\"`).chomp.stringify.downcase }}","doc":null,"summary":null}],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":null,"doc":"Alias of `Validator`","summary":"
","class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[]},{"html_id":"validator/Validator","path":"Validator.html","kind":"module","full_name":"Validator","name":"Validator","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/validator.cr","line_number":116,"url":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validator.cr#L116"},{"filename":"src/validators/alpha_num.cr","line_number":8,"url":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/alpha_num.cr#L8"},{"filename":"src/validators/case_sensitive.cr","line_number":8,"url":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/case_sensitive.cr#L8"},{"filename":"src/validators/comparisons.cr","line_number":8,"url":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/comparisons.cr#L8"},{"filename":"src/validators/format.cr","line_number":8,"url":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/format.cr#L8"},{"filename":"src/validators/geo.cr","line_number":8,"url":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/geo.cr#L8"},{"filename":"src/validators/presence.cr","line_number":8,"url":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/presence.cr#L8"},{"filename":"src/validators/uri.cr","line_number":8,"url":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/uri.cr#L8"}],"repository_name":"validator","program":false,"enum":false,"alias":false,"aliased":"","const":false,"constants":[{"id":"VERSION","name":"VERSION","value":"{{ (`shards version \\\"/media/data/lab/dev/work/projects/nicolab/crystal/crystal-validator/src\\\"`).chomp.stringify.downcase }}","doc":null,"summary":null}],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":null,"doc":"∠(・.-)―〉 →◎ `validator` is a [Crystal](https://crystal-lang.org) data validation module.\nVery simple and efficient, all validations return `true` or `false`.\n\nAlso [validator/check](https://nicolab.github.io/crystal-validator/Check.html)\n(not exposed by default) provides error message handling intended for the end user.\n\nThere are 2 main ways to use *validator*:\n\n- As a simple validator to check rules (eg: email, url, min, max, presence, in, ...) which return a boolean.\n- As a more advanced validation system which will check a series of rules\n and returns all validation errors encountered with custom or standard messages.\n\nBy default the **validator** module expose only `Validator` and `Valid` (alias) in the scope:\n\n```\nrequire \"validator\"\n\nValid.email? \"contact@example.org\" # => true\nValid.url? \"https://github.com/Nicolab/crystal-validator\" # => true\nValid.my_validator? \"value to validate\", \"hello\", 42 # => true\n```\n\nAn (optional) expressive validation flavor, `is` available as an alternative. \\\nNot exposed by default, it must be imported:\n\n```\nrequire \"validator/is\"\n\nis :email?, \"contact@example.org\" # => true\nis :url?, \"https://github.com/Nicolab/crystal-validator\" # => true\nis :my_validator?, \"value to validate\", \"hello\", 42 # => true\n\n# raises an error if the email is not valid\nis! :email?, \"contact@@example..org\" # => Validator::Error\n```\n\n`is` is a macro, no overhead during the runtime 🚀\n By the nature of the macros, you can't pass the *validator* name dynamically\n with a variable like that `is(validator_name, \"my value to validate\", arg)`.\n But of course you can pass arguments with variables `is(:validator_name?, arg1, arg2)`.\n\n\n## Check\n\nMake a series of checks, with a customized error message for each case.\n\n```crystal\nrequire \"validator/check\"\n\ncheck = Check.new\n\ncheck(\"email\", \"The email is required.\", is :absence?, \"email\", user)\n```\n## Custom validator\n\nJust add your own method to register a custom *validator* or to overload an existing *validator*.\n\n```crystal\nmodule Validator\n # My custom validator\n def self.my_validator?(value, arg : String, another_arg : Int32) : Bool\n # write here the logic of your validator...\n return true\n end\nend\n\n# Call it\nputs Valid.my_validator?(\"value to validate\", \"hello\", 42) # => true\n\n# or with the `is` flavor\nputs is :my_validator?, \"value to validate\", \"hello\", 42 # => true\n```\n\n`Check` is a simple and lightweight wrapper, let your imagination run wild to add your logic around it.\n\nUsing the custom validator with the validation rules:\n\n```\nrequire \"validator/check\"\n\nclass Article\n # Mixin\n Check.checkable\n\n property title : String\n property content : String\n\n Check.rules(\n content: {\n # Now the custom validator is available\n check: {\n my_validator: {\"My validator error message\"},\n between: {\"The article content must be between 10 and 20 000 characters\", 10, 20_000},\n # ...\n },\n },\n )\nend\n\n# Triggered with all data\nv, article = Article.check(input_data)\n\n# Triggered with one value\nv, content = Article.check_content(input_data[\"content\"]?)\n```","summary":"
∠(・.-)―〉 →◎ validator is a Crystal data validation module.
","class_methods":[{"id":"absence?(key:String|Symbol,list:NamedTuple):Bool-class-method","html_id":"absence?(key:String|Symbol,list:NamedTuple):Bool-class-method","name":"absence?","doc":"Validates the absence of the value.\n- See also `#not_in?`.\n- See also `#empty?`.","summary":"
Validates the absence of the value.
","abstract":false,"args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"String | Symbol"},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"NamedTuple"}],"args_string":"(key : String | Symbol, list : NamedTuple) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/presence.cr#L47","def":{"name":"absence?","args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"String | Symbol"},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"NamedTuple"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"self.empty?(list[key]?)"}},{"id":"absence?(key:String|Symbol|Number,list:Hash):Bool-class-method","html_id":"absence?(key:String|Symbol|Number,list:Hash):Bool-class-method","name":"absence?","doc":"Validates the absence of the value.\n- See also `#not_in?`.\n- See also `#empty?`.","summary":"
Validates the absence of the value.
","abstract":false,"args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"String | Symbol | Number"},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Hash"}],"args_string":"(key : String | Symbol | Number, list : Hash) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/presence.cr#L42","def":{"name":"absence?","args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"String | Symbol | Number"},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Hash"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"self.empty?(list[key]?)"}},{"id":"accepted?(value:String):Bool-class-method","html_id":"accepted?(value:String):Bool-class-method","name":"accepted?","doc":"Validates that the *value* `String` is the representation of an acceptance.\n> One of: \"yes\", \"y\", \"on\", \"o\", \"ok\", \"1\", \"true\"\n- See also `#refused?`.","summary":"
Validates that the valueString is the representation of an acceptance.
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/presence.cr#L180","def":{"name":"accepted?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"self.in?(value.downcase, [\"yes\", \"y\", \"on\", \"o\", \"ok\", \"1\", \"true\"])"}},{"id":"accepted?(value):Bool-class-method","html_id":"accepted?(value):Bool-class-method","name":"accepted?","doc":"Validates that the *value* is the representation of an acceptance.\n> One of: \"yes\", \"y\", \"on\", \"o\", \"ok\", \"1\", \"true\"\n\n*value* must implements *#to_s* method.\n- See also `#refused?`.","summary":"
Validates that the value is the representation of an acceptance.
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"args_string":"(value) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/presence.cr#L189","def":{"name":"accepted?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"self.accepted?(value.to_s)"}},{"id":"ascii_only?(value:String):Bool-class-method","html_id":"ascii_only?(value:String):Bool-class-method","name":"ascii_only?","doc":"Validates that the *value* `String`\nis comprised in its entirety by ASCII characters.","summary":"
Validates that the valueString is comprised in its entirety by ASCII characters.
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/format.cr#L41","def":{"name":"ascii_only?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value.ascii_only?"}},{"id":"ascii_only?(values:Array(String)):Bool-class-method","html_id":"ascii_only?(values:Array(String)):Bool-class-method","name":"ascii_only?","doc":"Validates that all the `String` in the *values* `Array`\nare comprised in their entirety by ASCII characters.","summary":"
Validates that all the String in the valuesArray are comprised in their entirety by ASCII characters.
","abstract":false,"args":[{"name":"values","doc":null,"default_value":"","external_name":"values","restriction":"Array(String)"}],"args_string":"(values : Array(String)) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/format.cr#L47","def":{"name":"ascii_only?","args":[{"name":"values","doc":null,"default_value":"","external_name":"values","restriction":"Array(String)"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"size = value.size\nwhile size\n size = size - 1\n if value.ascii_only?(values[i])\n else\n return false\n end\nend\ntrue\n"}},{"id":"base64?(value:String):Bool-class-method","html_id":"base64?(value:String):Bool-class-method","name":"base64?","doc":"Validates that the *value* has the format *base64*.","summary":"
Validates that the value has the format base64.
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/format.cr#L87","def":{"name":"base64?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"if (value.match(@@rx_base64)) && ((value.size % 4) === 0)\n return true\nend\nfalse\n"}},{"id":"between?(value,min,max):Bool-class-method","html_id":"between?(value,min,max):Bool-class-method","name":"between?","doc":"Validates that the *value* is between (inclusive) *min* and *max*.","summary":"
Validates that the value is between (inclusive) min and max.
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"min","doc":null,"default_value":"","external_name":"min","restriction":""},{"name":"max","doc":null,"default_value":"","external_name":"max","restriction":""}],"args_string":"(value, min, max) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/comparisons.cr#L87","def":{"name":"between?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"min","doc":null,"default_value":"","external_name":"min","restriction":""},{"name":"max","doc":null,"default_value":"","external_name":"max","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value >= min && value <= max"}},{"id":"between?(value:String|Array,min:Int,max:Int):Bool-class-method","html_id":"between?(value:String|Array,min:Int,max:Int):Bool-class-method","name":"between?","doc":"Validates that the size of the *value* (`String` or `Array`) is between\n(inclusive) *min* and *max*.\n- See also `#size?`.","summary":"
Validates that the size of the value (String or Array) is between (inclusive) min and max.
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String | Array"},{"name":"min","doc":null,"default_value":"","external_name":"min","restriction":"Int"},{"name":"max","doc":null,"default_value":"","external_name":"max","restriction":"Int"}],"args_string":"(value : String | Array, min : Int, max : Int) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/comparisons.cr#L94","def":{"name":"between?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String | Array"},{"name":"min","doc":null,"default_value":"","external_name":"min","restriction":"Int"},{"name":"max","doc":null,"default_value":"","external_name":"max","restriction":"Int"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"size = value.size\nsize >= min && size <= max\n"}},{"id":"domain?(value:String):Bool-class-method","html_id":"domain?(value:String):Bool-class-method","name":"domain?","doc":null,"summary":null,"abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/uri.cr#L23","def":{"name":"domain?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"size = value.size\nif size > 75 || size < 4\n return false\nend\nif value.includes?(\"..\")\n return false\nend\nif m = value.match(@@rx_domain)\nelse\n return false\nend\next_size = m[\"ext\"].size\nif ext_size < 2 || ext_size > 12\n return false\nend\ntrue\n"}},{"id":"email?(value:String):Bool-class-method","html_id":"email?(value:String):Bool-class-method","name":"email?","doc":"Validates that the *value* is an email.\nThis method is stricter than the standard allows.\nIt is subjectively based on the common addresses\nof organisations (@enterprise.ltd, ...)\nand mail services suck as Gmail, Hotmail, Yahoo !, ...","summary":"
Validates that the value is an email.
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/uri.cr#L158","def":{"name":"email?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"size = value.size\nif size > 60 || size < 7\n return false\nend\nif value.includes?(\"..\")\n return false\nend\nif value.includes?(\"--\")\n return false\nend\nif value.includes?(\"___\")\n return false\nend\nif m = value.match(@@rx_email)\nelse\n return false\nend\nself.domain?(\"#{m[\"name\"]}.#{m[\"ext\"]}\")\n"}},{"id":"empty?(value):Bool-class-method","html_id":"empty?(value):Bool-class-method","name":"empty?","doc":"Validates that the *value* is empty.\n- See also `#absence?`.\n- See also `#not_in?`.","summary":"
Validates that the value is empty.
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"args_string":"(value) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/presence.cr#L58","def":{"name":"empty?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"case value\nwhen .nil?\n true\nwhen .is_a?(String)\n value.presence.nil?\nwhen .is_a?(Number)\n value == 0\nwhen .responds_to?(:size)\n value.size == 0\nelse\n false\nend"}},{"id":"ends?(value:String,search:String):Bool-class-method","html_id":"ends?(value:String,search:String):Bool-class-method","name":"ends?","doc":"Validates that the `String` *value* ends with *search*.\n- See also `#starts?`.\n- See also `#match?`.\n- See also `#in?`.","summary":"
Validates that the Stringvalue ends with search.
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"search","doc":null,"default_value":"","external_name":"search","restriction":"String"}],"args_string":"(value : String, search : String) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/presence.cr#L243","def":{"name":"ends?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"search","doc":null,"default_value":"","external_name":"search","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value.ends_with?(search)"}},{"id":"ends?(value:String,search:Char):Bool-class-method","html_id":"ends?(value:String,search:Char):Bool-class-method","name":"ends?","doc":"Validates that the `String` *value* ends with *search*.\n- See also `#starts?`.\n- See also `#match?`.\n- See also `#in?`.","summary":"
Validates that the Stringvalue ends with search.
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"search","doc":null,"default_value":"","external_name":"search","restriction":"Char"}],"args_string":"(value : String, search : Char) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/presence.cr#L248","def":{"name":"ends?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"search","doc":null,"default_value":"","external_name":"search","restriction":"Char"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value.ends_with?(search)"}},{"id":"ends?(value:String,search:Regex):Bool-class-method","html_id":"ends?(value:String,search:Regex):Bool-class-method","name":"ends?","doc":"Validates that the `String` *value* ends with *search*.\n- See also `#starts?`.\n- See also `#match?`.\n- See also `#in?`.","summary":"
Validates that the Stringvalue ends with search.
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"search","doc":null,"default_value":"","external_name":"search","restriction":"Regex"}],"args_string":"(value : String, search : Regex) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/presence.cr#L253","def":{"name":"ends?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"search","doc":null,"default_value":"","external_name":"search","restriction":"Regex"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value.ends_with?(search)"}},{"id":"eq?(value,another_value):Bool-class-method","html_id":"eq?(value,another_value):Bool-class-method","name":"eq?","doc":"Validates that the *value* is equal to *another_value*.","summary":"
Validates that the value is equal to another_value.
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"another_value","doc":null,"default_value":"","external_name":"another_value","restriction":""}],"args_string":"(value, another_value) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/comparisons.cr#L10","def":{"name":"eq?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"another_value","doc":null,"default_value":"","external_name":"another_value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value == another_value"}},{"id":"gt?(value,another_value):Bool-class-method","html_id":"gt?(value,another_value):Bool-class-method","name":"gt?","doc":"Validates that the *value* is greater than *another_value*.","summary":"
Validates that the value is greater than another_value.
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"another_value","doc":null,"default_value":"","external_name":"another_value","restriction":""}],"args_string":"(value, another_value) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/comparisons.cr#L15","def":{"name":"gt?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"another_value","doc":null,"default_value":"","external_name":"another_value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value > another_value"}},{"id":"gt?(value:String|Array,limit:Int):Bool-class-method","html_id":"gt?(value:String|Array,limit:Int):Bool-class-method","name":"gt?","doc":"Validates that the size of the *value* (`String` or `Array`)\nis greater than *limit* number.","summary":"
Validates that the size of the value (String or Array) is greater than limit number.
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String | Array"},{"name":"limit","doc":null,"default_value":"","external_name":"limit","restriction":"Int"}],"args_string":"(value : String | Array, limit : Int) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/comparisons.cr#L21","def":{"name":"gt?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String | Array"},{"name":"limit","doc":null,"default_value":"","external_name":"limit","restriction":"Int"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value.size > limit"}},{"id":"gte?(value,another_value):Bool-class-method","html_id":"gte?(value,another_value):Bool-class-method","name":"gte?","doc":"Validates that the *value* is equal to or greater than *another_value*.\n> Similar to `#min`.","summary":"
Validates that the value is equal to or greater than another_value.
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"another_value","doc":null,"default_value":"","external_name":"another_value","restriction":""}],"args_string":"(value, another_value) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/comparisons.cr#L27","def":{"name":"gte?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"another_value","doc":null,"default_value":"","external_name":"another_value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value >= another_value"}},{"id":"gte?(value:String|Array,min:Int):Bool-class-method","html_id":"gte?(value:String|Array,min:Int):Bool-class-method","name":"gte?","doc":"Validates that the size of the *value* (`String` or `Array`)\nis greater than *min* number.\n> Similar to `#min`.","summary":"
Validates that the size of the value (String or Array) is greater than min number.
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String | Array"},{"name":"min","doc":null,"default_value":"","external_name":"min","restriction":"Int"}],"args_string":"(value : String | Array, min : Int) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/comparisons.cr#L34","def":{"name":"gte?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String | Array"},{"name":"min","doc":null,"default_value":"","external_name":"min","restriction":"Int"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value.size >= min"}},{"id":"hex?(value:String):Bool-class-method","html_id":"hex?(value:String):Bool-class-method","name":"hex?","doc":"Validates that the `String` *value* does denote\na representation of a hexadecimal string.","summary":"
Validates that the Stringvalue does denote a representation of a hexadecimal string.
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/format.cr#L112","def":{"name":"hex?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!value.match(@@rx_hex).nil?"}},{"id":"hex?(value:Bytes):Bool-class-method","html_id":"hex?(value:Bytes):Bool-class-method","name":"hex?","doc":"Validates that the `Bytes` *value* does denote\na representation of a hexadecimal slice of Bytes.","summary":"
Validates that the Bytesvalue does denote a representation of a hexadecimal slice of Bytes.
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"Bytes"}],"args_string":"(value : Bytes) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/format.cr#L118","def":{"name":"hex?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"Bytes"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!(String.new(value)).match(@@rx_hex).nil?"}},{"id":"hex_color?(value:String):Bool-class-method","html_id":"hex_color?(value:String):Bool-class-method","name":"hex_color?","doc":"Validates that the `String` *value* does denote\na representation of a hexadecimal color.\n\n```\nValid.hex_color? \"#fff\" => true\nValid.hex_color? \"#ffffff\" => true\n```","summary":"
Validates that the Stringvalue does denote a representation of a hexadecimal color.
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/format.cr#L129","def":{"name":"hex_color?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!value.match(@@rx_hex_color).nil?"}},{"id":"in?(value,list:Array):Bool-class-method","html_id":"in?(value,list:Array):Bool-class-method","name":"in?","doc":"Validates that the (*list*) contains the *value*.\n- See also `#presence?`.\n- See also `#not_in?`.\n- See also `#not_empty?`.","summary":"
Validates that the (list) contains the value.
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Array"}],"args_string":"(value, list : Array) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/presence.cr#L109","def":{"name":"in?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Array"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"list.includes?(value)"}},{"id":"in?(value:String,str:String):Bool-class-method","html_id":"in?(value:String,str:String):Bool-class-method","name":"in?","doc":"Validates that the (*str*) `String` contains the *value*.\n- See also `#presence?`.\n- See also `#not_in?`.\n- See also `#not_empty?`.","summary":"
Validates that the (str) String contains the value.
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"str","doc":null,"default_value":"","external_name":"str","restriction":"String"}],"args_string":"(value : String, str : String) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/presence.cr#L101","def":{"name":"in?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"str","doc":null,"default_value":"","external_name":"str","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"str.includes?(value)"}},{"id":"in?(key:Symbol|String,list:Hash):Bool-class-method","html_id":"in?(key:Symbol|String,list:Hash):Bool-class-method","name":"in?","doc":"Validates that the (*list*) contains the *value*.\n- See also `#presence?`.\n- See also `#not_in?`.\n- See also `#not_empty?`.","summary":"
Validates that the (list) contains the value.
","abstract":false,"args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"Symbol | String"},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Hash"}],"args_string":"(key : Symbol | String, list : Hash) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/presence.cr#L129","def":{"name":"in?","args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"Symbol | String"},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Hash"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"list.has_key?(key)"}},{"id":"in?(key:Symbol|String,list:NamedTuple):Bool-class-method","html_id":"in?(key:Symbol|String,list:NamedTuple):Bool-class-method","name":"in?","doc":"Validates that the (*list*) contains the *value*.\n- See also `#presence?`.\n- See also `#not_in?`.\n- See also `#not_empty?`.","summary":"
Validates that the (list) contains the value.
","abstract":false,"args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"Symbol | String"},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"NamedTuple"}],"args_string":"(key : Symbol | String, list : NamedTuple) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/presence.cr#L124","def":{"name":"in?","args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"Symbol | String"},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"NamedTuple"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"list.has_key?(key)"}},{"id":"in?(value,list:Range):Bool-class-method","html_id":"in?(value,list:Range):Bool-class-method","name":"in?","doc":"Validates that the (*list*) contains the *value*.\n- See also `#presence?`.\n- See also `#not_in?`.\n- See also `#not_empty?`.","summary":"
Validates that the (list) contains the value.
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Range"}],"args_string":"(value, list : Range) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/presence.cr#L119","def":{"name":"in?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Range"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"list.includes?(value)"}},{"id":"in?(value,list:Tuple):Bool-class-method","html_id":"in?(value,list:Tuple):Bool-class-method","name":"in?","doc":"Validates that the (*list*) contains the *value*.\n- See also `#presence?`.\n- See also `#not_in?`.\n- See also `#not_empty?`.","summary":"
Validates that the (list) contains the value.
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Tuple"}],"args_string":"(value, list : Tuple) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/presence.cr#L114","def":{"name":"in?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Tuple"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"list.includes?(value)"}},{"id":"ip?(value:String):Bool-class-method","html_id":"ip?(value:String):Bool-class-method","name":"ip?","doc":"Validates that the *value* is an IP (IPv4 or IPv6).","summary":"
Validates that the value is an IP (IPv4 or IPv6).
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/uri.cr#L77","def":{"name":"ip?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"(self.ipv4?(value)) || (self.ipv6?(value))"}},{"id":"ipv4?(value:String):Bool-class-method","html_id":"ipv4?(value:String):Bool-class-method","name":"ipv4?","doc":"Validates that the *value* is an IPv4.","summary":"
Validates that the value is an IPv4.
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/uri.cr#L82","def":{"name":"ipv4?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!value.match(@@rx_ipv4).nil?"}},{"id":"ipv6?(value:String):Bool-class-method","html_id":"ipv6?(value:String):Bool-class-method","name":"ipv6?","doc":"Validates that the *value* is an IPv6.","summary":"
Validates that the value is an IPv6.
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/uri.cr#L87","def":{"name":"ipv6?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"addr_and_zone = [value]\nif value.includes?('%')\n addr_and_zone = value.split('%')\n if addr_and_zone.size == 2\n else\n return false\n end\n if addr_and_zone[0].includes?(':')\n else\n return false\n end\n if addr_and_zone[1] == \"\"\n return false\n end\nend\nblocks = addr_and_zone[0].split(':')\nfound_omission_block = false\nfound_ipv4_transition_block = self.ipv4?(blocks[blocks.size - 1])\nexpected_number_of_blocks = found_ipv4_transition_block ? 7 : 8\nif blocks.size > expected_number_of_blocks\n return false\nend\nif value == \"::\"\n return true\nend\nif value[0...2] == \"::\"\n blocks.shift(2)\n found_omission_block = true\nelse\n if value[(value.size - 2)..] == \"::\"\n blocks.pop(2)\n found_omission_block = true\n end\nend\ni = 0\nwhile i < blocks.size\n if ((blocks[i] === \"\") && i > 0) && i < (blocks.size - 1)\n if found_omission_block\n return false\n end\n found_omission_block = true\n else\n if (!(found_ipv4_transition_block && (i == (blocks.size - 1)))) && blocks[i].match(@@rx_ipv6_block).nil?\n return false\n end\n end\n i = i + 1\nend\nif found_omission_block\n return blocks.size >= 1\nend\nblocks.size == expected_number_of_blocks\n"}},{"id":"json?(value:String,strict:Bool=true):Bool-class-method","html_id":"json?(value:String,strict:Bool=true):Bool-class-method","name":"json?","doc":"Validates that the *value* represents a JSON string.\n*strict* to `true` (default) to try to parse the JSON,\nreturns `false` if the parsing fails.\nIf *strict* is `false`, only the first char and the last char are checked.","summary":"
Validates that the value represents a JSON string.
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"strict","doc":null,"default_value":"true","external_name":"strict","restriction":"Bool"}],"args_string":"(value : String, strict : Bool = true) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/format.cr#L64","def":{"name":"json?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"strict","doc":null,"default_value":"true","external_name":"strict","restriction":"Bool"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"if strict\n begin\n JSON.parse(value)\n rescue err\n return false\n else\n return true\n end\nend\n((self.starts?(value, \"{\")) && (self.ends?(value, \"}\"))) || ((self.starts?(value, \"[\")) && (self.ends?(value, \"]\")))\n"}},{"id":"jwt?(value:String):Bool-class-method","html_id":"jwt?(value:String):Bool-class-method","name":"jwt?","doc":"Validates that the *value* is a *JSON Web Token*.","summary":"
Validates that the value is a JSON Web Token.
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/format.cr#L95","def":{"name":"jwt?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!value.match(@@rx_jwt).nil?"}},{"id":"lat?(value:String|Float):Bool-class-method","html_id":"lat?(value:String|Float):Bool-class-method","name":"lat?","doc":"Validates that the *value* is a valid format representation of a geographical latitude.\n- See also `#lng?`.\n- See also `#lat_lng?`.","summary":"
Validates that the value is a valid format representation of a geographical latitude.
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String | Float"}],"args_string":"(value : String | Float) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/geo.cr#L31","def":{"name":"lat?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String | Float"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!value.to_s.match(@@rx_geo_lat).nil?"}},{"id":"lat_lng?(value:String):Bool-class-method","html_id":"lat_lng?(value:String):Bool-class-method","name":"lat_lng?","doc":"Validates that the *value* is a valid format representation of\na geographical position (given in latitude and longitude).\n- See also `#lat?`.\n- See also `#lng?`.","summary":"
Validates that the value is a valid format representation of a geographical position (given in latitude and longitude).
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/geo.cr#L16","def":{"name":"lat_lng?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"if !(value.includes?(\",\"))\n return false\nend\nlat, lng = value.split(\",\")\nif lat && lng\nelse\n return false\nend\nif ((lat.starts_with?('(')) && (!(lng.ends_with?(')'))))\n return false\nend\nif ((lng.ends_with?(')')) && (!(lat.starts_with?('('))))\n return false\nend\nif (lat.match(@@rx_geo_lat)) && (lng.match(@@rx_geo_lng))\n return true\nend\nfalse\n"}},{"id":"lng?(value:String|Float):Bool-class-method","html_id":"lng?(value:String|Float):Bool-class-method","name":"lng?","doc":"Validates that the *value* is a valid format representation of a geographical longitude.\n- See also `#lat?`.\n- See also `#lat_lng?`.","summary":"
Validates that the value is a valid format representation of a geographical longitude.
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String | Float"}],"args_string":"(value : String | Float) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/geo.cr#L38","def":{"name":"lng?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String | Float"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!value.to_s.match(@@rx_geo_lng).nil?"}},{"id":"lower?(value:String):Bool-class-method","html_id":"lower?(value:String):Bool-class-method","name":"lower?","doc":"Validates that the *value* is in lower case.","summary":"
Validates that the value is in lower case.
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/case_sensitive.cr#L10","def":{"name":"lower?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"(!value.blank?) && (value.downcase === value)"}},{"id":"lt?(value:String|Array,limit:Int):Bool-class-method","html_id":"lt?(value:String|Array,limit:Int):Bool-class-method","name":"lt?","doc":"Validates that the size of the *value* (`String` or `Array`)\nis lesser than *limit* number.","summary":"
Validates that the size of the value (String or Array) is lesser than limit number.
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String | Array"},{"name":"limit","doc":null,"default_value":"","external_name":"limit","restriction":"Int"}],"args_string":"(value : String | Array, limit : Int) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/comparisons.cr#L45","def":{"name":"lt?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String | Array"},{"name":"limit","doc":null,"default_value":"","external_name":"limit","restriction":"Int"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value.size < limit"}},{"id":"lt?(value,another_value):Bool-class-method","html_id":"lt?(value,another_value):Bool-class-method","name":"lt?","doc":"Validates that the *value* is lesser than *another_value*.","summary":"
Validates that the value is lesser than another_value.
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"another_value","doc":null,"default_value":"","external_name":"another_value","restriction":""}],"args_string":"(value, another_value) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/comparisons.cr#L39","def":{"name":"lt?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"another_value","doc":null,"default_value":"","external_name":"another_value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value < another_value"}},{"id":"lte?(value:String|Array,max:Int):Bool-class-method","html_id":"lte?(value:String|Array,max:Int):Bool-class-method","name":"lte?","doc":"Validates that the size of the *value* (`String` or `Array`)\nis equal or lesser than *max* number.\n> Similar to `#max`.","summary":"
Validates that the size of the value (String or Array) is equal or lesser than max number.
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String | Array"},{"name":"max","doc":null,"default_value":"","external_name":"max","restriction":"Int"}],"args_string":"(value : String | Array, max : Int) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/comparisons.cr#L58","def":{"name":"lte?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String | Array"},{"name":"max","doc":null,"default_value":"","external_name":"max","restriction":"Int"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value.size <= max"}},{"id":"lte?(value,another_value):Bool-class-method","html_id":"lte?(value,another_value):Bool-class-method","name":"lte?","doc":"Validates that the *value* is equal to or lesser than *another_value*.\n> Similar to `#max`.","summary":"
Validates that the value is equal to or lesser than another_value.
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"another_value","doc":null,"default_value":"","external_name":"another_value","restriction":""}],"args_string":"(value, another_value) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/comparisons.cr#L51","def":{"name":"lte?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"another_value","doc":null,"default_value":"","external_name":"another_value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value <= another_value"}},{"id":"mac_addr?(value:String,no_colons:Bool=false):Bool-class-method","html_id":"mac_addr?(value:String,no_colons:Bool=false):Bool-class-method","name":"mac_addr?","doc":"Validates that the *value* is a MAC address.","summary":"
Validates that the value is a MAC address.
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"no_colons","doc":null,"default_value":"false","external_name":"no_colons","restriction":"Bool"}],"args_string":"(value : String, no_colons : Bool = false) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/uri.cr#L176","def":{"name":"mac_addr?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"no_colons","doc":null,"default_value":"false","external_name":"no_colons","restriction":"Bool"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"if no_colons\n return !value.match(@@rx_mac_addr_no_colons).nil?\nend\n(((!value.match(@@rx_mac_addr).nil?) || (!value.match(@@rx_mac_addr_with_hyphen).nil?)) || (!value.match(@@rx_mac_addr_with_spaces).nil?)) || (!value.match(@@rx_mac_addr_with_dots).nil?)\n"}},{"id":"magnet_uri?(value:String):Bool-class-method","html_id":"magnet_uri?(value:String):Bool-class-method","name":"magnet_uri?","doc":"Validates that the *value* is a Magnet URI.","summary":"
Validates that the value is a Magnet URI.
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/uri.cr#L186","def":{"name":"magnet_uri?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!value.match(@@rx_magnet_uri).nil?"}},{"id":"match?(value:Number,pattern:Regex):Bool-class-method","html_id":"match?(value:Number,pattern:Regex):Bool-class-method","name":"match?","doc":"Validates that the *value* matches the *pattern*.","summary":"
Validates that the value matches the pattern.
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"Number"},{"name":"pattern","doc":null,"default_value":"","external_name":"pattern","restriction":"Regex"}],"args_string":"(value : Number, pattern : Regex) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/presence.cr#L15","def":{"name":"match?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"Number"},{"name":"pattern","doc":null,"default_value":"","external_name":"pattern","restriction":"Regex"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!value.to_s.match(pattern).nil?"}},{"id":"match?(value:String,pattern:Regex):Bool-class-method","html_id":"match?(value:String,pattern:Regex):Bool-class-method","name":"match?","doc":"Validates that the *value* matches the *pattern*.","summary":"
Validates that the value matches the pattern.
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"pattern","doc":null,"default_value":"","external_name":"pattern","restriction":"Regex"}],"args_string":"(value : String, pattern : Regex) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/presence.cr#L10","def":{"name":"match?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"pattern","doc":null,"default_value":"","external_name":"pattern","restriction":"Regex"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!value.match(pattern).nil?"}},{"id":"max?(value,max):Bool-class-method","html_id":"max?(value,max):Bool-class-method","name":"max?","doc":"Validates that the *value* is equal to or lesser than *max* (inclusive).\n> Similar to `#lte`.","summary":"
Validates that the value is equal to or lesser than max (inclusive).
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"max","doc":null,"default_value":"","external_name":"max","restriction":""}],"args_string":"(value, max) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/comparisons.cr#L76","def":{"name":"max?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"max","doc":null,"default_value":"","external_name":"max","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value <= max"}},{"id":"max?(value:String|Array,max:Int):Bool-class-method","html_id":"max?(value:String|Array,max:Int):Bool-class-method","name":"max?","doc":":ditto:\n> Based on the size of the `String`.","summary":"
:ditto: > Based on the size of the String.
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String | Array"},{"name":"max","doc":null,"default_value":"","external_name":"max","restriction":"Int"}],"args_string":"(value : String | Array, max : Int) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/comparisons.cr#L82","def":{"name":"max?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String | Array"},{"name":"max","doc":null,"default_value":"","external_name":"max","restriction":"Int"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value.size <= max"}},{"id":"md5?(value:String):Bool-class-method","html_id":"md5?(value:String):Bool-class-method","name":"md5?","doc":"Validates that the *value* has the format *md5*.","summary":"
Validates that the value has the format md5.
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/format.cr#L82","def":{"name":"md5?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!value.match(@@rx_md5).nil?"}},{"id":"min?(value,min):Bool-class-method","html_id":"min?(value,min):Bool-class-method","name":"min?","doc":"Validates that the *value* is equal to or greater than *min* (inclusive).\n> Similar to `#gte`.","summary":"
Validates that the value is equal to or greater than min (inclusive).
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"min","doc":null,"default_value":"","external_name":"min","restriction":""}],"args_string":"(value, min) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/comparisons.cr#L64","def":{"name":"min?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"min","doc":null,"default_value":"","external_name":"min","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value >= min"}},{"id":"min?(value:String|Array,min:Int):Bool-class-method","html_id":"min?(value:String|Array,min:Int):Bool-class-method","name":"min?","doc":":ditto:\n> Based on the size of the `String`.","summary":"
:ditto: > Based on the size of the String.
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String | Array"},{"name":"min","doc":null,"default_value":"","external_name":"min","restriction":"Int"}],"args_string":"(value : String | Array, min : Int) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/comparisons.cr#L70","def":{"name":"min?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String | Array"},{"name":"min","doc":null,"default_value":"","external_name":"min","restriction":"Int"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value.size >= min"}},{"id":"mongo_id?(value:Bytes):Bool-class-method","html_id":"mongo_id?(value:Bytes):Bool-class-method","name":"mongo_id?","doc":"Validates that the `Bytes` *value* does denote\na representation of a *MongoID* slice of Bytes.","summary":"
Validates that the Bytesvalue does denote a representation of a MongoID slice of Bytes.
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"Bytes"}],"args_string":"(value : Bytes) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/format.cr#L143","def":{"name":"mongo_id?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"Bytes"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"(self.hex?(value)) && (value.size == 24)"}},{"id":"mongo_id?(value:String):Bool-class-method","html_id":"mongo_id?(value:String):Bool-class-method","name":"mongo_id?","doc":"Validates that the `String` *value* does denote\na representation of a *MongoID* string.","summary":"
Validates that the Stringvalue does denote a representation of a MongoID string.
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/format.cr#L137","def":{"name":"mongo_id?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"(self.hex?(value)) && (value.size == 24)"}},{"id":"not_empty?(value):Bool-class-method","html_id":"not_empty?(value):Bool-class-method","name":"not_empty?","doc":"Validates that the *value* is not empty.\n- See also `#presence?`.\n- See also `#in?`.","summary":"
Validates that the value is not empty.
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"args_string":"(value) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/presence.cr#L71","def":{"name":"not_empty?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"(self.empty?(value)) == false"}},{"id":"not_in?(value:String,str:String):Bool-class-method","html_id":"not_in?(value:String,str:String):Bool-class-method","name":"not_in?","doc":"Validates that the (*str*) `String` does not contain the *value*.\n- See also `#absence?`.\n- See also `#in?`.\n- See also `#empty?`.","summary":"
Validates that the (str) String does not contain the value.
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"str","doc":null,"default_value":"","external_name":"str","restriction":"String"}],"args_string":"(value : String, str : String) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/presence.cr#L141","def":{"name":"not_in?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"str","doc":null,"default_value":"","external_name":"str","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!(str.includes?(value))"}},{"id":"not_in?(value,list:Array):Bool-class-method","html_id":"not_in?(value,list:Array):Bool-class-method","name":"not_in?","doc":"Validates that the (*list*) does not contain the *value*.\n- See also `#absence?`.\n- See also `#in?`.\n- See also `#empty?`.","summary":"
Validates that the (list) does not contain the value.
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Array"}],"args_string":"(value, list : Array) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/presence.cr#L149","def":{"name":"not_in?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Array"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!(list.includes?(value))"}},{"id":"not_in?(value,list:Tuple):Bool-class-method","html_id":"not_in?(value,list:Tuple):Bool-class-method","name":"not_in?","doc":"Validates that the (*list*) does not contain the *value*.\n- See also `#absence?`.\n- See also `#in?`.\n- See also `#empty?`.","summary":"
Validates that the (list) does not contain the value.
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Tuple"}],"args_string":"(value, list : Tuple) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/presence.cr#L154","def":{"name":"not_in?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Tuple"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!(list.includes?(value))"}},{"id":"not_in?(value,list:Range):Bool-class-method","html_id":"not_in?(value,list:Range):Bool-class-method","name":"not_in?","doc":"Validates that the (*list*) does not contain the *value*.\n- See also `#absence?`.\n- See also `#in?`.\n- See also `#empty?`.","summary":"
Validates that the (list) does not contain the value.
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Range"}],"args_string":"(value, list : Range) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/presence.cr#L159","def":{"name":"not_in?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Range"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!(list.includes?(value))"}},{"id":"not_in?(key:Symbol|String,list:NamedTuple):Bool-class-method","html_id":"not_in?(key:Symbol|String,list:NamedTuple):Bool-class-method","name":"not_in?","doc":"Validates that the (*list*) does not contain the *value*.\n- See also `#absence?`.\n- See also `#in?`.\n- See also `#empty?`.","summary":"
Validates that the (list) does not contain the value.
","abstract":false,"args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"Symbol | String"},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"NamedTuple"}],"args_string":"(key : Symbol | String, list : NamedTuple) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/presence.cr#L164","def":{"name":"not_in?","args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"Symbol | String"},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"NamedTuple"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!(list.has_key?(key))"}},{"id":"not_in?(key:Symbol|String,list:Hash):Bool-class-method","html_id":"not_in?(key:Symbol|String,list:Hash):Bool-class-method","name":"not_in?","doc":"Validates that the (*list*) does not contain the *value*.\n- See also `#absence?`.\n- See also `#in?`.\n- See also `#empty?`.","summary":"
Validates that the (list) does not contain the value.
","abstract":false,"args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"Symbol | String"},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Hash"}],"args_string":"(key : Symbol | String, list : Hash) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/presence.cr#L169","def":{"name":"not_in?","args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"Symbol | String"},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Hash"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!(list.has_key?(key))"}},{"id":"not_null?(value):Bool-class-method","html_id":"not_null?(value):Bool-class-method","name":"not_null?","doc":"Validates that the *value* is not null (`nil`).\n- See also `#null?`.\n- See also `#not_empty?`.","summary":"
Validates that the value is not null (nil).
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"args_string":"(value) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/presence.cr#L89","def":{"name":"not_null?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!value.nil?"}},{"id":"null?(value):Bool-class-method","html_id":"null?(value):Bool-class-method","name":"null?","doc":"Validates that the *value* is null (`nil`).\n- See also `#empty?`.\n- See also `#not_null?`.","summary":"
Validates that the value is null (nil).
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"args_string":"(value) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/presence.cr#L82","def":{"name":"null?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value.nil?"}},{"id":"number?(value:String):Bool-class-method","html_id":"number?(value:String):Bool-class-method","name":"number?","doc":"Validates that the *value* is a numeric `String` representation.","summary":"
Validates that the value is a numeric String representation.
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/alpha_num.cr#L12","def":{"name":"number?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"(!value.blank?) && (!value.match(@@rx_number).nil?)"}},{"id":"port?(value:String="0",min:String="1",max:String="65535"):Bool-class-method","html_id":"port?(value:String="0",min:String="1",max:String="65535"):Bool-class-method","name":"port?","doc":"Validates that the *value* is in a valid port range,\nbetween (inclusive) 1 / *min* and 65535 / *max*.","summary":"
Validates that the value is in a valid port range, between (inclusive) 1 / min and 65535 / max.
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"\"0\"","external_name":"value","restriction":"String"},{"name":"min","doc":null,"default_value":"\"1\"","external_name":"min","restriction":"String"},{"name":"max","doc":null,"default_value":"\"65535\"","external_name":"max","restriction":"String"}],"args_string":"(value : String = "0", min : String = "1", max : String = "65535") : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/uri.cr#L44","def":{"name":"port?","args":[{"name":"value","doc":null,"default_value":"\"0\"","external_name":"value","restriction":"String"},{"name":"min","doc":null,"default_value":"\"1\"","external_name":"min","restriction":"String"},{"name":"max","doc":null,"default_value":"\"65535\"","external_name":"max","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"if (self.number?(min)) && (self.number?(max))\nelse\n return false\nend\nself.port?(value.to_i, min.to_i, max.to_i)\n"}},{"id":"port?(value=0,min=1,max=65535):Bool-class-method","html_id":"port?(value=0,min=1,max=65535):Bool-class-method","name":"port?","doc":"Validates that the *value* is in a valid port range,\nbetween (inclusive) 1 / *min* and 65535 / *max*.","summary":"
Validates that the value is in a valid port range, between (inclusive) 1 / min and 65535 / max.
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"0","external_name":"value","restriction":""},{"name":"min","doc":null,"default_value":"1","external_name":"min","restriction":""},{"name":"max","doc":null,"default_value":"65535","external_name":"max","restriction":""}],"args_string":"(value = 0, min = 1, max = 65535) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/uri.cr#L38","def":{"name":"port?","args":[{"name":"value","doc":null,"default_value":"0","external_name":"value","restriction":""},{"name":"min","doc":null,"default_value":"1","external_name":"min","restriction":""},{"name":"max","doc":null,"default_value":"65535","external_name":"max","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"if self.between?(value, 1, 65535)\nelse\n return false\nend\nself.between?(value, min, max)\n"}},{"id":"presence?(key:String|Symbol,list:NamedTuple):Bool-class-method","html_id":"presence?(key:String|Symbol,list:NamedTuple):Bool-class-method","name":"presence?","doc":"Validates the presence of the value.\n- See also `#in?`.\n- See also `#not_empty?`.","summary":"
Validates the presence of the value.
","abstract":false,"args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"String | Symbol"},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"NamedTuple"}],"args_string":"(key : String | Symbol, list : NamedTuple) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/presence.cr#L31","def":{"name":"presence?","args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"String | Symbol"},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"NamedTuple"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"self.not_empty?(list[key]?)"}},{"id":"presence?(key:String|Symbol|Number,list:Hash):Bool-class-method","html_id":"presence?(key:String|Symbol|Number,list:Hash):Bool-class-method","name":"presence?","doc":"Validates the presence of the value.\n- See also `#in?`.\n- See also `#not_empty?`.","summary":"
Validates the presence of the value.
","abstract":false,"args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"String | Symbol | Number"},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Hash"}],"args_string":"(key : String | Symbol | Number, list : Hash) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/presence.cr#L26","def":{"name":"presence?","args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"String | Symbol | Number"},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Hash"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"self.not_empty?(list[key]?)"}},{"id":"refused?(value):Bool-class-method","html_id":"refused?(value):Bool-class-method","name":"refused?","doc":"Returns `true` if the *value* is the representation of a refusal.\n> One of: \"no\", \"n\", \"off\", \"0\", \"false\"\n\n*value* must implements *#to_s* method.\n- See also `#accepted?`.","summary":"
Returns true if the value is the representation of a refusal.
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"args_string":"(value) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/presence.cr#L209","def":{"name":"refused?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"self.refused?(value.to_s)"}},{"id":"refused?(value:String):Bool-class-method","html_id":"refused?(value:String):Bool-class-method","name":"refused?","doc":"Validates that the *value* `String` is the representation of a refusal.\n> One of: \"no\", \"n\", \"off\", \"0\", \"false\"\n- See also `#accepted?`.","summary":"
Validates that the valueString is the representation of a refusal.
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/presence.cr#L200","def":{"name":"refused?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"self.in?(value.downcase, [\"no\", \"n\", \"off\", \"0\", \"false\"])"}},{"id":"size?(value,size:Array(String))-class-method","html_id":"size?(value,size:Array(String))-class-method","name":"size?","doc":"Validates that the *value* is in the *size* array.\n- See also `#between?`.","summary":"
Validates that the value is in the size array.
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"size","doc":null,"default_value":"","external_name":"size","restriction":"Array(String)"}],"args_string":"(value, size : Array(String))","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/comparisons.cr#L122","def":{"name":"size?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"size","doc":null,"default_value":"","external_name":"size","restriction":"Array(String)"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"size.includes?(value.size.to_s)"}},{"id":"size?(value,size:Array(Int))-class-method","html_id":"size?(value,size:Array(Int))-class-method","name":"size?","doc":"Validates that the *value* is in the *size* array.\n- See also `#between?`.","summary":"
Validates that the value is in the size array.
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"size","doc":null,"default_value":"","external_name":"size","restriction":"Array(Int)"}],"args_string":"(value, size : Array(Int))","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/comparisons.cr#L117","def":{"name":"size?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"size","doc":null,"default_value":"","external_name":"size","restriction":"Array(Int)"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"size.includes?(value.size)"}},{"id":"size?(value,size:Range)-class-method","html_id":"size?(value,size:Range)-class-method","name":"size?","doc":"Validates that the *value* is in the *size* range.\n- See also `#between?`.","summary":"
Validates that the value is in the size range.
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"size","doc":null,"default_value":"","external_name":"size","restriction":"Range"}],"args_string":"(value, size : Range)","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/comparisons.cr#L111","def":{"name":"size?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"size","doc":null,"default_value":"","external_name":"size","restriction":"Range"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"size.includes?(value.size)"}},{"id":"size?(value,size:String)-class-method","html_id":"size?(value,size:String)-class-method","name":"size?","doc":"Validates that the *value* is equal to the *size*.","summary":"
Validates that the value is equal to the size.
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"size","doc":null,"default_value":"","external_name":"size","restriction":"String"}],"args_string":"(value, size : String)","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/comparisons.cr#L105","def":{"name":"size?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"size","doc":null,"default_value":"","external_name":"size","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"value.size.to_s == size"}},{"id":"size?(value,size:Int)-class-method","html_id":"size?(value,size:Int)-class-method","name":"size?","doc":"Validates that the *value* is equal to the *size*.","summary":"
Validates that the value is equal to the size.
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"size","doc":null,"default_value":"","external_name":"size","restriction":"Int"}],"args_string":"(value, size : Int)","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/comparisons.cr#L100","def":{"name":"size?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"size","doc":null,"default_value":"","external_name":"size","restriction":"Int"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"value.size == size"}},{"id":"slug?(value:String,min=1,max=100):Bool-class-method","html_id":"slug?(value:String,min=1,max=100):Bool-class-method","name":"slug?","doc":"Validates that the *value* is a slug.","summary":"
Validates that the value is a slug.
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"min","doc":null,"default_value":"1","external_name":"min","restriction":""},{"name":"max","doc":null,"default_value":"100","external_name":"max","restriction":""}],"args_string":"(value : String, min = 1, max = 100) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/uri.cr#L171","def":{"name":"slug?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"min","doc":null,"default_value":"1","external_name":"min","restriction":""},{"name":"max","doc":null,"default_value":"100","external_name":"max","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!value.match(/^([a-zA-Z0-9_-]{#{min},#{max}})$/).nil?"}},{"id":"starts?(value:String,search:Char):Bool-class-method","html_id":"starts?(value:String,search:Char):Bool-class-method","name":"starts?","doc":"Validates that the `String` *value* starts with *search*.\n- See also `#ends?`.\n- See also `#match?`.\n- See also `#in?`.","summary":"
Validates that the Stringvalue starts with search.
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"search","doc":null,"default_value":"","external_name":"search","restriction":"Char"}],"args_string":"(value : String, search : Char) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/presence.cr#L226","def":{"name":"starts?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"search","doc":null,"default_value":"","external_name":"search","restriction":"Char"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value.starts_with?(search)"}},{"id":"starts?(value:String,search:Regex):Bool-class-method","html_id":"starts?(value:String,search:Regex):Bool-class-method","name":"starts?","doc":"Validates that the `String` *value* starts with *search*.\n- See also `#ends?`.\n- See also `#match?`.\n- See also `#in?`.","summary":"
Validates that the Stringvalue starts with search.
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"search","doc":null,"default_value":"","external_name":"search","restriction":"Regex"}],"args_string":"(value : String, search : Regex) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/presence.cr#L231","def":{"name":"starts?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"search","doc":null,"default_value":"","external_name":"search","restriction":"Regex"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value.starts_with?(search)"}},{"id":"starts?(value:String,search:String):Bool-class-method","html_id":"starts?(value:String,search:String):Bool-class-method","name":"starts?","doc":"Validates that the `String` *value* starts with *search*.\n- See also `#ends?`.\n- See also `#match?`.\n- See also `#in?`.","summary":"
Validates that the Stringvalue starts with search.
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"search","doc":null,"default_value":"","external_name":"search","restriction":"String"}],"args_string":"(value : String, search : String) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/presence.cr#L221","def":{"name":"starts?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"search","doc":null,"default_value":"","external_name":"search","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value.starts_with?(search)"}},{"id":"time?(value:String):Bool-class-method","html_id":"time?(value:String):Bool-class-method","name":"time?","doc":"Validates that the *value* is a time `String` representation.","summary":"
Validates that the value is a time String representation.
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/format.cr#L31","def":{"name":"time?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"(!value.blank?) && (!value.match(@@rx_time).nil?)"}},{"id":"upper?(value:String):Bool-class-method","html_id":"upper?(value:String):Bool-class-method","name":"upper?","doc":"Validates that the *value* is in upper case.","summary":"
Validates that the value is in upper case.
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/case_sensitive.cr#L15","def":{"name":"upper?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"(!value.blank?) && (value.upcase === value)"}},{"id":"url?(value:String):Bool-class-method","html_id":"url?(value:String):Bool-class-method","name":"url?","doc":"Validates that the *value* is a URL.","summary":"
Validates that the value is a URL.
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/uri.cr#L52","def":{"name":"url?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"size = value.size\nif ((size >= 2083 || size < 11) || (value.match(/[\\s<>]/))) || (value.starts_with?(\"mailto:\"))\n return false\nend\nif m = value.match(@@rx_url)\nelse\n return false\nend\nif self.domain?(\"#{m[\"name\"]}.#{m[\"ext\"]}\")\nelse\n return false\nend\nsp = (value.gsub(/^http(?:s)?:\\/\\//, \"\")).split(\":\")\nif sp.size > 1\n if m_port = sp[1].match(/^[0-9]+/)\n else\n return true\n end\n return self.port?(m_port[0])\nend\ntrue\n"}},{"id":"uuid?(value:String,version=0):Bool-class-method","html_id":"uuid?(value:String,version=0):Bool-class-method","name":"uuid?","doc":"Validates that the *value* is a *UUID*\nVersions: 0 (all), 3, 4 and 5. *version* by default is 0 (all).","summary":"
Validates that the value is a UUID Versions: 0 (all), 3, 4 and 5.
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"version","doc":null,"default_value":"0","external_name":"version","restriction":""}],"args_string":"(value : String, version = 0) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/format.cr#L103","def":{"name":"uuid?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"version","doc":null,"default_value":"0","external_name":"version","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"if @@rx_uuid.has_key?(version)\nelse\n return false\nend\n!value.match(@@rx_uuid[version]).nil?\n"}}],"constructors":[],"instance_methods":[],"macros":[],"types":[{"html_id":"validator/Validator/Error","path":"Validator/Error.html","kind":"class","full_name":"Validator::Error","name":"Error","abstract":false,"superclass":{"html_id":"validator/Exception","kind":"class","full_name":"Exception","name":"Exception"},"ancestors":[{"html_id":"validator/Exception","kind":"class","full_name":"Exception","name":"Exception"},{"html_id":"validator/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"validator/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"src/validator.cr","line_number":120,"url":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validator.cr#L120"}],"repository_name":"validator","program":false,"enum":false,"alias":false,"aliased":"","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"validator/Validator","kind":"module","full_name":"Validator","name":"Validator"},"doc":"Used by `is!` when a validation is not `true`.","summary":"