diff --git a/docs/Check/CheckableStatic.html b/docs/Check/CheckableStatic.html index ea57c80..21b6ac0 100644 --- a/docs/Check/CheckableStatic.html +++ b/docs/Check/CheckableStatic.html @@ -242,7 +242,14 @@

  • #h_from_json(json : String | IO) -

    Returns a Hash from a JSON input.

    +

    Returns a json Hash from a JSON input.

    + +
  • + +
  • + #h_from_json!(json : String | IO) + +

    Returns a json Hash from a JSON input.

  • @@ -451,7 +458,7 @@

    -

    Returns a Hash from a JSON input. +

    Returns a json 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.

    @@ -465,6 +472,28 @@

    +
    +
    + + def h_from_json!(json : String | IO) + + # +
    + +
    + +

    Returns a json Hash from a JSON input. +Same as #h_from_json, except that this method raises a JSON::ParseException if the conversion fails.

    + +
    user_h = User.h_from_json!(json) # => {"username" => "Bob", "email" => "user@example.com"}
    +
    + +
    +
    + +
    +
    +
    diff --git a/docs/Check/ValidationError.html b/docs/Check/ValidationError.html index c99b0ce..05d68f6 100644 --- a/docs/Check/ValidationError.html +++ b/docs/Check/ValidationError.html @@ -135,7 +135,7 @@

    - + @@ -249,6 +249,16 @@

    + + + + + + + + + + diff --git a/docs/Validator/Error.html b/docs/Validator/Error.html index e14498b..5df20fb 100644 --- a/docs/Validator/Error.html +++ b/docs/Validator/Error.html @@ -159,6 +159,20 @@

    +

    + + + + Direct Known Subclasses +

    + + diff --git a/docs/index.json b/docs/index.json index 6fb9884..42e004c 100644 --- a/docs/index.json +++ b/docs/index.json @@ -1 +1 @@ -{"repository_name":"validator","body":"# validator\n\n[![CI Status](https://github.com/Nicolab/crystal-validator/workflows/CI/badge.svg?branch=master)](https://github.com/Nicolab/crystal-validator/actions) [![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```\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\nThe validation rules can be defined directly when defining properties (with `getter` or `property`).\nOr with the macro `Check.rules`. Depending on preference, it's the same under the hood.\n\n```crystal\nrequire \"validator/check\"\n\nclass User\n # Mixin\n Check.checkable\n\n # required\n property email : String, {\n required: true,\n\n # Optional lifecycle hook to be executed on `check_email` call.\n # Before the `check` rules, just after `clean_email` called inside `check_email`.\n # Proc or method name (here is a Proc)\n before_check: ->(v : Check::Validation, content : String?, required : Bool, format : Bool) {\n puts \"before_check_content\"\n content\n },\n\n # Optional lifecycle hook to be executed on `check_email` call, after the `check` rules.\n # Proc or method name (here is the method name)\n after_check: :after_check_email\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) or method name (Symbol)\n format: :format_email,\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 property age : Int32, {\n required: \"Age is required\", # Custom message\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 property bio : String?, {\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 def initialize(@email, @age)\n end\n\n # ---------------------------------------------------------------------------\n # Lifecycle methods (hooks)\n # ---------------------------------------------------------------------------\n\n # Triggered on instance: `user.check`\n private def before_check(v : Check::Validation, required : Bool, format : Bool)\n # Code...\n end\n\n # Triggered on instance: `user.check`\n private 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 private 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 private 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 # Triggered on a static call and on instance call: `User.check_email(value)`, `User.check(h)`, `user.check`.\n private def self.after_check_content(v : Check::Validation, content : String?, required : Bool, format : Bool)\n puts \"after_check_content\"\n puts \"Valid? #{v.valid?}\"\n content\n end\n\n # --------------------------------------------------------------------------\n # Custom checkers\n # --------------------------------------------------------------------------\n\n # Triggered on instance: `user.check`\n @[Check::Checker]\n private def custom_checker(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 @[Check::Checker]\n private def self.custom_checker(v : Check::Validation, h, cleaned_h, required : Bool, format : Bool)\n # Code...\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 # ...\nend\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# Same but raise if there is a validation error\nuser_h = User.check!(input_h)\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# Same but raise if there is a validation error\nuser.check! # => Validation instance\n\n# Example with an active record model\nuser.check!.save\n\n# Check field\nv, email = User.check_email(value: \"demo@example.org\")\nv, age = User.check_age(value: 42)\n\n# Same but raise if there is a validation error\nemail = User.check_email!(value: \"demo@example.org\")\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# Same but raise if there is a validation error\nemail = 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# Same but raise if there is a validation error\nvalue1, 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# Same but raise if there is a validation error\n# Email value with one space before and one space after\nemail = 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./bin/ameba\n```\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":null,"aliased_html":null,"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)","location":{"filename":"src/is.cr","line_number":18,"url":null},"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)","location":{"filename":"src/is.cr","line_number":26,"url":null},"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":null},{"filename":"src/checkable.cr","line_number":11,"url":null}],"repository_name":"validator","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[{"id":"RULES","name":"RULES","value":"{} of String => HashLiteral(String, ASTNode)","doc":null,"summary":null}],"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":"

    Initializes a new Validation instance to combine a series of checks (Validation#check).

    ","abstract":false,"args":[{"name":"errors","doc":null,"default_value":"","external_name":"errors","restriction":"Errors"}],"args_string":"(errors : Errors)","args_html":"(errors : Errors)","location":{"filename":"src/check.cr","line_number":377,"url":null},"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":"

    Initializes a new Validation instance to combine a series of checks (Validation#check).

    ","abstract":false,"args":[],"args_string":"","args_html":"","location":{"filename":"src/check.cr","line_number":353,"url":null},"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 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\n def initialize(@title, @content)\n end\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":"","location":{"filename":"src/checkable.cr","line_number":69,"url":null},"def":{"name":"checkable","args":[],"double_splat":null,"splat_index":null,"block_arg":null,"visibility":"Public","body":" include Check::Prop\n 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 private def self.after_check_content(v : Check::Validation, content : String?, required : Bool, format : Bool)\n puts \"after_check_content\"\n puts \"Valid? #{v.valid?}\"\n content\n end\n\n Check.rules(\n content: {\n required: \"Content is required\", # or `true` to use the default error message\n before_check: ->(v : Check::Validation, content : String?, required : Bool, format : Bool) {\n puts \"before_check_content\"\n content\n },\n after_check: :after_check_email,\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 # Proc or method name (Symbol)\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)","location":{"filename":"src/checkable.cr","line_number":168,"url":null},"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":" \n{% for field, rules in fields %}\n {% if RULES[\"#{@type.name}\"] %}{% else %}\n {% RULES[\"#{@type.name}\"] = {} of String => ASTNode %}\n {% end %}\n\n {% RULES[\"#{@type.name}\"][field] = rules %}\n {% end %}\n\n\n \n# Returns all validation rules.\n\n private def self.validation_rules\n \n{\n \n{% for field, rules in RULES[\"#{@type.name}\"] %}\n {{ field }}: {{ rules }},\n {% end %}\n\n }\n \nend\n\n \n# Returns `true` if a given *field* is required.\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) == false ? false : true\n \nend\n\n \n# Returns `true` if a given *field* is nilable.\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 # Same as `clean_{{ field }}` but this method raises a `Validator::Error`\n # if the clean has not been processed successfully.\n #\n # ```\n # email = MyCheckable.clean_email!(user_input[\"email\"]) # => user@example.com\n # ```\n def self.clean_{{ field }}!(value, format = true) : {{ type }}\n ok, value = self.clean_{{ field }}(value, format)\n raise Validator::Error.new %(Cannot clean the \"{{ field }}\" field) unless ok\n value.as({{ type }})\n end\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 = MyCheckable.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,\n {% if format.is_a?(SymbolLiteral) %}\n {{ format.id }}(value)\n {% else %}\n {{ format }}.call(value)\n {% end %}\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 # Checks *value* and returns it cleaned.\n # This method raises a `Check::ValidationError` if the validation fails.\n def self.check_{{ field }}!(*, value, required : Bool = true, format : Bool = true) : {{ type }}\n v, value = self.check_{{ field }}(value: value, required: required, format: format)\n raise v.to_exception unless v.valid?\n value.as({{ type }})\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 # Checks *value* and returns it cleaned.\n # This method raises a `Check::ValidationError` if the validation fails.\n def self.check_{{ field }}!(\n v : Check::Validation,\n value,\n required : Bool = true,\n format : Bool = true\n ) : {{ type }}\n v, value = self.check_{{ field }}(v, value, required, format)\n raise v.to_exception unless v.valid?\n value.as({{ type }})\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(\n {{ field.stringify }},\n {{ msg }}\n ) {% if nilable || (check[\"not_null\"].nil? && check[\"not_empty\"].nil?) %}unless value.nil?{% end %}\n\n return v, value\n end\n\n # Lifecycle: hook before_check_field\n {% if before_check = rules[\"before_check\"] %}\n {% if before_check.is_a?(SymbolLiteral) %}\n value = {{ before_check.id }}(v, value, required, format)\n {% else %}\n value = {{ before_check }}.call(v, value, required, format)\n {% end %}\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?\n {% end %}\n {% end %}\n\n # Lifecycle: hook after_check_field\n {% if after_check = rules[\"after_check\"] %}\n {% if after_check.is_a?(SymbolLiteral) %}\n value = {{ after_check.id }}(v, value, required, format)\n {% else %}\n value = {{ after_check }}.call(v, value, required, format)\n {% 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":558,"url":null}],"repository_name":"validator","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"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)","args_html":"(v : Check::Validation, required : Bool = true, format : Bool = true)","location":{"filename":"src/checkable.cr","line_number":581,"url":null},"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)","args_html":"(v : Check::Validation, required : Bool = true, format : Bool = true)","location":{"filename":"src/checkable.cr","line_number":567,"url":null},"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":"Same as `check` but this method raises a `Check::ValidationError`\nif the validation fails or if the clean has not been processed successfully.\n\n```\nmyCheckable.check! # => Returns the current instance.\n```\n\nThis method returns `self`, so it chainable :)\n\n```\nuser.email = \"me@example.org\"\nuser.check!.save\n```","summary":"

    Same as #check but this method raises a Check::ValidationError if the validation fails or if the clean has not been processed successfully.

    ","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","args_html":"(required : Bool = true, format : Bool = true) : Validation","location":{"filename":"src/checkable.cr","line_number":667,"url":null},"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","args_html":"(v : Check::Validation, required : Bool = true, format : Bool = true) : Validation","location":{"filename":"src/checkable.cr","line_number":618,"url":null},"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(&.annotation(Checker)) %}\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 %}"}},{"id":"check!(required:Bool=true,format:Bool=true):self-instance-method","html_id":"check!(required:Bool=true,format:Bool=true):self-instance-method","name":"check!","doc":"Same as `check` but this method raises a `Check::ValidationError`\nif the validation fails or if the clean has not been processed successfully.\n\n```\nmyCheckable.check! # => Returns the current instance.\n```\n\nThis method returns `self`, so it chainable :)\n\n```\nuser.email = \"me@example.org\"\nuser.check!.save\n```","summary":"

    Same as #check but this method raises a Check::ValidationError if the validation fails or if the clean has not been processed successfully.

    ","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) : self","args_html":"(required : Bool = true, format : Bool = true) : self","location":{"filename":"src/checkable.cr","line_number":660,"url":null},"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":"self","visibility":"Public","body":"v = check(required, format)\nif v.valid?\nelse\n raise(v.to_exception)\nend\nself\n"}},{"id":"check!(v:Check::Validation,required:Bool=true,format:Bool=true):self-instance-method","html_id":"check!(v:Check::Validation,required:Bool=true,format:Bool=true):self-instance-method","name":"check!","doc":"Same as `check` but this method raises a `Check::ValidationError`\nif the validation fails or if the clean has not been processed successfully.\n\n```\nv = Validation.new_validation\nmyCheckable.check!(v) # => Returns the current instance.\n```\n\nThis method returns `self`, so it chainable :)\n\n```\nv = Validation.new_validation\nuser.email = \"me@example.org\"\nuser.check!(v).save\n```","summary":"

    Same as #check but this method raises a Check::ValidationError if the validation fails or if the clean has not been processed successfully.

    ","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) : self","args_html":"(v : Check::Validation, required : Bool = true, format : Bool = true) : self","location":{"filename":"src/checkable.cr","line_number":602,"url":null},"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":"self","visibility":"Public","body":"v = check(v, required, format)\nif v.valid?\nelse\n raise(v.to_exception)\nend\nself\n"}}],"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":372,"url":null}],"repository_name":"validator","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"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","args_html":"(v : Check::Validation, h : Hash, cleaned_h : Hash, required : Bool = true, format : Bool = true) : Hash","location":{"filename":"src/checkable.cr","line_number":452,"url":null},"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)","args_html":"(v : Check::Validation, h : Hash, required : Bool = true, format : Bool = true)","location":{"filename":"src/checkable.cr","line_number":431,"url":null},"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)","args_html":"(v : Check::Validation, h : Hash, required : Bool = true, format : Bool = true)","location":{"filename":"src/checkable.cr","line_number":484,"url":null},"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\n if h.has_key?({{ field_name }})\n v, value = self.check_{{ field }}(v, h[{{ field_name }}]?, required, format)\n cleaned_h[{{ field_name }}] = value.as({{ types[i] }})\n\n # or if this field MUST be checked when required\n elsif required && self.validation_required?({{ field_name }})\n required_msg = self.validation_rules[{{ field_name }}].fetch(:required, nil)\n\n msg = if required_msg && required_msg.is_a?(String)\n required_msg.as(String)\n else\n \"This field is required\"\n end\n\n v.add_error {{ field_name }}, msg\n end\n {% end %}\n\n # Check methods with `Check::Checker` annotation\n {% for method in @type.class.methods.select(&.annotation(Checker)) %}\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":"Same as `check` but this method raises a `Check::ValidationError`\nif the validation fails or if the clean has not been processed successfully.\n\n```\ncleaned_h = MyCheckable.check!(h)\n```","summary":"

    Same as #check but this method raises a Check::ValidationError if the validation fails or if the clean has not been processed successfully.

    ","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)","args_html":"(h : Hash, required : Bool = true, format : Bool = true)","location":{"filename":"src/checkable.cr","line_number":549,"url":null},"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":"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":"Same as `check` but this method raises a `Check::ValidationError`\nif the validation fails or if the clean has not been processed successfully.\n\n```\ncleaned_h = MyCheckable.check!(v, h)\n```","summary":"

    Same as #check but this method raises a Check::ValidationError if the validation fails or if the clean has not been processed successfully.

    ","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)","args_html":"(v : Check::Validation, h : Hash, required : Bool = true, format : Bool = true)","location":{"filename":"src/checkable.cr","line_number":467,"url":null},"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":"v, cleaned_h = check(v, h, required, format)\nif v.valid?\nelse\n raise(v.to_exception)\nend\ncleaned_h\n"}},{"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":"Same as `check` but this method raises a `Check::ValidationError`\nif the validation fails or if the clean has not been processed successfully.\n\n```\ncleaned_h = MyCheckable.check!(h)\n```","summary":"

    Same as #check but this method raises a Check::ValidationError if the validation fails or if the clean has not been processed successfully.

    ","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)","args_html":"(h : Hash, required : Bool = true, format : Bool = true)","location":{"filename":"src/checkable.cr","line_number":542,"url":null},"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, cleaned_h = check(h, required, format)\nif v.valid?\nelse\n raise(v.to_exception)\nend\ncleaned_h\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)","args_html":"(json : String | IO)","location":{"filename":"src/checkable.cr","line_number":416,"url":null},"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)","args_html":" : Hash(String, String)","location":{"filename":"src/checkable.cr","line_number":374,"url":null},"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","args_html":"(h : Hash) : Hash","location":{"filename":"src/checkable.cr","line_number":389,"url":null},"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","args_html":"(h : Hash) : Hash","location":{"filename":"src/checkable.cr","line_number":399,"url":null},"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":30,"url":null}],"repository_name":"validator","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"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":null}],"repository_name":"validator","program":false,"enum":false,"alias":true,"aliased":"Hash(String | Symbol, Array(String))","aliased_html":"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/Prop","path":"Check/Prop.html","kind":"module","full_name":"Check::Prop","name":"Prop","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/checkable.cr","line_number":77,"url":null}],"repository_name":"validator","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"validator/Check","kind":"module","full_name":"Check","name":"Check"},"doc":"A mixin to make the `getter` macro of the Crystal std's,\nable to support the rules definition and factory block.","summary":"

    A mixin to make the getter macro of the Crystal std's, able to support the rules definition and factory block.

    ","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":152,"url":null}],"repository_name":"validator","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"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 errors Hash (Check::Errors).

    ","abstract":false,"args":[{"name":"errors","doc":null,"default_value":"","external_name":"errors","restriction":"Errors"}],"args_string":"(errors : Errors)","args_html":"(errors : Errors)","location":{"filename":"src/check.cr","line_number":181,"url":null},"def":{"name":"new","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":"_ = allocate\n_.initialize(errors)\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}},{"id":"new-class-method","html_id":"new-class-method","name":"new","doc":"Initializes a validation.\n\n```\nv = Check::Validation.new\n```\n\nSame as:\n\n```\nv = Check.new_validation\n```","summary":"

    Initializes a validation.

    ","abstract":false,"args":[],"args_string":"","args_html":"","location":{"filename":"src/check.cr","line_number":166,"url":null},"def":{"name":"new","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"_ = allocate\n_.initialize\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}}],"instance_methods":[{"id":"add_error(key:Symbol|String,message:String):Validation-instance-method","html_id":"add_error(key:Symbol|String,message:String):Validation-instance-method","name":"add_error","doc":"Add a validation error.\n\n```\nv = Check.new_validation\nv.add_error(:foo, \"Foo error!\")\npp v.errors # => {:foo => [\"Foo error!\"]}\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"},{"name":"message","doc":null,"default_value":"","external_name":"message","restriction":"String"}],"args_string":"(key : Symbol | String, message : String) : Validation","args_html":"(key : Symbol | String, message : String) : Validation","location":{"filename":"src/check.cr","line_number":204,"url":null},"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","args_html":"(key : Symbol | String) : Validation","location":{"filename":"src/check.cr","line_number":224,"url":null},"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","args_html":"(key : Symbol | String, message : String, valid : Bool) : Validation","location":{"filename":"src/check.cr","line_number":272,"url":null},"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","args_html":"(key : Symbol | String, valid : Bool, message : String) : Validation","location":{"filename":"src/check.cr","line_number":309,"url":null},"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":"

    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"}],"args_string":"(key : Symbol | String, valid : Bool) : Validation","args_html":"(key : Symbol | String, valid : Bool) : Validation","location":{"filename":"src/check.cr","line_number":330,"url":null},"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"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Validation","visibility":"Public","body":"if valid\nelse\n add_error(key, \"\")\nend\nself\n"}},{"id":"errors:Errors-instance-method","html_id":"errors:Errors-instance-method","name":"errors","doc":"Errors container.\n\n```\nv = Check.new_validation\npp v.errors\n```","summary":"

    Errors container.

    ","abstract":false,"args":[],"args_string":" : Errors","args_html":" : Errors","location":{"filename":"src/check.cr","line_number":191,"url":null},"def":{"name":"errors","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Errors","visibility":"Public","body":"@errors"}},{"id":"to_exception-instance-method","html_id":"to_exception-instance-method","name":"to_exception","doc":"Creates a new instance of `ValidationError` (`Exception`).","summary":"

    Creates a new instance of ValidationError (Exception).

    ","abstract":false,"args":[],"args_string":"","args_html":"","location":{"filename":"src/check.cr","line_number":336,"url":null},"def":{"name":"to_exception","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"ValidationError.new(@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":"","args_html":"","location":{"filename":"src/check.cr","line_number":236,"url":null},"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/Check/ValidationError","path":"Check/ValidationError.html","kind":"class","full_name":"Check::ValidationError","name":"ValidationError","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/check.cr","line_number":23,"url":null}],"repository_name":"validator","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"validator/Check","kind":"module","full_name":"Check","name":"Check"},"doc":"Validation error.\nTo carry `Errors` into an `Exception`.","summary":"

    Validation error.

    ","class_methods":[],"constructors":[{"id":"new(errors:Errors,message="Validationerror")-class-method","html_id":"new(errors:Errors,message="Validationerror")-class-method","name":"new","doc":null,"summary":null,"abstract":false,"args":[{"name":"errors","doc":null,"default_value":"","external_name":"errors","restriction":"Errors"},{"name":"message","doc":null,"default_value":"\"Validation error\"","external_name":"message","restriction":""}],"args_string":"(errors : Errors, message = "Validation error")","args_html":"(errors : Errors, message = "Validation error")","location":{"filename":"src/check.cr","line_number":24,"url":null},"def":{"name":"new","args":[{"name":"errors","doc":null,"default_value":"","external_name":"errors","restriction":"Errors"},{"name":"message","doc":null,"default_value":"\"Validation error\"","external_name":"message","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"_ = allocate\n_.initialize(errors, message)\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}}],"instance_methods":[{"id":"errors:Errors-instance-method","html_id":"errors:Errors-instance-method","name":"errors","doc":"Returns `Errors` container (`Hash`).","summary":"

    Returns Errors container (Hash).

    ","abstract":false,"args":[],"args_string":" : Errors","args_html":" : Errors","location":{"filename":"src/check.cr","line_number":29,"url":null},"def":{"name":"errors","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Errors","visibility":"Public","body":"@errors"}}],"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":null}],"repository_name":"validator","program":false,"enum":false,"alias":true,"aliased":"Validator","aliased_html":"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":"

    Alias of Validator

    ","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":null},{"filename":"src/validators/alpha_num.cr","line_number":8,"url":null},{"filename":"src/validators/case_sensitive.cr","line_number":8,"url":null},{"filename":"src/validators/comparisons.cr","line_number":8,"url":null},{"filename":"src/validators/format.cr","line_number":8,"url":null},{"filename":"src/validators/geo.cr","line_number":8,"url":null},{"filename":"src/validators/presence.cr","line_number":8,"url":null},{"filename":"src/validators/uri.cr","line_number":8,"url":null}],"repository_name":"validator","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"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```\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```\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","args_html":"(key : String | Symbol, list : NamedTuple) : Bool","location":{"filename":"src/validators/presence.cr","line_number":47,"url":null},"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","args_html":"(key : String | Symbol | Number, list : Hash) : Bool","location":{"filename":"src/validators/presence.cr","line_number":42,"url":null},"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 value String 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","args_html":"(value : String) : Bool","location":{"filename":"src/validators/presence.cr","line_number":180,"url":null},"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","args_html":"(value) : Bool","location":{"filename":"src/validators/presence.cr","line_number":189,"url":null},"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 value String 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","args_html":"(value : String) : Bool","location":{"filename":"src/validators/format.cr","line_number":41,"url":null},"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 values Array 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","args_html":"(values : Array(String)) : Bool","location":{"filename":"src/validators/format.cr","line_number":47,"url":null},"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","args_html":"(value : String) : Bool","location":{"filename":"src/validators/format.cr","line_number":87,"url":null},"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","args_html":"(value, min, max) : Bool","location":{"filename":"src/validators/comparisons.cr","line_number":87,"url":null},"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","args_html":"(value : String | Array, min : Int, max : Int) : Bool","location":{"filename":"src/validators/comparisons.cr","line_number":94,"url":null},"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","args_html":"(value : String) : Bool","location":{"filename":"src/validators/uri.cr","line_number":26,"url":null},"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","args_html":"(value : String) : Bool","location":{"filename":"src/validators/uri.cr","line_number":161,"url":null},"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","args_html":"(value) : Bool","location":{"filename":"src/validators/presence.cr","line_number":58,"url":null},"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 String value 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","args_html":"(value : String, search : String) : Bool","location":{"filename":"src/validators/presence.cr","line_number":243,"url":null},"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 String value 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","args_html":"(value : String, search : Char) : Bool","location":{"filename":"src/validators/presence.cr","line_number":248,"url":null},"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 String value 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","args_html":"(value : String, search : Regex) : Bool","location":{"filename":"src/validators/presence.cr","line_number":253,"url":null},"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","args_html":"(value, another_value) : Bool","location":{"filename":"src/validators/comparisons.cr","line_number":10,"url":null},"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","args_html":"(value, another_value) : Bool","location":{"filename":"src/validators/comparisons.cr","line_number":15,"url":null},"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","args_html":"(value : String | Array, limit : Int) : Bool","location":{"filename":"src/validators/comparisons.cr","line_number":21,"url":null},"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","args_html":"(value, another_value) : Bool","location":{"filename":"src/validators/comparisons.cr","line_number":27,"url":null},"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","args_html":"(value : String | Array, min : Int) : Bool","location":{"filename":"src/validators/comparisons.cr","line_number":34,"url":null},"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 String value 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","args_html":"(value : String) : Bool","location":{"filename":"src/validators/format.cr","line_number":112,"url":null},"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 Bytes value 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","args_html":"(value : Bytes) : Bool","location":{"filename":"src/validators/format.cr","line_number":118,"url":null},"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 String value 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","args_html":"(value : String) : Bool","location":{"filename":"src/validators/format.cr","line_number":129,"url":null},"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","args_html":"(value, list : Array) : Bool","location":{"filename":"src/validators/presence.cr","line_number":109,"url":null},"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","args_html":"(value : String, str : String) : Bool","location":{"filename":"src/validators/presence.cr","line_number":101,"url":null},"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","args_html":"(key : Symbol | String, list : Hash) : Bool","location":{"filename":"src/validators/presence.cr","line_number":129,"url":null},"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","args_html":"(key : Symbol | String, list : NamedTuple) : Bool","location":{"filename":"src/validators/presence.cr","line_number":124,"url":null},"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","args_html":"(value, list : Range) : Bool","location":{"filename":"src/validators/presence.cr","line_number":119,"url":null},"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","args_html":"(value, list : Tuple) : Bool","location":{"filename":"src/validators/presence.cr","line_number":114,"url":null},"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","args_html":"(value : String) : Bool","location":{"filename":"src/validators/uri.cr","line_number":80,"url":null},"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","args_html":"(value : String) : Bool","location":{"filename":"src/validators/uri.cr","line_number":85,"url":null},"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","args_html":"(value : String) : Bool","location":{"filename":"src/validators/uri.cr","line_number":90,"url":null},"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","args_html":"(value : String, strict : Bool = true) : Bool","location":{"filename":"src/validators/format.cr","line_number":64,"url":null},"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","args_html":"(value : String) : Bool","location":{"filename":"src/validators/format.cr","line_number":95,"url":null},"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","args_html":"(value : String | Float) : Bool","location":{"filename":"src/validators/geo.cr","line_number":31,"url":null},"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","args_html":"(value : String) : Bool","location":{"filename":"src/validators/geo.cr","line_number":16,"url":null},"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","args_html":"(value : String | Float) : Bool","location":{"filename":"src/validators/geo.cr","line_number":38,"url":null},"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","args_html":"(value : String) : Bool","location":{"filename":"src/validators/case_sensitive.cr","line_number":10,"url":null},"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","args_html":"(value : String | Array, limit : Int) : Bool","location":{"filename":"src/validators/comparisons.cr","line_number":45,"url":null},"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","args_html":"(value, another_value) : Bool","location":{"filename":"src/validators/comparisons.cr","line_number":39,"url":null},"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","args_html":"(value : String | Array, max : Int) : Bool","location":{"filename":"src/validators/comparisons.cr","line_number":58,"url":null},"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","args_html":"(value, another_value) : Bool","location":{"filename":"src/validators/comparisons.cr","line_number":51,"url":null},"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","args_html":"(value : String, no_colons : Bool = false) : Bool","location":{"filename":"src/validators/uri.cr","line_number":179,"url":null},"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","args_html":"(value : String) : Bool","location":{"filename":"src/validators/uri.cr","line_number":189,"url":null},"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","args_html":"(value : Number, pattern : Regex) : Bool","location":{"filename":"src/validators/presence.cr","line_number":15,"url":null},"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","args_html":"(value : String, pattern : Regex) : Bool","location":{"filename":"src/validators/presence.cr","line_number":10,"url":null},"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","args_html":"(value, max) : Bool","location":{"filename":"src/validators/comparisons.cr","line_number":76,"url":null},"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","args_html":"(value : String | Array, max : Int) : Bool","location":{"filename":"src/validators/comparisons.cr","line_number":82,"url":null},"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","args_html":"(value : String) : Bool","location":{"filename":"src/validators/format.cr","line_number":82,"url":null},"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","args_html":"(value, min) : Bool","location":{"filename":"src/validators/comparisons.cr","line_number":64,"url":null},"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","args_html":"(value : String | Array, min : Int) : Bool","location":{"filename":"src/validators/comparisons.cr","line_number":70,"url":null},"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 Bytes value 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","args_html":"(value : Bytes) : Bool","location":{"filename":"src/validators/format.cr","line_number":143,"url":null},"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 String value 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","args_html":"(value : String) : Bool","location":{"filename":"src/validators/format.cr","line_number":137,"url":null},"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","args_html":"(value) : Bool","location":{"filename":"src/validators/presence.cr","line_number":71,"url":null},"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","args_html":"(value : String, str : String) : Bool","location":{"filename":"src/validators/presence.cr","line_number":141,"url":null},"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","args_html":"(value, list : Array) : Bool","location":{"filename":"src/validators/presence.cr","line_number":149,"url":null},"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","args_html":"(value, list : Tuple) : Bool","location":{"filename":"src/validators/presence.cr","line_number":154,"url":null},"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","args_html":"(value, list : Range) : Bool","location":{"filename":"src/validators/presence.cr","line_number":159,"url":null},"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","args_html":"(key : Symbol | String, list : NamedTuple) : Bool","location":{"filename":"src/validators/presence.cr","line_number":164,"url":null},"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","args_html":"(key : Symbol | String, list : Hash) : Bool","location":{"filename":"src/validators/presence.cr","line_number":169,"url":null},"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","args_html":"(value) : Bool","location":{"filename":"src/validators/presence.cr","line_number":89,"url":null},"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","args_html":"(value) : Bool","location":{"filename":"src/validators/presence.cr","line_number":82,"url":null},"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","args_html":"(value : String) : Bool","location":{"filename":"src/validators/alpha_num.cr","line_number":12,"url":null},"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","args_html":"(value : String = "0", min : String = "1", max : String = "65535") : Bool","location":{"filename":"src/validators/uri.cr","line_number":47,"url":null},"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","args_html":"(value = 0, min = 1, max = 65535) : Bool","location":{"filename":"src/validators/uri.cr","line_number":41,"url":null},"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","args_html":"(key : String | Symbol, list : NamedTuple) : Bool","location":{"filename":"src/validators/presence.cr","line_number":31,"url":null},"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","args_html":"(key : String | Symbol | Number, list : Hash) : Bool","location":{"filename":"src/validators/presence.cr","line_number":26,"url":null},"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","args_html":"(value) : Bool","location":{"filename":"src/validators/presence.cr","line_number":209,"url":null},"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 value String 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","args_html":"(value : String) : Bool","location":{"filename":"src/validators/presence.cr","line_number":200,"url":null},"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))","args_html":"(value, size : Array(String))","location":{"filename":"src/validators/comparisons.cr","line_number":122,"url":null},"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))","args_html":"(value, size : Array(Int))","location":{"filename":"src/validators/comparisons.cr","line_number":117,"url":null},"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)","args_html":"(value, size : Range)","location":{"filename":"src/validators/comparisons.cr","line_number":111,"url":null},"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)","args_html":"(value, size : String)","location":{"filename":"src/validators/comparisons.cr","line_number":105,"url":null},"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)","args_html":"(value, size : Int)","location":{"filename":"src/validators/comparisons.cr","line_number":100,"url":null},"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","args_html":"(value : String, min = 1, max = 100) : Bool","location":{"filename":"src/validators/uri.cr","line_number":174,"url":null},"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 String value 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","args_html":"(value : String, search : Char) : Bool","location":{"filename":"src/validators/presence.cr","line_number":226,"url":null},"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 String value 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","args_html":"(value : String, search : Regex) : Bool","location":{"filename":"src/validators/presence.cr","line_number":231,"url":null},"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 String value 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","args_html":"(value : String, search : String) : Bool","location":{"filename":"src/validators/presence.cr","line_number":221,"url":null},"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","args_html":"(value : String) : Bool","location":{"filename":"src/validators/format.cr","line_number":31,"url":null},"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","args_html":"(value : String) : Bool","location":{"filename":"src/validators/case_sensitive.cr","line_number":15,"url":null},"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","args_html":"(value : String) : Bool","location":{"filename":"src/validators/uri.cr","line_number":55,"url":null},"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","args_html":"(value : String, version = 0) : Bool","location":{"filename":"src/validators/format.cr","line_number":103,"url":null},"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":null}],"repository_name":"validator","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"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":"

    Used by is! when a validation is not true.

    ","class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[]}]}]}} \ No newline at end of file +{"repository_name":"validator","body":"# validator\n\n[![CI Status](https://github.com/Nicolab/crystal-validator/workflows/CI/badge.svg?branch=master)](https://github.com/Nicolab/crystal-validator/actions) [![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```\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\nThe validation rules can be defined directly when defining properties (with `getter` or `property`).\nOr with the macro `Check.rules`. Depending on preference, it's the same under the hood.\n\n```crystal\nrequire \"validator/check\"\n\nclass User\n # Mixin\n Check.checkable\n\n # required\n property email : String, {\n required: true,\n\n # Optional lifecycle hook to be executed on `check_email` call.\n # Before the `check` rules, just after `clean_email` called inside `check_email`.\n # Proc or method name (here is a Proc)\n before_check: ->(v : Check::Validation, content : String?, required : Bool, format : Bool) {\n puts \"before_check_content\"\n content\n },\n\n # Optional lifecycle hook to be executed on `check_email` call, after the `check` rules.\n # Proc or method name (here is the method name)\n after_check: :after_check_email\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) or method name (Symbol)\n format: :format_email,\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 property age : Int32, {\n required: \"Age is required\", # Custom message\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 property bio : String?, {\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 def initialize(@email, @age)\n end\n\n # ---------------------------------------------------------------------------\n # Lifecycle methods (hooks)\n # ---------------------------------------------------------------------------\n\n # Triggered on instance: `user.check`\n private def before_check(v : Check::Validation, required : Bool, format : Bool)\n # Code...\n end\n\n # Triggered on instance: `user.check`\n private 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 private 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 private 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 # Triggered on a static call and on instance call: `User.check_email(value)`, `User.check(h)`, `user.check`.\n private def self.after_check_content(v : Check::Validation, content : String?, required : Bool, format : Bool)\n puts \"after_check_content\"\n puts \"Valid? #{v.valid?}\"\n content\n end\n\n # --------------------------------------------------------------------------\n # Custom checkers\n # --------------------------------------------------------------------------\n\n # Triggered on instance: `user.check`\n @[Check::Checker]\n private def custom_checker(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 @[Check::Checker]\n private def self.custom_checker(v : Check::Validation, h, cleaned_h, required : Bool, format : Bool)\n # Code...\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 # ...\nend\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# Same but raise if there is a validation error\nuser_h = User.check!(input_h)\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# Same but raise if there is a validation error\nuser.check! # => Validation instance\n\n# Example with an active record model\nuser.check!.save\n\n# Check field\nv, email = User.check_email(value: \"demo@example.org\")\nv, age = User.check_age(value: 42)\n\n# Same but raise if there is a validation error\nemail = User.check_email!(value: \"demo@example.org\")\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# Same but raise if there is a validation error\nemail = 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# Same but raise if there is a validation error\nvalue1, 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# Same but raise if there is a validation error\n# Email value with one space before and one space after\nemail = 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./bin/ameba\n```\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":null,"aliased_html":null,"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)","location":{"filename":"src/is.cr","line_number":18,"url":null},"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)","location":{"filename":"src/is.cr","line_number":26,"url":null},"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":12,"url":null},{"filename":"src/checkable.cr","line_number":11,"url":null}],"repository_name":"validator","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[{"id":"RULES","name":"RULES","value":"{} of String => HashLiteral(String, ASTNode)","doc":null,"summary":null}],"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":"

    Initializes a new Validation instance to combine a series of checks (Validation#check).

    ","abstract":false,"args":[{"name":"errors","doc":null,"default_value":"","external_name":"errors","restriction":"Errors"}],"args_string":"(errors : Errors)","args_html":"(errors : Errors)","location":{"filename":"src/check.cr","line_number":378,"url":null},"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":"

    Initializes a new Validation instance to combine a series of checks (Validation#check).

    ","abstract":false,"args":[],"args_string":"","args_html":"","location":{"filename":"src/check.cr","line_number":354,"url":null},"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 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\n def initialize(@title, @content)\n end\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":"","location":{"filename":"src/checkable.cr","line_number":69,"url":null},"def":{"name":"checkable","args":[],"double_splat":null,"splat_index":null,"block_arg":null,"visibility":"Public","body":" include Check::Prop\n 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 private def self.after_check_content(v : Check::Validation, content : String?, required : Bool, format : Bool)\n puts \"after_check_content\"\n puts \"Valid? #{v.valid?}\"\n content\n end\n\n Check.rules(\n content: {\n required: \"Content is required\", # or `true` to use the default error message\n before_check: ->(v : Check::Validation, content : String?, required : Bool, format : Bool) {\n puts \"before_check_content\"\n content\n },\n after_check: :after_check_email,\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 # Proc or method name (Symbol)\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)","location":{"filename":"src/checkable.cr","line_number":168,"url":null},"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":" \n{% for field, rules in fields %}\n {% if RULES[\"#{@type.name}\"] %}{% else %}\n {% RULES[\"#{@type.name}\"] = {} of String => ASTNode %}\n {% end %}\n\n {% RULES[\"#{@type.name}\"][field] = rules %}\n {% end %}\n\n\n \n# Returns all validation rules.\n\n private def self.validation_rules\n \n{\n \n{% for field, rules in RULES[\"#{@type.name}\"] %}\n {{ field }}: {{ rules }},\n {% end %}\n\n }\n \nend\n\n \n# Returns `true` if a given *field* is required.\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) == false ? false : true\n \nend\n\n \n# Returns `true` if a given *field* is nilable.\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 # Same as `clean_{{ field }}` but this method raises a `Validator::Error`\n # if the clean has not been processed successfully.\n #\n # ```\n # email = MyCheckable.clean_email!(user_input[\"email\"]) # => user@example.com\n # ```\n def self.clean_{{ field }}!(value, format = true) : {{ type }}\n ok, value = self.clean_{{ field }}(value, format)\n raise Validator::Error.new %(Cannot clean the \"{{ field }}\" field) unless ok\n value.as({{ type }})\n end\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 = MyCheckable.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,\n {% if format.is_a?(SymbolLiteral) %}\n {{ format.id }}(value)\n {% else %}\n {{ format }}.call(value)\n {% end %}\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 # Checks *value* and returns it cleaned.\n # This method raises a `Check::ValidationError` if the validation fails.\n def self.check_{{ field }}!(*, value, required : Bool = true, format : Bool = true) : {{ type }}\n v, value = self.check_{{ field }}(value: value, required: required, format: format)\n raise v.to_exception unless v.valid?\n value.as({{ type }})\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 # Checks *value* and returns it cleaned.\n # This method raises a `Check::ValidationError` if the validation fails.\n def self.check_{{ field }}!(\n v : Check::Validation,\n value,\n required : Bool = true,\n format : Bool = true\n ) : {{ type }}\n v, value = self.check_{{ field }}(v, value, required, format)\n raise v.to_exception unless v.valid?\n value.as({{ type }})\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(\n {{ field.stringify }},\n {{ msg }}\n ) {% if nilable || (check[\"not_null\"].nil? && check[\"not_empty\"].nil?) %}unless value.nil?{% end %}\n\n return v, value\n end\n\n # Lifecycle: hook before_check_field\n {% if before_check = rules[\"before_check\"] %}\n {% if before_check.is_a?(SymbolLiteral) %}\n value = {{ before_check.id }}(v, value, required, format)\n {% else %}\n value = {{ before_check }}.call(v, value, required, format)\n {% end %}\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?\n {% end %}\n {% end %}\n\n # Lifecycle: hook after_check_field\n {% if after_check = rules[\"after_check\"] %}\n {% if after_check.is_a?(SymbolLiteral) %}\n value = {{ after_check.id }}(v, value, required, format)\n {% else %}\n value = {{ after_check }}.call(v, value, required, format)\n {% 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":568,"url":null}],"repository_name":"validator","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"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)","args_html":"(v : Check::Validation, required : Bool = true, format : Bool = true)","location":{"filename":"src/checkable.cr","line_number":591,"url":null},"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)","args_html":"(v : Check::Validation, required : Bool = true, format : Bool = true)","location":{"filename":"src/checkable.cr","line_number":577,"url":null},"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":"Same as `check` but this method raises a `Check::ValidationError`\nif the validation fails or if the clean has not been processed successfully.\n\n```\nmyCheckable.check! # => Returns the current instance.\n```\n\nThis method returns `self`, so it chainable :)\n\n```\nuser.email = \"me@example.org\"\nuser.check!.save\n```","summary":"

    Same as #check but this method raises a Check::ValidationError if the validation fails or if the clean has not been processed successfully.

    ","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","args_html":"(required : Bool = true, format : Bool = true) : Validation","location":{"filename":"src/checkable.cr","line_number":677,"url":null},"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","args_html":"(v : Check::Validation, required : Bool = true, format : Bool = true) : Validation","location":{"filename":"src/checkable.cr","line_number":628,"url":null},"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(&.annotation(Checker)) %}\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 %}"}},{"id":"check!(required:Bool=true,format:Bool=true):self-instance-method","html_id":"check!(required:Bool=true,format:Bool=true):self-instance-method","name":"check!","doc":"Same as `check` but this method raises a `Check::ValidationError`\nif the validation fails or if the clean has not been processed successfully.\n\n```\nmyCheckable.check! # => Returns the current instance.\n```\n\nThis method returns `self`, so it chainable :)\n\n```\nuser.email = \"me@example.org\"\nuser.check!.save\n```","summary":"

    Same as #check but this method raises a Check::ValidationError if the validation fails or if the clean has not been processed successfully.

    ","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) : self","args_html":"(required : Bool = true, format : Bool = true) : self","location":{"filename":"src/checkable.cr","line_number":670,"url":null},"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":"self","visibility":"Public","body":"v = check(required, format)\nif v.valid?\nelse\n raise(v.to_exception)\nend\nself\n"}},{"id":"check!(v:Check::Validation,required:Bool=true,format:Bool=true):self-instance-method","html_id":"check!(v:Check::Validation,required:Bool=true,format:Bool=true):self-instance-method","name":"check!","doc":"Same as `check` but this method raises a `Check::ValidationError`\nif the validation fails or if the clean has not been processed successfully.\n\n```\nv = Validation.new_validation\nmyCheckable.check!(v) # => Returns the current instance.\n```\n\nThis method returns `self`, so it chainable :)\n\n```\nv = Validation.new_validation\nuser.email = \"me@example.org\"\nuser.check!(v).save\n```","summary":"

    Same as #check but this method raises a Check::ValidationError if the validation fails or if the clean has not been processed successfully.

    ","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) : self","args_html":"(v : Check::Validation, required : Bool = true, format : Bool = true) : self","location":{"filename":"src/checkable.cr","line_number":612,"url":null},"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":"self","visibility":"Public","body":"v = check(v, required, format)\nif v.valid?\nelse\n raise(v.to_exception)\nend\nself\n"}}],"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":372,"url":null}],"repository_name":"validator","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"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","args_html":"(v : Check::Validation, h : Hash, cleaned_h : Hash, required : Bool = true, format : Bool = true) : Hash","location":{"filename":"src/checkable.cr","line_number":462,"url":null},"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)","args_html":"(v : Check::Validation, h : Hash, required : Bool = true, format : Bool = true)","location":{"filename":"src/checkable.cr","line_number":441,"url":null},"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)","args_html":"(v : Check::Validation, h : Hash, required : Bool = true, format : Bool = true)","location":{"filename":"src/checkable.cr","line_number":494,"url":null},"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\n if h.has_key?({{ field_name }})\n v, value = self.check_{{ field }}(v, h[{{ field_name }}]?, required, format)\n cleaned_h[{{ field_name }}] = value.as({{ types[i] }})\n\n # or if this field MUST be checked when required\n elsif required && self.validation_required?({{ field_name }})\n required_msg = self.validation_rules[{{ field_name }}].fetch(:required, nil)\n\n msg = if required_msg && required_msg.is_a?(String)\n required_msg.as(String)\n else\n \"This field is required\"\n end\n\n v.add_error {{ field_name }}, msg\n end\n {% end %}\n\n # Check methods with `Check::Checker` annotation\n {% for method in @type.class.methods.select(&.annotation(Checker)) %}\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":"Same as `check` but this method raises a `Check::ValidationError`\nif the validation fails or if the clean has not been processed successfully.\n\n```\ncleaned_h = MyCheckable.check!(h)\n```","summary":"

    Same as #check but this method raises a Check::ValidationError if the validation fails or if the clean has not been processed successfully.

    ","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)","args_html":"(h : Hash, required : Bool = true, format : Bool = true)","location":{"filename":"src/checkable.cr","line_number":559,"url":null},"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":"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":"Same as `check` but this method raises a `Check::ValidationError`\nif the validation fails or if the clean has not been processed successfully.\n\n```\ncleaned_h = MyCheckable.check!(v, h)\n```","summary":"

    Same as #check but this method raises a Check::ValidationError if the validation fails or if the clean has not been processed successfully.

    ","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)","args_html":"(v : Check::Validation, h : Hash, required : Bool = true, format : Bool = true)","location":{"filename":"src/checkable.cr","line_number":477,"url":null},"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":"v, cleaned_h = check(v, h, required, format)\nif v.valid?\nelse\n raise(v.to_exception)\nend\ncleaned_h\n"}},{"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":"Same as `check` but this method raises a `Check::ValidationError`\nif the validation fails or if the clean has not been processed successfully.\n\n```\ncleaned_h = MyCheckable.check!(h)\n```","summary":"

    Same as #check but this method raises a Check::ValidationError if the validation fails or if the clean has not been processed successfully.

    ","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)","args_html":"(h : Hash, required : Bool = true, format : Bool = true)","location":{"filename":"src/checkable.cr","line_number":552,"url":null},"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, cleaned_h = check(h, required, format)\nif v.valid?\nelse\n raise(v.to_exception)\nend\ncleaned_h\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 *json* `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 json 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)","args_html":"(json : String | IO)","location":{"filename":"src/checkable.cr","line_number":416,"url":null},"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":"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 *json* `Hash` from a JSON input.\nSame as `h_from_json`, except that this method raises a `JSON::ParseException` if the conversion fails.\n\n```\nuser_h = User.h_from_json!(json) # => {\"username\" => \"Bob\", \"email\" => \"user@example.com\"}\n```","summary":"

    Returns a json 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)","args_html":"(json : String | IO)","location":{"filename":"src/checkable.cr","line_number":428,"url":null},"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":"self.to_crystal_h((JSON.parse(json)).as_h)"}},{"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)","args_html":" : Hash(String, String)","location":{"filename":"src/checkable.cr","line_number":374,"url":null},"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","args_html":"(h : Hash) : Hash","location":{"filename":"src/checkable.cr","line_number":389,"url":null},"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","args_html":"(h : Hash) : Hash","location":{"filename":"src/checkable.cr","line_number":399,"url":null},"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":30,"url":null}],"repository_name":"validator","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"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":20,"url":null}],"repository_name":"validator","program":false,"enum":false,"alias":true,"aliased":"Hash(String | Symbol, Array(String))","aliased_html":"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/Prop","path":"Check/Prop.html","kind":"module","full_name":"Check::Prop","name":"Prop","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/checkable.cr","line_number":77,"url":null}],"repository_name":"validator","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"validator/Check","kind":"module","full_name":"Check","name":"Check"},"doc":"A mixin to make the `getter` macro of the Crystal std's,\nable to support the rules definition and factory block.","summary":"

    A mixin to make the getter macro of the Crystal std's, able to support the rules definition and factory block.

    ","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":153,"url":null}],"repository_name":"validator","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"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 errors Hash (Check::Errors).

    ","abstract":false,"args":[{"name":"errors","doc":null,"default_value":"","external_name":"errors","restriction":"Errors"}],"args_string":"(errors : Errors)","args_html":"(errors : Errors)","location":{"filename":"src/check.cr","line_number":182,"url":null},"def":{"name":"new","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":"_ = allocate\n_.initialize(errors)\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}},{"id":"new-class-method","html_id":"new-class-method","name":"new","doc":"Initializes a validation.\n\n```\nv = Check::Validation.new\n```\n\nSame as:\n\n```\nv = Check.new_validation\n```","summary":"

    Initializes a validation.

    ","abstract":false,"args":[],"args_string":"","args_html":"","location":{"filename":"src/check.cr","line_number":167,"url":null},"def":{"name":"new","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"_ = allocate\n_.initialize\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}}],"instance_methods":[{"id":"add_error(key:Symbol|String,message:String):Validation-instance-method","html_id":"add_error(key:Symbol|String,message:String):Validation-instance-method","name":"add_error","doc":"Add a validation error.\n\n```\nv = Check.new_validation\nv.add_error(:foo, \"Foo error!\")\npp v.errors # => {:foo => [\"Foo error!\"]}\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"},{"name":"message","doc":null,"default_value":"","external_name":"message","restriction":"String"}],"args_string":"(key : Symbol | String, message : String) : Validation","args_html":"(key : Symbol | String, message : String) : Validation","location":{"filename":"src/check.cr","line_number":205,"url":null},"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","args_html":"(key : Symbol | String) : Validation","location":{"filename":"src/check.cr","line_number":225,"url":null},"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","args_html":"(key : Symbol | String, message : String, valid : Bool) : Validation","location":{"filename":"src/check.cr","line_number":273,"url":null},"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","args_html":"(key : Symbol | String, valid : Bool, message : String) : Validation","location":{"filename":"src/check.cr","line_number":310,"url":null},"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":"

    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"}],"args_string":"(key : Symbol | String, valid : Bool) : Validation","args_html":"(key : Symbol | String, valid : Bool) : Validation","location":{"filename":"src/check.cr","line_number":331,"url":null},"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"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Validation","visibility":"Public","body":"if valid\nelse\n add_error(key, \"\")\nend\nself\n"}},{"id":"errors:Errors-instance-method","html_id":"errors:Errors-instance-method","name":"errors","doc":"Errors container.\n\n```\nv = Check.new_validation\npp v.errors\n```","summary":"

    Errors container.

    ","abstract":false,"args":[],"args_string":" : Errors","args_html":" : Errors","location":{"filename":"src/check.cr","line_number":192,"url":null},"def":{"name":"errors","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Errors","visibility":"Public","body":"@errors"}},{"id":"to_exception-instance-method","html_id":"to_exception-instance-method","name":"to_exception","doc":"Creates a new instance of `ValidationError` (`Exception`).","summary":"

    Creates a new instance of ValidationError (Exception).

    ","abstract":false,"args":[],"args_string":"","args_html":"","location":{"filename":"src/check.cr","line_number":337,"url":null},"def":{"name":"to_exception","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"ValidationError.new(@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":"","args_html":"","location":{"filename":"src/check.cr","line_number":237,"url":null},"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/Check/ValidationError","path":"Check/ValidationError.html","kind":"class","full_name":"Check::ValidationError","name":"ValidationError","abstract":false,"superclass":{"html_id":"validator/Validator/Error","kind":"class","full_name":"Validator::Error","name":"Error"},"ancestors":[{"html_id":"validator/Validator/Error","kind":"class","full_name":"Validator::Error","name":"Error"},{"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/check.cr","line_number":24,"url":null}],"repository_name":"validator","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"validator/Check","kind":"module","full_name":"Check","name":"Check"},"doc":"Validation error.\nTo carry `Errors` into an `Exception`.","summary":"

    Validation error.

    ","class_methods":[],"constructors":[{"id":"new(errors:Errors,message="Validationerror")-class-method","html_id":"new(errors:Errors,message="Validationerror")-class-method","name":"new","doc":null,"summary":null,"abstract":false,"args":[{"name":"errors","doc":null,"default_value":"","external_name":"errors","restriction":"Errors"},{"name":"message","doc":null,"default_value":"\"Validation error\"","external_name":"message","restriction":""}],"args_string":"(errors : Errors, message = "Validation error")","args_html":"(errors : Errors, message = "Validation error")","location":{"filename":"src/check.cr","line_number":25,"url":null},"def":{"name":"new","args":[{"name":"errors","doc":null,"default_value":"","external_name":"errors","restriction":"Errors"},{"name":"message","doc":null,"default_value":"\"Validation error\"","external_name":"message","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"_ = allocate\n_.initialize(errors, message)\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}}],"instance_methods":[{"id":"errors:Errors-instance-method","html_id":"errors:Errors-instance-method","name":"errors","doc":"Returns `Errors` container (`Hash`).","summary":"

    Returns Errors container (Hash).

    ","abstract":false,"args":[],"args_string":" : Errors","args_html":" : Errors","location":{"filename":"src/check.cr","line_number":30,"url":null},"def":{"name":"errors","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Errors","visibility":"Public","body":"@errors"}}],"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":null}],"repository_name":"validator","program":false,"enum":false,"alias":true,"aliased":"Validator","aliased_html":"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":"

    Alias of Validator

    ","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":null},{"filename":"src/validators/alpha_num.cr","line_number":8,"url":null},{"filename":"src/validators/case_sensitive.cr","line_number":8,"url":null},{"filename":"src/validators/comparisons.cr","line_number":8,"url":null},{"filename":"src/validators/format.cr","line_number":8,"url":null},{"filename":"src/validators/geo.cr","line_number":8,"url":null},{"filename":"src/validators/presence.cr","line_number":8,"url":null},{"filename":"src/validators/uri.cr","line_number":8,"url":null}],"repository_name":"validator","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"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```\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```\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","args_html":"(key : String | Symbol, list : NamedTuple) : Bool","location":{"filename":"src/validators/presence.cr","line_number":47,"url":null},"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","args_html":"(key : String | Symbol | Number, list : Hash) : Bool","location":{"filename":"src/validators/presence.cr","line_number":42,"url":null},"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 value String 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","args_html":"(value : String) : Bool","location":{"filename":"src/validators/presence.cr","line_number":180,"url":null},"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","args_html":"(value) : Bool","location":{"filename":"src/validators/presence.cr","line_number":189,"url":null},"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 value String 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","args_html":"(value : String) : Bool","location":{"filename":"src/validators/format.cr","line_number":41,"url":null},"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 values Array 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","args_html":"(values : Array(String)) : Bool","location":{"filename":"src/validators/format.cr","line_number":47,"url":null},"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","args_html":"(value : String) : Bool","location":{"filename":"src/validators/format.cr","line_number":87,"url":null},"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","args_html":"(value, min, max) : Bool","location":{"filename":"src/validators/comparisons.cr","line_number":87,"url":null},"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","args_html":"(value : String | Array, min : Int, max : Int) : Bool","location":{"filename":"src/validators/comparisons.cr","line_number":94,"url":null},"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","args_html":"(value : String) : Bool","location":{"filename":"src/validators/uri.cr","line_number":26,"url":null},"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","args_html":"(value : String) : Bool","location":{"filename":"src/validators/uri.cr","line_number":161,"url":null},"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","args_html":"(value) : Bool","location":{"filename":"src/validators/presence.cr","line_number":58,"url":null},"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 String value 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","args_html":"(value : String, search : String) : Bool","location":{"filename":"src/validators/presence.cr","line_number":243,"url":null},"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 String value 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","args_html":"(value : String, search : Char) : Bool","location":{"filename":"src/validators/presence.cr","line_number":248,"url":null},"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 String value 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","args_html":"(value : String, search : Regex) : Bool","location":{"filename":"src/validators/presence.cr","line_number":253,"url":null},"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","args_html":"(value, another_value) : Bool","location":{"filename":"src/validators/comparisons.cr","line_number":10,"url":null},"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","args_html":"(value, another_value) : Bool","location":{"filename":"src/validators/comparisons.cr","line_number":15,"url":null},"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","args_html":"(value : String | Array, limit : Int) : Bool","location":{"filename":"src/validators/comparisons.cr","line_number":21,"url":null},"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","args_html":"(value, another_value) : Bool","location":{"filename":"src/validators/comparisons.cr","line_number":27,"url":null},"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","args_html":"(value : String | Array, min : Int) : Bool","location":{"filename":"src/validators/comparisons.cr","line_number":34,"url":null},"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 String value 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","args_html":"(value : String) : Bool","location":{"filename":"src/validators/format.cr","line_number":112,"url":null},"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 Bytes value 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","args_html":"(value : Bytes) : Bool","location":{"filename":"src/validators/format.cr","line_number":118,"url":null},"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 String value 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","args_html":"(value : String) : Bool","location":{"filename":"src/validators/format.cr","line_number":129,"url":null},"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","args_html":"(value, list : Array) : Bool","location":{"filename":"src/validators/presence.cr","line_number":109,"url":null},"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","args_html":"(value : String, str : String) : Bool","location":{"filename":"src/validators/presence.cr","line_number":101,"url":null},"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","args_html":"(key : Symbol | String, list : Hash) : Bool","location":{"filename":"src/validators/presence.cr","line_number":129,"url":null},"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","args_html":"(key : Symbol | String, list : NamedTuple) : Bool","location":{"filename":"src/validators/presence.cr","line_number":124,"url":null},"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","args_html":"(value, list : Range) : Bool","location":{"filename":"src/validators/presence.cr","line_number":119,"url":null},"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","args_html":"(value, list : Tuple) : Bool","location":{"filename":"src/validators/presence.cr","line_number":114,"url":null},"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","args_html":"(value : String) : Bool","location":{"filename":"src/validators/uri.cr","line_number":80,"url":null},"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","args_html":"(value : String) : Bool","location":{"filename":"src/validators/uri.cr","line_number":85,"url":null},"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","args_html":"(value : String) : Bool","location":{"filename":"src/validators/uri.cr","line_number":90,"url":null},"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","args_html":"(value : String, strict : Bool = true) : Bool","location":{"filename":"src/validators/format.cr","line_number":64,"url":null},"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","args_html":"(value : String) : Bool","location":{"filename":"src/validators/format.cr","line_number":95,"url":null},"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","args_html":"(value : String | Float) : Bool","location":{"filename":"src/validators/geo.cr","line_number":31,"url":null},"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","args_html":"(value : String) : Bool","location":{"filename":"src/validators/geo.cr","line_number":16,"url":null},"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","args_html":"(value : String | Float) : Bool","location":{"filename":"src/validators/geo.cr","line_number":38,"url":null},"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","args_html":"(value : String) : Bool","location":{"filename":"src/validators/case_sensitive.cr","line_number":10,"url":null},"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","args_html":"(value : String | Array, limit : Int) : Bool","location":{"filename":"src/validators/comparisons.cr","line_number":45,"url":null},"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","args_html":"(value, another_value) : Bool","location":{"filename":"src/validators/comparisons.cr","line_number":39,"url":null},"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","args_html":"(value : String | Array, max : Int) : Bool","location":{"filename":"src/validators/comparisons.cr","line_number":58,"url":null},"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","args_html":"(value, another_value) : Bool","location":{"filename":"src/validators/comparisons.cr","line_number":51,"url":null},"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","args_html":"(value : String, no_colons : Bool = false) : Bool","location":{"filename":"src/validators/uri.cr","line_number":179,"url":null},"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","args_html":"(value : String) : Bool","location":{"filename":"src/validators/uri.cr","line_number":189,"url":null},"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","args_html":"(value : Number, pattern : Regex) : Bool","location":{"filename":"src/validators/presence.cr","line_number":15,"url":null},"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","args_html":"(value : String, pattern : Regex) : Bool","location":{"filename":"src/validators/presence.cr","line_number":10,"url":null},"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","args_html":"(value, max) : Bool","location":{"filename":"src/validators/comparisons.cr","line_number":76,"url":null},"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","args_html":"(value : String | Array, max : Int) : Bool","location":{"filename":"src/validators/comparisons.cr","line_number":82,"url":null},"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","args_html":"(value : String) : Bool","location":{"filename":"src/validators/format.cr","line_number":82,"url":null},"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","args_html":"(value, min) : Bool","location":{"filename":"src/validators/comparisons.cr","line_number":64,"url":null},"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","args_html":"(value : String | Array, min : Int) : Bool","location":{"filename":"src/validators/comparisons.cr","line_number":70,"url":null},"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 Bytes value 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","args_html":"(value : Bytes) : Bool","location":{"filename":"src/validators/format.cr","line_number":143,"url":null},"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 String value 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","args_html":"(value : String) : Bool","location":{"filename":"src/validators/format.cr","line_number":137,"url":null},"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","args_html":"(value) : Bool","location":{"filename":"src/validators/presence.cr","line_number":71,"url":null},"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","args_html":"(value : String, str : String) : Bool","location":{"filename":"src/validators/presence.cr","line_number":141,"url":null},"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","args_html":"(value, list : Array) : Bool","location":{"filename":"src/validators/presence.cr","line_number":149,"url":null},"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","args_html":"(value, list : Tuple) : Bool","location":{"filename":"src/validators/presence.cr","line_number":154,"url":null},"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","args_html":"(value, list : Range) : Bool","location":{"filename":"src/validators/presence.cr","line_number":159,"url":null},"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","args_html":"(key : Symbol | String, list : NamedTuple) : Bool","location":{"filename":"src/validators/presence.cr","line_number":164,"url":null},"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","args_html":"(key : Symbol | String, list : Hash) : Bool","location":{"filename":"src/validators/presence.cr","line_number":169,"url":null},"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","args_html":"(value) : Bool","location":{"filename":"src/validators/presence.cr","line_number":89,"url":null},"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","args_html":"(value) : Bool","location":{"filename":"src/validators/presence.cr","line_number":82,"url":null},"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","args_html":"(value : String) : Bool","location":{"filename":"src/validators/alpha_num.cr","line_number":12,"url":null},"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","args_html":"(value : String = "0", min : String = "1", max : String = "65535") : Bool","location":{"filename":"src/validators/uri.cr","line_number":47,"url":null},"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","args_html":"(value = 0, min = 1, max = 65535) : Bool","location":{"filename":"src/validators/uri.cr","line_number":41,"url":null},"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","args_html":"(key : String | Symbol, list : NamedTuple) : Bool","location":{"filename":"src/validators/presence.cr","line_number":31,"url":null},"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","args_html":"(key : String | Symbol | Number, list : Hash) : Bool","location":{"filename":"src/validators/presence.cr","line_number":26,"url":null},"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","args_html":"(value) : Bool","location":{"filename":"src/validators/presence.cr","line_number":209,"url":null},"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 value String 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","args_html":"(value : String) : Bool","location":{"filename":"src/validators/presence.cr","line_number":200,"url":null},"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))","args_html":"(value, size : Array(String))","location":{"filename":"src/validators/comparisons.cr","line_number":122,"url":null},"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))","args_html":"(value, size : Array(Int))","location":{"filename":"src/validators/comparisons.cr","line_number":117,"url":null},"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)","args_html":"(value, size : Range)","location":{"filename":"src/validators/comparisons.cr","line_number":111,"url":null},"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)","args_html":"(value, size : String)","location":{"filename":"src/validators/comparisons.cr","line_number":105,"url":null},"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)","args_html":"(value, size : Int)","location":{"filename":"src/validators/comparisons.cr","line_number":100,"url":null},"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","args_html":"(value : String, min = 1, max = 100) : Bool","location":{"filename":"src/validators/uri.cr","line_number":174,"url":null},"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 String value 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","args_html":"(value : String, search : Char) : Bool","location":{"filename":"src/validators/presence.cr","line_number":226,"url":null},"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 String value 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","args_html":"(value : String, search : Regex) : Bool","location":{"filename":"src/validators/presence.cr","line_number":231,"url":null},"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 String value 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","args_html":"(value : String, search : String) : Bool","location":{"filename":"src/validators/presence.cr","line_number":221,"url":null},"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","args_html":"(value : String) : Bool","location":{"filename":"src/validators/format.cr","line_number":31,"url":null},"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","args_html":"(value : String) : Bool","location":{"filename":"src/validators/case_sensitive.cr","line_number":15,"url":null},"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","args_html":"(value : String) : Bool","location":{"filename":"src/validators/uri.cr","line_number":55,"url":null},"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","args_html":"(value : String, version = 0) : Bool","location":{"filename":"src/validators/format.cr","line_number":103,"url":null},"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":null}],"repository_name":"validator","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[{"html_id":"validator/Check/ValidationError","kind":"class","full_name":"Check::ValidationError","name":"ValidationError"}],"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":"

    Used by is! when a validation is not true.

    ","class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[]}]}]}} \ No newline at end of file diff --git a/docs/search-index.js b/docs/search-index.js index 85851a9..5b398cf 100644 --- a/docs/search-index.js +++ b/docs/search-index.js @@ -1 +1 @@ -crystal_doc_search_index_callback({"repository_name":"validator","body":"# validator\n\n[![CI Status](https://github.com/Nicolab/crystal-validator/workflows/CI/badge.svg?branch=master)](https://github.com/Nicolab/crystal-validator/actions) [![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```\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\nThe validation rules can be defined directly when defining properties (with `getter` or `property`).\nOr with the macro `Check.rules`. Depending on preference, it's the same under the hood.\n\n```crystal\nrequire \"validator/check\"\n\nclass User\n # Mixin\n Check.checkable\n\n # required\n property email : String, {\n required: true,\n\n # Optional lifecycle hook to be executed on `check_email` call.\n # Before the `check` rules, just after `clean_email` called inside `check_email`.\n # Proc or method name (here is a Proc)\n before_check: ->(v : Check::Validation, content : String?, required : Bool, format : Bool) {\n puts \"before_check_content\"\n content\n },\n\n # Optional lifecycle hook to be executed on `check_email` call, after the `check` rules.\n # Proc or method name (here is the method name)\n after_check: :after_check_email\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) or method name (Symbol)\n format: :format_email,\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 property age : Int32, {\n required: \"Age is required\", # Custom message\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 property bio : String?, {\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 def initialize(@email, @age)\n end\n\n # ---------------------------------------------------------------------------\n # Lifecycle methods (hooks)\n # ---------------------------------------------------------------------------\n\n # Triggered on instance: `user.check`\n private def before_check(v : Check::Validation, required : Bool, format : Bool)\n # Code...\n end\n\n # Triggered on instance: `user.check`\n private 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 private 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 private 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 # Triggered on a static call and on instance call: `User.check_email(value)`, `User.check(h)`, `user.check`.\n private def self.after_check_content(v : Check::Validation, content : String?, required : Bool, format : Bool)\n puts \"after_check_content\"\n puts \"Valid? #{v.valid?}\"\n content\n end\n\n # --------------------------------------------------------------------------\n # Custom checkers\n # --------------------------------------------------------------------------\n\n # Triggered on instance: `user.check`\n @[Check::Checker]\n private def custom_checker(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 @[Check::Checker]\n private def self.custom_checker(v : Check::Validation, h, cleaned_h, required : Bool, format : Bool)\n # Code...\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 # ...\nend\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# Same but raise if there is a validation error\nuser_h = User.check!(input_h)\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# Same but raise if there is a validation error\nuser.check! # => Validation instance\n\n# Example with an active record model\nuser.check!.save\n\n# Check field\nv, email = User.check_email(value: \"demo@example.org\")\nv, age = User.check_age(value: 42)\n\n# Same but raise if there is a validation error\nemail = User.check_email!(value: \"demo@example.org\")\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# Same but raise if there is a validation error\nemail = 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# Same but raise if there is a validation error\nvalue1, 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# Same but raise if there is a validation error\n# Email value with one space before and one space after\nemail = 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./bin/ameba\n```\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":null,"aliased_html":null,"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)","location":{"filename":"src/is.cr","line_number":18,"url":null},"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)","location":{"filename":"src/is.cr","line_number":26,"url":null},"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":null},{"filename":"src/checkable.cr","line_number":11,"url":null}],"repository_name":"validator","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[{"id":"RULES","name":"RULES","value":"{} of String => HashLiteral(String, ASTNode)","doc":null,"summary":null}],"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":"

    Initializes a new Validation instance to combine a series of checks (Validation#check).

    ","abstract":false,"args":[{"name":"errors","doc":null,"default_value":"","external_name":"errors","restriction":"Errors"}],"args_string":"(errors : Errors)","args_html":"(errors : Errors)","location":{"filename":"src/check.cr","line_number":377,"url":null},"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":"

    Initializes a new Validation instance to combine a series of checks (Validation#check).

    ","abstract":false,"args":[],"args_string":"","args_html":"","location":{"filename":"src/check.cr","line_number":353,"url":null},"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 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\n def initialize(@title, @content)\n end\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":"","location":{"filename":"src/checkable.cr","line_number":69,"url":null},"def":{"name":"checkable","args":[],"double_splat":null,"splat_index":null,"block_arg":null,"visibility":"Public","body":" include Check::Prop\n 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 private def self.after_check_content(v : Check::Validation, content : String?, required : Bool, format : Bool)\n puts \"after_check_content\"\n puts \"Valid? #{v.valid?}\"\n content\n end\n\n Check.rules(\n content: {\n required: \"Content is required\", # or `true` to use the default error message\n before_check: ->(v : Check::Validation, content : String?, required : Bool, format : Bool) {\n puts \"before_check_content\"\n content\n },\n after_check: :after_check_email,\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 # Proc or method name (Symbol)\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)","location":{"filename":"src/checkable.cr","line_number":168,"url":null},"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":" \n{% for field, rules in fields %}\n {% if RULES[\"#{@type.name}\"] %}{% else %}\n {% RULES[\"#{@type.name}\"] = {} of String => ASTNode %}\n {% end %}\n\n {% RULES[\"#{@type.name}\"][field] = rules %}\n {% end %}\n\n\n \n# Returns all validation rules.\n\n private def self.validation_rules\n \n{\n \n{% for field, rules in RULES[\"#{@type.name}\"] %}\n {{ field }}: {{ rules }},\n {% end %}\n\n }\n \nend\n\n \n# Returns `true` if a given *field* is required.\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) == false ? false : true\n \nend\n\n \n# Returns `true` if a given *field* is nilable.\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 # Same as `clean_{{ field }}` but this method raises a `Validator::Error`\n # if the clean has not been processed successfully.\n #\n # ```\n # email = MyCheckable.clean_email!(user_input[\"email\"]) # => user@example.com\n # ```\n def self.clean_{{ field }}!(value, format = true) : {{ type }}\n ok, value = self.clean_{{ field }}(value, format)\n raise Validator::Error.new %(Cannot clean the \"{{ field }}\" field) unless ok\n value.as({{ type }})\n end\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 = MyCheckable.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,\n {% if format.is_a?(SymbolLiteral) %}\n {{ format.id }}(value)\n {% else %}\n {{ format }}.call(value)\n {% end %}\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 # Checks *value* and returns it cleaned.\n # This method raises a `Check::ValidationError` if the validation fails.\n def self.check_{{ field }}!(*, value, required : Bool = true, format : Bool = true) : {{ type }}\n v, value = self.check_{{ field }}(value: value, required: required, format: format)\n raise v.to_exception unless v.valid?\n value.as({{ type }})\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 # Checks *value* and returns it cleaned.\n # This method raises a `Check::ValidationError` if the validation fails.\n def self.check_{{ field }}!(\n v : Check::Validation,\n value,\n required : Bool = true,\n format : Bool = true\n ) : {{ type }}\n v, value = self.check_{{ field }}(v, value, required, format)\n raise v.to_exception unless v.valid?\n value.as({{ type }})\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(\n {{ field.stringify }},\n {{ msg }}\n ) {% if nilable || (check[\"not_null\"].nil? && check[\"not_empty\"].nil?) %}unless value.nil?{% end %}\n\n return v, value\n end\n\n # Lifecycle: hook before_check_field\n {% if before_check = rules[\"before_check\"] %}\n {% if before_check.is_a?(SymbolLiteral) %}\n value = {{ before_check.id }}(v, value, required, format)\n {% else %}\n value = {{ before_check }}.call(v, value, required, format)\n {% end %}\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?\n {% end %}\n {% end %}\n\n # Lifecycle: hook after_check_field\n {% if after_check = rules[\"after_check\"] %}\n {% if after_check.is_a?(SymbolLiteral) %}\n value = {{ after_check.id }}(v, value, required, format)\n {% else %}\n value = {{ after_check }}.call(v, value, required, format)\n {% 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":558,"url":null}],"repository_name":"validator","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"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)","args_html":"(v : Check::Validation, required : Bool = true, format : Bool = true)","location":{"filename":"src/checkable.cr","line_number":581,"url":null},"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)","args_html":"(v : Check::Validation, required : Bool = true, format : Bool = true)","location":{"filename":"src/checkable.cr","line_number":567,"url":null},"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":"Same as `check` but this method raises a `Check::ValidationError`\nif the validation fails or if the clean has not been processed successfully.\n\n```\nmyCheckable.check! # => Returns the current instance.\n```\n\nThis method returns `self`, so it chainable :)\n\n```\nuser.email = \"me@example.org\"\nuser.check!.save\n```","summary":"

    Same as #check but this method raises a Check::ValidationError if the validation fails or if the clean has not been processed successfully.

    ","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","args_html":"(required : Bool = true, format : Bool = true) : Validation","location":{"filename":"src/checkable.cr","line_number":667,"url":null},"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","args_html":"(v : Check::Validation, required : Bool = true, format : Bool = true) : Validation","location":{"filename":"src/checkable.cr","line_number":618,"url":null},"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(&.annotation(Checker)) %}\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 %}"}},{"id":"check!(required:Bool=true,format:Bool=true):self-instance-method","html_id":"check!(required:Bool=true,format:Bool=true):self-instance-method","name":"check!","doc":"Same as `check` but this method raises a `Check::ValidationError`\nif the validation fails or if the clean has not been processed successfully.\n\n```\nmyCheckable.check! # => Returns the current instance.\n```\n\nThis method returns `self`, so it chainable :)\n\n```\nuser.email = \"me@example.org\"\nuser.check!.save\n```","summary":"

    Same as #check but this method raises a Check::ValidationError if the validation fails or if the clean has not been processed successfully.

    ","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) : self","args_html":"(required : Bool = true, format : Bool = true) : self","location":{"filename":"src/checkable.cr","line_number":660,"url":null},"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":"self","visibility":"Public","body":"v = check(required, format)\nif v.valid?\nelse\n raise(v.to_exception)\nend\nself\n"}},{"id":"check!(v:Check::Validation,required:Bool=true,format:Bool=true):self-instance-method","html_id":"check!(v:Check::Validation,required:Bool=true,format:Bool=true):self-instance-method","name":"check!","doc":"Same as `check` but this method raises a `Check::ValidationError`\nif the validation fails or if the clean has not been processed successfully.\n\n```\nv = Validation.new_validation\nmyCheckable.check!(v) # => Returns the current instance.\n```\n\nThis method returns `self`, so it chainable :)\n\n```\nv = Validation.new_validation\nuser.email = \"me@example.org\"\nuser.check!(v).save\n```","summary":"

    Same as #check but this method raises a Check::ValidationError if the validation fails or if the clean has not been processed successfully.

    ","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) : self","args_html":"(v : Check::Validation, required : Bool = true, format : Bool = true) : self","location":{"filename":"src/checkable.cr","line_number":602,"url":null},"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":"self","visibility":"Public","body":"v = check(v, required, format)\nif v.valid?\nelse\n raise(v.to_exception)\nend\nself\n"}}],"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":372,"url":null}],"repository_name":"validator","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"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","args_html":"(v : Check::Validation, h : Hash, cleaned_h : Hash, required : Bool = true, format : Bool = true) : Hash","location":{"filename":"src/checkable.cr","line_number":452,"url":null},"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)","args_html":"(v : Check::Validation, h : Hash, required : Bool = true, format : Bool = true)","location":{"filename":"src/checkable.cr","line_number":431,"url":null},"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)","args_html":"(v : Check::Validation, h : Hash, required : Bool = true, format : Bool = true)","location":{"filename":"src/checkable.cr","line_number":484,"url":null},"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\n if h.has_key?({{ field_name }})\n v, value = self.check_{{ field }}(v, h[{{ field_name }}]?, required, format)\n cleaned_h[{{ field_name }}] = value.as({{ types[i] }})\n\n # or if this field MUST be checked when required\n elsif required && self.validation_required?({{ field_name }})\n required_msg = self.validation_rules[{{ field_name }}].fetch(:required, nil)\n\n msg = if required_msg && required_msg.is_a?(String)\n required_msg.as(String)\n else\n \"This field is required\"\n end\n\n v.add_error {{ field_name }}, msg\n end\n {% end %}\n\n # Check methods with `Check::Checker` annotation\n {% for method in @type.class.methods.select(&.annotation(Checker)) %}\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":"Same as `check` but this method raises a `Check::ValidationError`\nif the validation fails or if the clean has not been processed successfully.\n\n```\ncleaned_h = MyCheckable.check!(h)\n```","summary":"

    Same as #check but this method raises a Check::ValidationError if the validation fails or if the clean has not been processed successfully.

    ","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)","args_html":"(h : Hash, required : Bool = true, format : Bool = true)","location":{"filename":"src/checkable.cr","line_number":549,"url":null},"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":"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":"Same as `check` but this method raises a `Check::ValidationError`\nif the validation fails or if the clean has not been processed successfully.\n\n```\ncleaned_h = MyCheckable.check!(v, h)\n```","summary":"

    Same as #check but this method raises a Check::ValidationError if the validation fails or if the clean has not been processed successfully.

    ","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)","args_html":"(v : Check::Validation, h : Hash, required : Bool = true, format : Bool = true)","location":{"filename":"src/checkable.cr","line_number":467,"url":null},"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":"v, cleaned_h = check(v, h, required, format)\nif v.valid?\nelse\n raise(v.to_exception)\nend\ncleaned_h\n"}},{"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":"Same as `check` but this method raises a `Check::ValidationError`\nif the validation fails or if the clean has not been processed successfully.\n\n```\ncleaned_h = MyCheckable.check!(h)\n```","summary":"

    Same as #check but this method raises a Check::ValidationError if the validation fails or if the clean has not been processed successfully.

    ","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)","args_html":"(h : Hash, required : Bool = true, format : Bool = true)","location":{"filename":"src/checkable.cr","line_number":542,"url":null},"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, cleaned_h = check(h, required, format)\nif v.valid?\nelse\n raise(v.to_exception)\nend\ncleaned_h\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)","args_html":"(json : String | IO)","location":{"filename":"src/checkable.cr","line_number":416,"url":null},"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)","args_html":" : Hash(String, String)","location":{"filename":"src/checkable.cr","line_number":374,"url":null},"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","args_html":"(h : Hash) : Hash","location":{"filename":"src/checkable.cr","line_number":389,"url":null},"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","args_html":"(h : Hash) : Hash","location":{"filename":"src/checkable.cr","line_number":399,"url":null},"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":30,"url":null}],"repository_name":"validator","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"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":null}],"repository_name":"validator","program":false,"enum":false,"alias":true,"aliased":"Hash(String | Symbol, Array(String))","aliased_html":"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/Prop","path":"Check/Prop.html","kind":"module","full_name":"Check::Prop","name":"Prop","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/checkable.cr","line_number":77,"url":null}],"repository_name":"validator","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"validator/Check","kind":"module","full_name":"Check","name":"Check"},"doc":"A mixin to make the `getter` macro of the Crystal std's,\nable to support the rules definition and factory block.","summary":"

    A mixin to make the getter macro of the Crystal std's, able to support the rules definition and factory block.

    ","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":152,"url":null}],"repository_name":"validator","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"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 errors Hash (Check::Errors).

    ","abstract":false,"args":[{"name":"errors","doc":null,"default_value":"","external_name":"errors","restriction":"Errors"}],"args_string":"(errors : Errors)","args_html":"(errors : Errors)","location":{"filename":"src/check.cr","line_number":181,"url":null},"def":{"name":"new","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":"_ = allocate\n_.initialize(errors)\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}},{"id":"new-class-method","html_id":"new-class-method","name":"new","doc":"Initializes a validation.\n\n```\nv = Check::Validation.new\n```\n\nSame as:\n\n```\nv = Check.new_validation\n```","summary":"

    Initializes a validation.

    ","abstract":false,"args":[],"args_string":"","args_html":"","location":{"filename":"src/check.cr","line_number":166,"url":null},"def":{"name":"new","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"_ = allocate\n_.initialize\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}}],"instance_methods":[{"id":"add_error(key:Symbol|String,message:String):Validation-instance-method","html_id":"add_error(key:Symbol|String,message:String):Validation-instance-method","name":"add_error","doc":"Add a validation error.\n\n```\nv = Check.new_validation\nv.add_error(:foo, \"Foo error!\")\npp v.errors # => {:foo => [\"Foo error!\"]}\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"},{"name":"message","doc":null,"default_value":"","external_name":"message","restriction":"String"}],"args_string":"(key : Symbol | String, message : String) : Validation","args_html":"(key : Symbol | String, message : String) : Validation","location":{"filename":"src/check.cr","line_number":204,"url":null},"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","args_html":"(key : Symbol | String) : Validation","location":{"filename":"src/check.cr","line_number":224,"url":null},"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","args_html":"(key : Symbol | String, message : String, valid : Bool) : Validation","location":{"filename":"src/check.cr","line_number":272,"url":null},"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","args_html":"(key : Symbol | String, valid : Bool, message : String) : Validation","location":{"filename":"src/check.cr","line_number":309,"url":null},"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":"

    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"}],"args_string":"(key : Symbol | String, valid : Bool) : Validation","args_html":"(key : Symbol | String, valid : Bool) : Validation","location":{"filename":"src/check.cr","line_number":330,"url":null},"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"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Validation","visibility":"Public","body":"if valid\nelse\n add_error(key, \"\")\nend\nself\n"}},{"id":"errors:Errors-instance-method","html_id":"errors:Errors-instance-method","name":"errors","doc":"Errors container.\n\n```\nv = Check.new_validation\npp v.errors\n```","summary":"

    Errors container.

    ","abstract":false,"args":[],"args_string":" : Errors","args_html":" : Errors","location":{"filename":"src/check.cr","line_number":191,"url":null},"def":{"name":"errors","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Errors","visibility":"Public","body":"@errors"}},{"id":"to_exception-instance-method","html_id":"to_exception-instance-method","name":"to_exception","doc":"Creates a new instance of `ValidationError` (`Exception`).","summary":"

    Creates a new instance of ValidationError (Exception).

    ","abstract":false,"args":[],"args_string":"","args_html":"","location":{"filename":"src/check.cr","line_number":336,"url":null},"def":{"name":"to_exception","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"ValidationError.new(@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":"","args_html":"","location":{"filename":"src/check.cr","line_number":236,"url":null},"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/Check/ValidationError","path":"Check/ValidationError.html","kind":"class","full_name":"Check::ValidationError","name":"ValidationError","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/check.cr","line_number":23,"url":null}],"repository_name":"validator","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"validator/Check","kind":"module","full_name":"Check","name":"Check"},"doc":"Validation error.\nTo carry `Errors` into an `Exception`.","summary":"

    Validation error.

    ","class_methods":[],"constructors":[{"id":"new(errors:Errors,message="Validationerror")-class-method","html_id":"new(errors:Errors,message="Validationerror")-class-method","name":"new","doc":null,"summary":null,"abstract":false,"args":[{"name":"errors","doc":null,"default_value":"","external_name":"errors","restriction":"Errors"},{"name":"message","doc":null,"default_value":"\"Validation error\"","external_name":"message","restriction":""}],"args_string":"(errors : Errors, message = "Validation error")","args_html":"(errors : Errors, message = "Validation error")","location":{"filename":"src/check.cr","line_number":24,"url":null},"def":{"name":"new","args":[{"name":"errors","doc":null,"default_value":"","external_name":"errors","restriction":"Errors"},{"name":"message","doc":null,"default_value":"\"Validation error\"","external_name":"message","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"_ = allocate\n_.initialize(errors, message)\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}}],"instance_methods":[{"id":"errors:Errors-instance-method","html_id":"errors:Errors-instance-method","name":"errors","doc":"Returns `Errors` container (`Hash`).","summary":"

    Returns Errors container (Hash).

    ","abstract":false,"args":[],"args_string":" : Errors","args_html":" : Errors","location":{"filename":"src/check.cr","line_number":29,"url":null},"def":{"name":"errors","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Errors","visibility":"Public","body":"@errors"}}],"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":null}],"repository_name":"validator","program":false,"enum":false,"alias":true,"aliased":"Validator","aliased_html":"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":"

    Alias of Validator

    ","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":null},{"filename":"src/validators/alpha_num.cr","line_number":8,"url":null},{"filename":"src/validators/case_sensitive.cr","line_number":8,"url":null},{"filename":"src/validators/comparisons.cr","line_number":8,"url":null},{"filename":"src/validators/format.cr","line_number":8,"url":null},{"filename":"src/validators/geo.cr","line_number":8,"url":null},{"filename":"src/validators/presence.cr","line_number":8,"url":null},{"filename":"src/validators/uri.cr","line_number":8,"url":null}],"repository_name":"validator","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"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```\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```\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","args_html":"(key : String | Symbol, list : NamedTuple) : Bool","location":{"filename":"src/validators/presence.cr","line_number":47,"url":null},"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","args_html":"(key : String | Symbol | Number, list : Hash) : Bool","location":{"filename":"src/validators/presence.cr","line_number":42,"url":null},"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 value String 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","args_html":"(value : String) : Bool","location":{"filename":"src/validators/presence.cr","line_number":180,"url":null},"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","args_html":"(value) : Bool","location":{"filename":"src/validators/presence.cr","line_number":189,"url":null},"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 value String 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","args_html":"(value : String) : Bool","location":{"filename":"src/validators/format.cr","line_number":41,"url":null},"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 values Array 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","args_html":"(values : Array(String)) : Bool","location":{"filename":"src/validators/format.cr","line_number":47,"url":null},"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","args_html":"(value : String) : Bool","location":{"filename":"src/validators/format.cr","line_number":87,"url":null},"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","args_html":"(value, min, max) : Bool","location":{"filename":"src/validators/comparisons.cr","line_number":87,"url":null},"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","args_html":"(value : String | Array, min : Int, max : Int) : Bool","location":{"filename":"src/validators/comparisons.cr","line_number":94,"url":null},"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","args_html":"(value : String) : Bool","location":{"filename":"src/validators/uri.cr","line_number":26,"url":null},"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","args_html":"(value : String) : Bool","location":{"filename":"src/validators/uri.cr","line_number":161,"url":null},"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","args_html":"(value) : Bool","location":{"filename":"src/validators/presence.cr","line_number":58,"url":null},"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 String value 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","args_html":"(value : String, search : String) : Bool","location":{"filename":"src/validators/presence.cr","line_number":243,"url":null},"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 String value 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","args_html":"(value : String, search : Char) : Bool","location":{"filename":"src/validators/presence.cr","line_number":248,"url":null},"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 String value 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","args_html":"(value : String, search : Regex) : Bool","location":{"filename":"src/validators/presence.cr","line_number":253,"url":null},"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","args_html":"(value, another_value) : Bool","location":{"filename":"src/validators/comparisons.cr","line_number":10,"url":null},"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","args_html":"(value, another_value) : Bool","location":{"filename":"src/validators/comparisons.cr","line_number":15,"url":null},"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","args_html":"(value : String | Array, limit : Int) : Bool","location":{"filename":"src/validators/comparisons.cr","line_number":21,"url":null},"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","args_html":"(value, another_value) : Bool","location":{"filename":"src/validators/comparisons.cr","line_number":27,"url":null},"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","args_html":"(value : String | Array, min : Int) : Bool","location":{"filename":"src/validators/comparisons.cr","line_number":34,"url":null},"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 String value 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","args_html":"(value : String) : Bool","location":{"filename":"src/validators/format.cr","line_number":112,"url":null},"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 Bytes value 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","args_html":"(value : Bytes) : Bool","location":{"filename":"src/validators/format.cr","line_number":118,"url":null},"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 String value 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","args_html":"(value : String) : Bool","location":{"filename":"src/validators/format.cr","line_number":129,"url":null},"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","args_html":"(value, list : Array) : Bool","location":{"filename":"src/validators/presence.cr","line_number":109,"url":null},"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","args_html":"(value : String, str : String) : Bool","location":{"filename":"src/validators/presence.cr","line_number":101,"url":null},"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","args_html":"(key : Symbol | String, list : Hash) : Bool","location":{"filename":"src/validators/presence.cr","line_number":129,"url":null},"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","args_html":"(key : Symbol | String, list : NamedTuple) : Bool","location":{"filename":"src/validators/presence.cr","line_number":124,"url":null},"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","args_html":"(value, list : Range) : Bool","location":{"filename":"src/validators/presence.cr","line_number":119,"url":null},"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","args_html":"(value, list : Tuple) : Bool","location":{"filename":"src/validators/presence.cr","line_number":114,"url":null},"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","args_html":"(value : String) : Bool","location":{"filename":"src/validators/uri.cr","line_number":80,"url":null},"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","args_html":"(value : String) : Bool","location":{"filename":"src/validators/uri.cr","line_number":85,"url":null},"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","args_html":"(value : String) : Bool","location":{"filename":"src/validators/uri.cr","line_number":90,"url":null},"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","args_html":"(value : String, strict : Bool = true) : Bool","location":{"filename":"src/validators/format.cr","line_number":64,"url":null},"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","args_html":"(value : String) : Bool","location":{"filename":"src/validators/format.cr","line_number":95,"url":null},"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","args_html":"(value : String | Float) : Bool","location":{"filename":"src/validators/geo.cr","line_number":31,"url":null},"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","args_html":"(value : String) : Bool","location":{"filename":"src/validators/geo.cr","line_number":16,"url":null},"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","args_html":"(value : String | Float) : Bool","location":{"filename":"src/validators/geo.cr","line_number":38,"url":null},"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","args_html":"(value : String) : Bool","location":{"filename":"src/validators/case_sensitive.cr","line_number":10,"url":null},"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","args_html":"(value : String | Array, limit : Int) : Bool","location":{"filename":"src/validators/comparisons.cr","line_number":45,"url":null},"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","args_html":"(value, another_value) : Bool","location":{"filename":"src/validators/comparisons.cr","line_number":39,"url":null},"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","args_html":"(value : String | Array, max : Int) : Bool","location":{"filename":"src/validators/comparisons.cr","line_number":58,"url":null},"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","args_html":"(value, another_value) : Bool","location":{"filename":"src/validators/comparisons.cr","line_number":51,"url":null},"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","args_html":"(value : String, no_colons : Bool = false) : Bool","location":{"filename":"src/validators/uri.cr","line_number":179,"url":null},"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","args_html":"(value : String) : Bool","location":{"filename":"src/validators/uri.cr","line_number":189,"url":null},"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","args_html":"(value : Number, pattern : Regex) : Bool","location":{"filename":"src/validators/presence.cr","line_number":15,"url":null},"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","args_html":"(value : String, pattern : Regex) : Bool","location":{"filename":"src/validators/presence.cr","line_number":10,"url":null},"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","args_html":"(value, max) : Bool","location":{"filename":"src/validators/comparisons.cr","line_number":76,"url":null},"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","args_html":"(value : String | Array, max : Int) : Bool","location":{"filename":"src/validators/comparisons.cr","line_number":82,"url":null},"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","args_html":"(value : String) : Bool","location":{"filename":"src/validators/format.cr","line_number":82,"url":null},"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","args_html":"(value, min) : Bool","location":{"filename":"src/validators/comparisons.cr","line_number":64,"url":null},"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","args_html":"(value : String | Array, min : Int) : Bool","location":{"filename":"src/validators/comparisons.cr","line_number":70,"url":null},"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 Bytes value 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","args_html":"(value : Bytes) : Bool","location":{"filename":"src/validators/format.cr","line_number":143,"url":null},"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 String value 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","args_html":"(value : String) : Bool","location":{"filename":"src/validators/format.cr","line_number":137,"url":null},"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","args_html":"(value) : Bool","location":{"filename":"src/validators/presence.cr","line_number":71,"url":null},"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","args_html":"(value : String, str : String) : Bool","location":{"filename":"src/validators/presence.cr","line_number":141,"url":null},"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","args_html":"(value, list : Array) : Bool","location":{"filename":"src/validators/presence.cr","line_number":149,"url":null},"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","args_html":"(value, list : Tuple) : Bool","location":{"filename":"src/validators/presence.cr","line_number":154,"url":null},"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","args_html":"(value, list : Range) : Bool","location":{"filename":"src/validators/presence.cr","line_number":159,"url":null},"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","args_html":"(key : Symbol | String, list : NamedTuple) : Bool","location":{"filename":"src/validators/presence.cr","line_number":164,"url":null},"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","args_html":"(key : Symbol | String, list : Hash) : Bool","location":{"filename":"src/validators/presence.cr","line_number":169,"url":null},"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","args_html":"(value) : Bool","location":{"filename":"src/validators/presence.cr","line_number":89,"url":null},"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","args_html":"(value) : Bool","location":{"filename":"src/validators/presence.cr","line_number":82,"url":null},"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","args_html":"(value : String) : Bool","location":{"filename":"src/validators/alpha_num.cr","line_number":12,"url":null},"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","args_html":"(value : String = "0", min : String = "1", max : String = "65535") : Bool","location":{"filename":"src/validators/uri.cr","line_number":47,"url":null},"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","args_html":"(value = 0, min = 1, max = 65535) : Bool","location":{"filename":"src/validators/uri.cr","line_number":41,"url":null},"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","args_html":"(key : String | Symbol, list : NamedTuple) : Bool","location":{"filename":"src/validators/presence.cr","line_number":31,"url":null},"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","args_html":"(key : String | Symbol | Number, list : Hash) : Bool","location":{"filename":"src/validators/presence.cr","line_number":26,"url":null},"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","args_html":"(value) : Bool","location":{"filename":"src/validators/presence.cr","line_number":209,"url":null},"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 value String 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","args_html":"(value : String) : Bool","location":{"filename":"src/validators/presence.cr","line_number":200,"url":null},"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))","args_html":"(value, size : Array(String))","location":{"filename":"src/validators/comparisons.cr","line_number":122,"url":null},"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))","args_html":"(value, size : Array(Int))","location":{"filename":"src/validators/comparisons.cr","line_number":117,"url":null},"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)","args_html":"(value, size : Range)","location":{"filename":"src/validators/comparisons.cr","line_number":111,"url":null},"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)","args_html":"(value, size : String)","location":{"filename":"src/validators/comparisons.cr","line_number":105,"url":null},"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)","args_html":"(value, size : Int)","location":{"filename":"src/validators/comparisons.cr","line_number":100,"url":null},"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","args_html":"(value : String, min = 1, max = 100) : Bool","location":{"filename":"src/validators/uri.cr","line_number":174,"url":null},"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 String value 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","args_html":"(value : String, search : Char) : Bool","location":{"filename":"src/validators/presence.cr","line_number":226,"url":null},"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 String value 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","args_html":"(value : String, search : Regex) : Bool","location":{"filename":"src/validators/presence.cr","line_number":231,"url":null},"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 String value 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","args_html":"(value : String, search : String) : Bool","location":{"filename":"src/validators/presence.cr","line_number":221,"url":null},"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","args_html":"(value : String) : Bool","location":{"filename":"src/validators/format.cr","line_number":31,"url":null},"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","args_html":"(value : String) : Bool","location":{"filename":"src/validators/case_sensitive.cr","line_number":15,"url":null},"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","args_html":"(value : String) : Bool","location":{"filename":"src/validators/uri.cr","line_number":55,"url":null},"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","args_html":"(value : String, version = 0) : Bool","location":{"filename":"src/validators/format.cr","line_number":103,"url":null},"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":null}],"repository_name":"validator","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"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":"

    Used by is! when a validation is not true.

    ","class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[]}]}]}}) \ No newline at end of file +crystal_doc_search_index_callback({"repository_name":"validator","body":"# validator\n\n[![CI Status](https://github.com/Nicolab/crystal-validator/workflows/CI/badge.svg?branch=master)](https://github.com/Nicolab/crystal-validator/actions) [![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```\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\nThe validation rules can be defined directly when defining properties (with `getter` or `property`).\nOr with the macro `Check.rules`. Depending on preference, it's the same under the hood.\n\n```crystal\nrequire \"validator/check\"\n\nclass User\n # Mixin\n Check.checkable\n\n # required\n property email : String, {\n required: true,\n\n # Optional lifecycle hook to be executed on `check_email` call.\n # Before the `check` rules, just after `clean_email` called inside `check_email`.\n # Proc or method name (here is a Proc)\n before_check: ->(v : Check::Validation, content : String?, required : Bool, format : Bool) {\n puts \"before_check_content\"\n content\n },\n\n # Optional lifecycle hook to be executed on `check_email` call, after the `check` rules.\n # Proc or method name (here is the method name)\n after_check: :after_check_email\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) or method name (Symbol)\n format: :format_email,\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 property age : Int32, {\n required: \"Age is required\", # Custom message\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 property bio : String?, {\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 def initialize(@email, @age)\n end\n\n # ---------------------------------------------------------------------------\n # Lifecycle methods (hooks)\n # ---------------------------------------------------------------------------\n\n # Triggered on instance: `user.check`\n private def before_check(v : Check::Validation, required : Bool, format : Bool)\n # Code...\n end\n\n # Triggered on instance: `user.check`\n private 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 private 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 private 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 # Triggered on a static call and on instance call: `User.check_email(value)`, `User.check(h)`, `user.check`.\n private def self.after_check_content(v : Check::Validation, content : String?, required : Bool, format : Bool)\n puts \"after_check_content\"\n puts \"Valid? #{v.valid?}\"\n content\n end\n\n # --------------------------------------------------------------------------\n # Custom checkers\n # --------------------------------------------------------------------------\n\n # Triggered on instance: `user.check`\n @[Check::Checker]\n private def custom_checker(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 @[Check::Checker]\n private def self.custom_checker(v : Check::Validation, h, cleaned_h, required : Bool, format : Bool)\n # Code...\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 # ...\nend\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# Same but raise if there is a validation error\nuser_h = User.check!(input_h)\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# Same but raise if there is a validation error\nuser.check! # => Validation instance\n\n# Example with an active record model\nuser.check!.save\n\n# Check field\nv, email = User.check_email(value: \"demo@example.org\")\nv, age = User.check_age(value: 42)\n\n# Same but raise if there is a validation error\nemail = User.check_email!(value: \"demo@example.org\")\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# Same but raise if there is a validation error\nemail = 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# Same but raise if there is a validation error\nvalue1, 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# Same but raise if there is a validation error\n# Email value with one space before and one space after\nemail = 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./bin/ameba\n```\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":null,"aliased_html":null,"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)","location":{"filename":"src/is.cr","line_number":18,"url":null},"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)","location":{"filename":"src/is.cr","line_number":26,"url":null},"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":12,"url":null},{"filename":"src/checkable.cr","line_number":11,"url":null}],"repository_name":"validator","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[{"id":"RULES","name":"RULES","value":"{} of String => HashLiteral(String, ASTNode)","doc":null,"summary":null}],"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":"

    Initializes a new Validation instance to combine a series of checks (Validation#check).

    ","abstract":false,"args":[{"name":"errors","doc":null,"default_value":"","external_name":"errors","restriction":"Errors"}],"args_string":"(errors : Errors)","args_html":"(errors : Errors)","location":{"filename":"src/check.cr","line_number":378,"url":null},"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":"

    Initializes a new Validation instance to combine a series of checks (Validation#check).

    ","abstract":false,"args":[],"args_string":"","args_html":"","location":{"filename":"src/check.cr","line_number":354,"url":null},"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 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\n def initialize(@title, @content)\n end\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":"","location":{"filename":"src/checkable.cr","line_number":69,"url":null},"def":{"name":"checkable","args":[],"double_splat":null,"splat_index":null,"block_arg":null,"visibility":"Public","body":" include Check::Prop\n 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 private def self.after_check_content(v : Check::Validation, content : String?, required : Bool, format : Bool)\n puts \"after_check_content\"\n puts \"Valid? #{v.valid?}\"\n content\n end\n\n Check.rules(\n content: {\n required: \"Content is required\", # or `true` to use the default error message\n before_check: ->(v : Check::Validation, content : String?, required : Bool, format : Bool) {\n puts \"before_check_content\"\n content\n },\n after_check: :after_check_email,\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 # Proc or method name (Symbol)\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)","location":{"filename":"src/checkable.cr","line_number":168,"url":null},"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":" \n{% for field, rules in fields %}\n {% if RULES[\"#{@type.name}\"] %}{% else %}\n {% RULES[\"#{@type.name}\"] = {} of String => ASTNode %}\n {% end %}\n\n {% RULES[\"#{@type.name}\"][field] = rules %}\n {% end %}\n\n\n \n# Returns all validation rules.\n\n private def self.validation_rules\n \n{\n \n{% for field, rules in RULES[\"#{@type.name}\"] %}\n {{ field }}: {{ rules }},\n {% end %}\n\n }\n \nend\n\n \n# Returns `true` if a given *field* is required.\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) == false ? false : true\n \nend\n\n \n# Returns `true` if a given *field* is nilable.\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 # Same as `clean_{{ field }}` but this method raises a `Validator::Error`\n # if the clean has not been processed successfully.\n #\n # ```\n # email = MyCheckable.clean_email!(user_input[\"email\"]) # => user@example.com\n # ```\n def self.clean_{{ field }}!(value, format = true) : {{ type }}\n ok, value = self.clean_{{ field }}(value, format)\n raise Validator::Error.new %(Cannot clean the \"{{ field }}\" field) unless ok\n value.as({{ type }})\n end\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 = MyCheckable.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,\n {% if format.is_a?(SymbolLiteral) %}\n {{ format.id }}(value)\n {% else %}\n {{ format }}.call(value)\n {% end %}\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 # Checks *value* and returns it cleaned.\n # This method raises a `Check::ValidationError` if the validation fails.\n def self.check_{{ field }}!(*, value, required : Bool = true, format : Bool = true) : {{ type }}\n v, value = self.check_{{ field }}(value: value, required: required, format: format)\n raise v.to_exception unless v.valid?\n value.as({{ type }})\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 # Checks *value* and returns it cleaned.\n # This method raises a `Check::ValidationError` if the validation fails.\n def self.check_{{ field }}!(\n v : Check::Validation,\n value,\n required : Bool = true,\n format : Bool = true\n ) : {{ type }}\n v, value = self.check_{{ field }}(v, value, required, format)\n raise v.to_exception unless v.valid?\n value.as({{ type }})\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(\n {{ field.stringify }},\n {{ msg }}\n ) {% if nilable || (check[\"not_null\"].nil? && check[\"not_empty\"].nil?) %}unless value.nil?{% end %}\n\n return v, value\n end\n\n # Lifecycle: hook before_check_field\n {% if before_check = rules[\"before_check\"] %}\n {% if before_check.is_a?(SymbolLiteral) %}\n value = {{ before_check.id }}(v, value, required, format)\n {% else %}\n value = {{ before_check }}.call(v, value, required, format)\n {% end %}\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?\n {% end %}\n {% end %}\n\n # Lifecycle: hook after_check_field\n {% if after_check = rules[\"after_check\"] %}\n {% if after_check.is_a?(SymbolLiteral) %}\n value = {{ after_check.id }}(v, value, required, format)\n {% else %}\n value = {{ after_check }}.call(v, value, required, format)\n {% 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":568,"url":null}],"repository_name":"validator","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"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)","args_html":"(v : Check::Validation, required : Bool = true, format : Bool = true)","location":{"filename":"src/checkable.cr","line_number":591,"url":null},"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)","args_html":"(v : Check::Validation, required : Bool = true, format : Bool = true)","location":{"filename":"src/checkable.cr","line_number":577,"url":null},"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":"Same as `check` but this method raises a `Check::ValidationError`\nif the validation fails or if the clean has not been processed successfully.\n\n```\nmyCheckable.check! # => Returns the current instance.\n```\n\nThis method returns `self`, so it chainable :)\n\n```\nuser.email = \"me@example.org\"\nuser.check!.save\n```","summary":"

    Same as #check but this method raises a Check::ValidationError if the validation fails or if the clean has not been processed successfully.

    ","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","args_html":"(required : Bool = true, format : Bool = true) : Validation","location":{"filename":"src/checkable.cr","line_number":677,"url":null},"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","args_html":"(v : Check::Validation, required : Bool = true, format : Bool = true) : Validation","location":{"filename":"src/checkable.cr","line_number":628,"url":null},"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(&.annotation(Checker)) %}\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 %}"}},{"id":"check!(required:Bool=true,format:Bool=true):self-instance-method","html_id":"check!(required:Bool=true,format:Bool=true):self-instance-method","name":"check!","doc":"Same as `check` but this method raises a `Check::ValidationError`\nif the validation fails or if the clean has not been processed successfully.\n\n```\nmyCheckable.check! # => Returns the current instance.\n```\n\nThis method returns `self`, so it chainable :)\n\n```\nuser.email = \"me@example.org\"\nuser.check!.save\n```","summary":"

    Same as #check but this method raises a Check::ValidationError if the validation fails or if the clean has not been processed successfully.

    ","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) : self","args_html":"(required : Bool = true, format : Bool = true) : self","location":{"filename":"src/checkable.cr","line_number":670,"url":null},"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":"self","visibility":"Public","body":"v = check(required, format)\nif v.valid?\nelse\n raise(v.to_exception)\nend\nself\n"}},{"id":"check!(v:Check::Validation,required:Bool=true,format:Bool=true):self-instance-method","html_id":"check!(v:Check::Validation,required:Bool=true,format:Bool=true):self-instance-method","name":"check!","doc":"Same as `check` but this method raises a `Check::ValidationError`\nif the validation fails or if the clean has not been processed successfully.\n\n```\nv = Validation.new_validation\nmyCheckable.check!(v) # => Returns the current instance.\n```\n\nThis method returns `self`, so it chainable :)\n\n```\nv = Validation.new_validation\nuser.email = \"me@example.org\"\nuser.check!(v).save\n```","summary":"

    Same as #check but this method raises a Check::ValidationError if the validation fails or if the clean has not been processed successfully.

    ","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) : self","args_html":"(v : Check::Validation, required : Bool = true, format : Bool = true) : self","location":{"filename":"src/checkable.cr","line_number":612,"url":null},"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":"self","visibility":"Public","body":"v = check(v, required, format)\nif v.valid?\nelse\n raise(v.to_exception)\nend\nself\n"}}],"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":372,"url":null}],"repository_name":"validator","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"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","args_html":"(v : Check::Validation, h : Hash, cleaned_h : Hash, required : Bool = true, format : Bool = true) : Hash","location":{"filename":"src/checkable.cr","line_number":462,"url":null},"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)","args_html":"(v : Check::Validation, h : Hash, required : Bool = true, format : Bool = true)","location":{"filename":"src/checkable.cr","line_number":441,"url":null},"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)","args_html":"(v : Check::Validation, h : Hash, required : Bool = true, format : Bool = true)","location":{"filename":"src/checkable.cr","line_number":494,"url":null},"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\n if h.has_key?({{ field_name }})\n v, value = self.check_{{ field }}(v, h[{{ field_name }}]?, required, format)\n cleaned_h[{{ field_name }}] = value.as({{ types[i] }})\n\n # or if this field MUST be checked when required\n elsif required && self.validation_required?({{ field_name }})\n required_msg = self.validation_rules[{{ field_name }}].fetch(:required, nil)\n\n msg = if required_msg && required_msg.is_a?(String)\n required_msg.as(String)\n else\n \"This field is required\"\n end\n\n v.add_error {{ field_name }}, msg\n end\n {% end %}\n\n # Check methods with `Check::Checker` annotation\n {% for method in @type.class.methods.select(&.annotation(Checker)) %}\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":"Same as `check` but this method raises a `Check::ValidationError`\nif the validation fails or if the clean has not been processed successfully.\n\n```\ncleaned_h = MyCheckable.check!(h)\n```","summary":"

    Same as #check but this method raises a Check::ValidationError if the validation fails or if the clean has not been processed successfully.

    ","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)","args_html":"(h : Hash, required : Bool = true, format : Bool = true)","location":{"filename":"src/checkable.cr","line_number":559,"url":null},"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":"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":"Same as `check` but this method raises a `Check::ValidationError`\nif the validation fails or if the clean has not been processed successfully.\n\n```\ncleaned_h = MyCheckable.check!(v, h)\n```","summary":"

    Same as #check but this method raises a Check::ValidationError if the validation fails or if the clean has not been processed successfully.

    ","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)","args_html":"(v : Check::Validation, h : Hash, required : Bool = true, format : Bool = true)","location":{"filename":"src/checkable.cr","line_number":477,"url":null},"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":"v, cleaned_h = check(v, h, required, format)\nif v.valid?\nelse\n raise(v.to_exception)\nend\ncleaned_h\n"}},{"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":"Same as `check` but this method raises a `Check::ValidationError`\nif the validation fails or if the clean has not been processed successfully.\n\n```\ncleaned_h = MyCheckable.check!(h)\n```","summary":"

    Same as #check but this method raises a Check::ValidationError if the validation fails or if the clean has not been processed successfully.

    ","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)","args_html":"(h : Hash, required : Bool = true, format : Bool = true)","location":{"filename":"src/checkable.cr","line_number":552,"url":null},"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, cleaned_h = check(h, required, format)\nif v.valid?\nelse\n raise(v.to_exception)\nend\ncleaned_h\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 *json* `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 json 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)","args_html":"(json : String | IO)","location":{"filename":"src/checkable.cr","line_number":416,"url":null},"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":"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 *json* `Hash` from a JSON input.\nSame as `h_from_json`, except that this method raises a `JSON::ParseException` if the conversion fails.\n\n```\nuser_h = User.h_from_json!(json) # => {\"username\" => \"Bob\", \"email\" => \"user@example.com\"}\n```","summary":"

    Returns a json 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)","args_html":"(json : String | IO)","location":{"filename":"src/checkable.cr","line_number":428,"url":null},"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":"self.to_crystal_h((JSON.parse(json)).as_h)"}},{"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)","args_html":" : Hash(String, String)","location":{"filename":"src/checkable.cr","line_number":374,"url":null},"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","args_html":"(h : Hash) : Hash","location":{"filename":"src/checkable.cr","line_number":389,"url":null},"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","args_html":"(h : Hash) : Hash","location":{"filename":"src/checkable.cr","line_number":399,"url":null},"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":30,"url":null}],"repository_name":"validator","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"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":20,"url":null}],"repository_name":"validator","program":false,"enum":false,"alias":true,"aliased":"Hash(String | Symbol, Array(String))","aliased_html":"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/Prop","path":"Check/Prop.html","kind":"module","full_name":"Check::Prop","name":"Prop","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/checkable.cr","line_number":77,"url":null}],"repository_name":"validator","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"validator/Check","kind":"module","full_name":"Check","name":"Check"},"doc":"A mixin to make the `getter` macro of the Crystal std's,\nable to support the rules definition and factory block.","summary":"

    A mixin to make the getter macro of the Crystal std's, able to support the rules definition and factory block.

    ","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":153,"url":null}],"repository_name":"validator","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"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 errors Hash (Check::Errors).

    ","abstract":false,"args":[{"name":"errors","doc":null,"default_value":"","external_name":"errors","restriction":"Errors"}],"args_string":"(errors : Errors)","args_html":"(errors : Errors)","location":{"filename":"src/check.cr","line_number":182,"url":null},"def":{"name":"new","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":"_ = allocate\n_.initialize(errors)\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}},{"id":"new-class-method","html_id":"new-class-method","name":"new","doc":"Initializes a validation.\n\n```\nv = Check::Validation.new\n```\n\nSame as:\n\n```\nv = Check.new_validation\n```","summary":"

    Initializes a validation.

    ","abstract":false,"args":[],"args_string":"","args_html":"","location":{"filename":"src/check.cr","line_number":167,"url":null},"def":{"name":"new","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"_ = allocate\n_.initialize\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}}],"instance_methods":[{"id":"add_error(key:Symbol|String,message:String):Validation-instance-method","html_id":"add_error(key:Symbol|String,message:String):Validation-instance-method","name":"add_error","doc":"Add a validation error.\n\n```\nv = Check.new_validation\nv.add_error(:foo, \"Foo error!\")\npp v.errors # => {:foo => [\"Foo error!\"]}\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"},{"name":"message","doc":null,"default_value":"","external_name":"message","restriction":"String"}],"args_string":"(key : Symbol | String, message : String) : Validation","args_html":"(key : Symbol | String, message : String) : Validation","location":{"filename":"src/check.cr","line_number":205,"url":null},"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","args_html":"(key : Symbol | String) : Validation","location":{"filename":"src/check.cr","line_number":225,"url":null},"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","args_html":"(key : Symbol | String, message : String, valid : Bool) : Validation","location":{"filename":"src/check.cr","line_number":273,"url":null},"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","args_html":"(key : Symbol | String, valid : Bool, message : String) : Validation","location":{"filename":"src/check.cr","line_number":310,"url":null},"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":"

    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"}],"args_string":"(key : Symbol | String, valid : Bool) : Validation","args_html":"(key : Symbol | String, valid : Bool) : Validation","location":{"filename":"src/check.cr","line_number":331,"url":null},"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"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Validation","visibility":"Public","body":"if valid\nelse\n add_error(key, \"\")\nend\nself\n"}},{"id":"errors:Errors-instance-method","html_id":"errors:Errors-instance-method","name":"errors","doc":"Errors container.\n\n```\nv = Check.new_validation\npp v.errors\n```","summary":"

    Errors container.

    ","abstract":false,"args":[],"args_string":" : Errors","args_html":" : Errors","location":{"filename":"src/check.cr","line_number":192,"url":null},"def":{"name":"errors","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Errors","visibility":"Public","body":"@errors"}},{"id":"to_exception-instance-method","html_id":"to_exception-instance-method","name":"to_exception","doc":"Creates a new instance of `ValidationError` (`Exception`).","summary":"

    Creates a new instance of ValidationError (Exception).

    ","abstract":false,"args":[],"args_string":"","args_html":"","location":{"filename":"src/check.cr","line_number":337,"url":null},"def":{"name":"to_exception","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"ValidationError.new(@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":"","args_html":"","location":{"filename":"src/check.cr","line_number":237,"url":null},"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/Check/ValidationError","path":"Check/ValidationError.html","kind":"class","full_name":"Check::ValidationError","name":"ValidationError","abstract":false,"superclass":{"html_id":"validator/Validator/Error","kind":"class","full_name":"Validator::Error","name":"Error"},"ancestors":[{"html_id":"validator/Validator/Error","kind":"class","full_name":"Validator::Error","name":"Error"},{"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/check.cr","line_number":24,"url":null}],"repository_name":"validator","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"validator/Check","kind":"module","full_name":"Check","name":"Check"},"doc":"Validation error.\nTo carry `Errors` into an `Exception`.","summary":"

    Validation error.

    ","class_methods":[],"constructors":[{"id":"new(errors:Errors,message="Validationerror")-class-method","html_id":"new(errors:Errors,message="Validationerror")-class-method","name":"new","doc":null,"summary":null,"abstract":false,"args":[{"name":"errors","doc":null,"default_value":"","external_name":"errors","restriction":"Errors"},{"name":"message","doc":null,"default_value":"\"Validation error\"","external_name":"message","restriction":""}],"args_string":"(errors : Errors, message = "Validation error")","args_html":"(errors : Errors, message = "Validation error")","location":{"filename":"src/check.cr","line_number":25,"url":null},"def":{"name":"new","args":[{"name":"errors","doc":null,"default_value":"","external_name":"errors","restriction":"Errors"},{"name":"message","doc":null,"default_value":"\"Validation error\"","external_name":"message","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"_ = allocate\n_.initialize(errors, message)\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}}],"instance_methods":[{"id":"errors:Errors-instance-method","html_id":"errors:Errors-instance-method","name":"errors","doc":"Returns `Errors` container (`Hash`).","summary":"

    Returns Errors container (Hash).

    ","abstract":false,"args":[],"args_string":" : Errors","args_html":" : Errors","location":{"filename":"src/check.cr","line_number":30,"url":null},"def":{"name":"errors","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Errors","visibility":"Public","body":"@errors"}}],"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":null}],"repository_name":"validator","program":false,"enum":false,"alias":true,"aliased":"Validator","aliased_html":"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":"

    Alias of Validator

    ","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":null},{"filename":"src/validators/alpha_num.cr","line_number":8,"url":null},{"filename":"src/validators/case_sensitive.cr","line_number":8,"url":null},{"filename":"src/validators/comparisons.cr","line_number":8,"url":null},{"filename":"src/validators/format.cr","line_number":8,"url":null},{"filename":"src/validators/geo.cr","line_number":8,"url":null},{"filename":"src/validators/presence.cr","line_number":8,"url":null},{"filename":"src/validators/uri.cr","line_number":8,"url":null}],"repository_name":"validator","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"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```\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```\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","args_html":"(key : String | Symbol, list : NamedTuple) : Bool","location":{"filename":"src/validators/presence.cr","line_number":47,"url":null},"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","args_html":"(key : String | Symbol | Number, list : Hash) : Bool","location":{"filename":"src/validators/presence.cr","line_number":42,"url":null},"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 value String 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","args_html":"(value : String) : Bool","location":{"filename":"src/validators/presence.cr","line_number":180,"url":null},"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","args_html":"(value) : Bool","location":{"filename":"src/validators/presence.cr","line_number":189,"url":null},"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 value String 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","args_html":"(value : String) : Bool","location":{"filename":"src/validators/format.cr","line_number":41,"url":null},"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 values Array 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","args_html":"(values : Array(String)) : Bool","location":{"filename":"src/validators/format.cr","line_number":47,"url":null},"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","args_html":"(value : String) : Bool","location":{"filename":"src/validators/format.cr","line_number":87,"url":null},"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","args_html":"(value, min, max) : Bool","location":{"filename":"src/validators/comparisons.cr","line_number":87,"url":null},"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","args_html":"(value : String | Array, min : Int, max : Int) : Bool","location":{"filename":"src/validators/comparisons.cr","line_number":94,"url":null},"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","args_html":"(value : String) : Bool","location":{"filename":"src/validators/uri.cr","line_number":26,"url":null},"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","args_html":"(value : String) : Bool","location":{"filename":"src/validators/uri.cr","line_number":161,"url":null},"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","args_html":"(value) : Bool","location":{"filename":"src/validators/presence.cr","line_number":58,"url":null},"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 String value 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","args_html":"(value : String, search : String) : Bool","location":{"filename":"src/validators/presence.cr","line_number":243,"url":null},"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 String value 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","args_html":"(value : String, search : Char) : Bool","location":{"filename":"src/validators/presence.cr","line_number":248,"url":null},"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 String value 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","args_html":"(value : String, search : Regex) : Bool","location":{"filename":"src/validators/presence.cr","line_number":253,"url":null},"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","args_html":"(value, another_value) : Bool","location":{"filename":"src/validators/comparisons.cr","line_number":10,"url":null},"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","args_html":"(value, another_value) : Bool","location":{"filename":"src/validators/comparisons.cr","line_number":15,"url":null},"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","args_html":"(value : String | Array, limit : Int) : Bool","location":{"filename":"src/validators/comparisons.cr","line_number":21,"url":null},"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","args_html":"(value, another_value) : Bool","location":{"filename":"src/validators/comparisons.cr","line_number":27,"url":null},"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","args_html":"(value : String | Array, min : Int) : Bool","location":{"filename":"src/validators/comparisons.cr","line_number":34,"url":null},"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 String value 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","args_html":"(value : String) : Bool","location":{"filename":"src/validators/format.cr","line_number":112,"url":null},"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 Bytes value 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","args_html":"(value : Bytes) : Bool","location":{"filename":"src/validators/format.cr","line_number":118,"url":null},"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 String value 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","args_html":"(value : String) : Bool","location":{"filename":"src/validators/format.cr","line_number":129,"url":null},"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","args_html":"(value, list : Array) : Bool","location":{"filename":"src/validators/presence.cr","line_number":109,"url":null},"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","args_html":"(value : String, str : String) : Bool","location":{"filename":"src/validators/presence.cr","line_number":101,"url":null},"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","args_html":"(key : Symbol | String, list : Hash) : Bool","location":{"filename":"src/validators/presence.cr","line_number":129,"url":null},"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","args_html":"(key : Symbol | String, list : NamedTuple) : Bool","location":{"filename":"src/validators/presence.cr","line_number":124,"url":null},"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","args_html":"(value, list : Range) : Bool","location":{"filename":"src/validators/presence.cr","line_number":119,"url":null},"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","args_html":"(value, list : Tuple) : Bool","location":{"filename":"src/validators/presence.cr","line_number":114,"url":null},"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","args_html":"(value : String) : Bool","location":{"filename":"src/validators/uri.cr","line_number":80,"url":null},"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","args_html":"(value : String) : Bool","location":{"filename":"src/validators/uri.cr","line_number":85,"url":null},"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","args_html":"(value : String) : Bool","location":{"filename":"src/validators/uri.cr","line_number":90,"url":null},"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","args_html":"(value : String, strict : Bool = true) : Bool","location":{"filename":"src/validators/format.cr","line_number":64,"url":null},"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","args_html":"(value : String) : Bool","location":{"filename":"src/validators/format.cr","line_number":95,"url":null},"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","args_html":"(value : String | Float) : Bool","location":{"filename":"src/validators/geo.cr","line_number":31,"url":null},"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","args_html":"(value : String) : Bool","location":{"filename":"src/validators/geo.cr","line_number":16,"url":null},"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","args_html":"(value : String | Float) : Bool","location":{"filename":"src/validators/geo.cr","line_number":38,"url":null},"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","args_html":"(value : String) : Bool","location":{"filename":"src/validators/case_sensitive.cr","line_number":10,"url":null},"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","args_html":"(value : String | Array, limit : Int) : Bool","location":{"filename":"src/validators/comparisons.cr","line_number":45,"url":null},"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","args_html":"(value, another_value) : Bool","location":{"filename":"src/validators/comparisons.cr","line_number":39,"url":null},"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","args_html":"(value : String | Array, max : Int) : Bool","location":{"filename":"src/validators/comparisons.cr","line_number":58,"url":null},"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","args_html":"(value, another_value) : Bool","location":{"filename":"src/validators/comparisons.cr","line_number":51,"url":null},"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","args_html":"(value : String, no_colons : Bool = false) : Bool","location":{"filename":"src/validators/uri.cr","line_number":179,"url":null},"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","args_html":"(value : String) : Bool","location":{"filename":"src/validators/uri.cr","line_number":189,"url":null},"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","args_html":"(value : Number, pattern : Regex) : Bool","location":{"filename":"src/validators/presence.cr","line_number":15,"url":null},"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","args_html":"(value : String, pattern : Regex) : Bool","location":{"filename":"src/validators/presence.cr","line_number":10,"url":null},"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","args_html":"(value, max) : Bool","location":{"filename":"src/validators/comparisons.cr","line_number":76,"url":null},"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","args_html":"(value : String | Array, max : Int) : Bool","location":{"filename":"src/validators/comparisons.cr","line_number":82,"url":null},"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","args_html":"(value : String) : Bool","location":{"filename":"src/validators/format.cr","line_number":82,"url":null},"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","args_html":"(value, min) : Bool","location":{"filename":"src/validators/comparisons.cr","line_number":64,"url":null},"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","args_html":"(value : String | Array, min : Int) : Bool","location":{"filename":"src/validators/comparisons.cr","line_number":70,"url":null},"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 Bytes value 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","args_html":"(value : Bytes) : Bool","location":{"filename":"src/validators/format.cr","line_number":143,"url":null},"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 String value 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","args_html":"(value : String) : Bool","location":{"filename":"src/validators/format.cr","line_number":137,"url":null},"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","args_html":"(value) : Bool","location":{"filename":"src/validators/presence.cr","line_number":71,"url":null},"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","args_html":"(value : String, str : String) : Bool","location":{"filename":"src/validators/presence.cr","line_number":141,"url":null},"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","args_html":"(value, list : Array) : Bool","location":{"filename":"src/validators/presence.cr","line_number":149,"url":null},"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","args_html":"(value, list : Tuple) : Bool","location":{"filename":"src/validators/presence.cr","line_number":154,"url":null},"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","args_html":"(value, list : Range) : Bool","location":{"filename":"src/validators/presence.cr","line_number":159,"url":null},"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","args_html":"(key : Symbol | String, list : NamedTuple) : Bool","location":{"filename":"src/validators/presence.cr","line_number":164,"url":null},"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","args_html":"(key : Symbol | String, list : Hash) : Bool","location":{"filename":"src/validators/presence.cr","line_number":169,"url":null},"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","args_html":"(value) : Bool","location":{"filename":"src/validators/presence.cr","line_number":89,"url":null},"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","args_html":"(value) : Bool","location":{"filename":"src/validators/presence.cr","line_number":82,"url":null},"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","args_html":"(value : String) : Bool","location":{"filename":"src/validators/alpha_num.cr","line_number":12,"url":null},"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","args_html":"(value : String = "0", min : String = "1", max : String = "65535") : Bool","location":{"filename":"src/validators/uri.cr","line_number":47,"url":null},"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","args_html":"(value = 0, min = 1, max = 65535) : Bool","location":{"filename":"src/validators/uri.cr","line_number":41,"url":null},"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","args_html":"(key : String | Symbol, list : NamedTuple) : Bool","location":{"filename":"src/validators/presence.cr","line_number":31,"url":null},"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","args_html":"(key : String | Symbol | Number, list : Hash) : Bool","location":{"filename":"src/validators/presence.cr","line_number":26,"url":null},"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","args_html":"(value) : Bool","location":{"filename":"src/validators/presence.cr","line_number":209,"url":null},"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 value String 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","args_html":"(value : String) : Bool","location":{"filename":"src/validators/presence.cr","line_number":200,"url":null},"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))","args_html":"(value, size : Array(String))","location":{"filename":"src/validators/comparisons.cr","line_number":122,"url":null},"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))","args_html":"(value, size : Array(Int))","location":{"filename":"src/validators/comparisons.cr","line_number":117,"url":null},"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)","args_html":"(value, size : Range)","location":{"filename":"src/validators/comparisons.cr","line_number":111,"url":null},"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)","args_html":"(value, size : String)","location":{"filename":"src/validators/comparisons.cr","line_number":105,"url":null},"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)","args_html":"(value, size : Int)","location":{"filename":"src/validators/comparisons.cr","line_number":100,"url":null},"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","args_html":"(value : String, min = 1, max = 100) : Bool","location":{"filename":"src/validators/uri.cr","line_number":174,"url":null},"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 String value 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","args_html":"(value : String, search : Char) : Bool","location":{"filename":"src/validators/presence.cr","line_number":226,"url":null},"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 String value 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","args_html":"(value : String, search : Regex) : Bool","location":{"filename":"src/validators/presence.cr","line_number":231,"url":null},"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 String value 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","args_html":"(value : String, search : String) : Bool","location":{"filename":"src/validators/presence.cr","line_number":221,"url":null},"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","args_html":"(value : String) : Bool","location":{"filename":"src/validators/format.cr","line_number":31,"url":null},"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","args_html":"(value : String) : Bool","location":{"filename":"src/validators/case_sensitive.cr","line_number":15,"url":null},"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","args_html":"(value : String) : Bool","location":{"filename":"src/validators/uri.cr","line_number":55,"url":null},"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","args_html":"(value : String, version = 0) : Bool","location":{"filename":"src/validators/format.cr","line_number":103,"url":null},"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":null}],"repository_name":"validator","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[{"html_id":"validator/Check/ValidationError","kind":"class","full_name":"Check::ValidationError","name":"ValidationError"}],"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":"

    Used by is! when a validation is not true.

    ","class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[]}]}]}}) \ No newline at end of file diff --git a/shard.yml b/shard.yml index fad854c..be638e1 100644 --- a/shard.yml +++ b/shard.yml @@ -1,5 +1,5 @@ name: validator -version: 1.10.1 +version: 1.11.0 crystal: ">= 0.35.0" license: MIT diff --git a/src/check.cr b/src/check.cr index d5f3245..a3ed406 100644 --- a/src/check.cr +++ b/src/check.cr @@ -5,6 +5,7 @@ # information and documentation: https://github.com/Nicolab/crystal-validator # ------------------------------------------------------------------------------ +require "./validator" require "./checkable" # Standalone check module that provides a practical workflow for validations.