From e499ab4ae8b219c7ae5156aa03013b92cae87748 Mon Sep 17 00:00:00 2001 From: Nicolas Talle Date: Fri, 11 Sep 2020 15:19:53 +0200 Subject: [PATCH] [docs] v1.1.1 --- docs/Check.html | 474 ++++++ docs/Check/Checkable.html | 363 ++++ docs/Check/CheckableStatic.html | 489 ++++++ docs/Check/Checker.html | 214 +++ docs/Check/Errors.html | 213 +++ docs/Check/Validation.html | 730 ++++++++ docs/Valid.html | 228 +++ docs/Validator.html | 2807 +++++++++++++++++++++++++++++++ docs/Validator/Error.html | 231 +++ docs/css/style.css | 726 ++++++++ docs/index.html | 661 ++++++++ docs/index.json | 1 + docs/js/doc.js | 1086 ++++++++++++ docs/search-index.js | 1 + docs/toplevel.html | 268 +++ 15 files changed, 8492 insertions(+) create mode 100644 docs/Check.html create mode 100644 docs/Check/Checkable.html create mode 100644 docs/Check/CheckableStatic.html create mode 100644 docs/Check/Checker.html create mode 100644 docs/Check/Errors.html create mode 100644 docs/Check/Validation.html create mode 100644 docs/Valid.html create mode 100644 docs/Validator.html create mode 100644 docs/Validator/Error.html create mode 100644 docs/css/style.css create mode 100644 docs/index.html create mode 100644 docs/index.json create mode 100644 docs/js/doc.js create mode 100644 docs/search-index.js create mode 100644 docs/toplevel.html diff --git a/docs/Check.html b/docs/Check.html new file mode 100644 index 0000000..e7b120e --- /dev/null +++ b/docs/Check.html @@ -0,0 +1,474 @@ + + + + + + + + + + + + + + + + + Check - validator master + + + + + + + +
+

+ + module Check + +

+ + + + + +

+ + + + Overview +

+ +

Standalone check module that provides a practical workflow for validations.

+ + + + + + + + + + + + + + +

+ + + + Defined in: +

+ + + + check.cr + + +
+ + + + checkable.cr + + +
+ + + + + + + + +

+ + + + Class Method Summary +

+ + + + + + +

+ + + + Macro Summary +

+ + + + +
+ +
+ + + + +

+ + + + Class Method Detail +

+ +
+
+ + def self.new_validation(errors : Errors) + + # +
+ +
+ +

Initializes a new Validation instance to combine +a series of checks (Validation#check). +using an existing errors Hash (Check::Errors).

+ +
v = Check.new_validation existing_errors
+ +

Same as:

+ +
v = Check::Validation.new existing_errors
+ +

Example to combine two hashes of validation errors:

+ +
preview_validation = Check.new_validation
+v = Check.new_validation preview_validation.errors
+
+ +
+
+ + [View source] + +
+
+ +
+
+ + def self.new_validation + + # +
+ +
+ +

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

+ +
v = Check.new_validation
+ +

Same as:

+ +
v = Check::Validation.new
+
+ +
+
+ + [View source] + +
+
+ + + + + + +

+ + + + Macro Detail +

+ +
+
+ + macro checkable + + # +
+ +
+ +

A mixin to make a class checkable. +This mixin includes Checkable and CheckableStatic. +It must be used in conjonction with Check.rules.

+ +
require "validator/check"
+
+class Article
+  # Mixin
+  Check.checkable
+
+  property title : String
+  property content : String
+
+  Check.rules(
+    content: {
+      check: {
+        not_empty: {"Article content is required"},
+        between:   {"The article content must be between 10 and 20 000 characters", 10, 20_000},
+        # ...
+      },
+      clean: {
+        type:    String,
+        to:      :to_s,
+        format:  ->(content : String) { content.strip },
+        message: "Wrong type",
+      },
+    },
+  )
+end
+
+# Triggered on all data
+v, article = Article.check(input_data)
+
+# Triggered on a value
+v, content = Article.check_content(input_data["content"]?)
+
+ +
+
+ + [View source] + +
+
+ +
+
+ + macro rules(**fields) + + # +
+ +
+ +

Generates check, check_{{field}} and clean_{{field}} methods for fields (class variables).

+ +
require "validator/check"
+
+class Article
+  # Mixin
+  Check.checkable
+
+  property title : String
+  property content : String
+  property url : String?
+
+  Check.rules(
+    content: {
+      required: true,
+      check:    {
+        not_empty: {"Article content is required"},
+        between:   {"The article content must be between 10 and 20 000 characters", 10, 20_000},
+        # ...
+      },
+      clean: {
+        type:    String,
+        to:      :to_s,
+        format:  ->(content : String) { content.strip },
+        message: "Wrong type",
+      },
+    },
+    url: {
+      check: {
+        url: {"Article URL is invalid"},
+      },
+      clean: {
+        # `nilable` means omited if not provided,
+        # regardless of Crystal type (nilable or not)
+        nilable: true,
+        # Crystal type
+        type: String,
+        # Converter to the expected typed value
+        to: :to_s,
+      },
+    },
+      # ...
+)
+end
+
+# Triggered on all data
+v, article = Article.check(input_data)
+
+# Triggered on all fields of an instance
+article = Article.new(title: "foo", content: "bar")
+v = article.check
+
+# Triggered on a value
+v, content = Article.check_content(input_data["content"]?)
+
+# Cast and clean a value
+ok, content = Article.clean_content(input_data["content"]?)
+ +

See also Check.checkable.

+
+ +
+
+ + [View source] + +
+
+ + + +
+ + + diff --git a/docs/Check/Checkable.html b/docs/Check/Checkable.html new file mode 100644 index 0000000..9e1b315 --- /dev/null +++ b/docs/Check/Checkable.html @@ -0,0 +1,363 @@ + + + + + + + + + + + + + + + + + Check::Checkable - validator master + + + + + + + +
+

+ + module Check::Checkable + +

+ + + + + +

+ + + + Overview +

+ +

Mixin that adds #check method to be used with variables of an instance of the class including it. +The idea is to check the instance variables of the class extending it +against rules defined with Check.rules plus executing custom checkers defined with Checker.

+ + + + + + + + + + + + + + +

+ + + + Defined in: +

+ + + + checkable.cr + + +
+ + + + + + + + + + +

+ + + + Instance Method Summary +

+ + + + + + +
+ +
+ + + + + + +

+ + + + Instance Method Detail +

+ +
+
+ + def after_check(v : Check::Validation, required : Bool = true, format : Bool = true) + + # +
+ +
+ +

Lifecycle method triggered after each call of #check.

+ +
# Triggered on instance: `user.check`
+def after_check(v : Check::Validation, required : Bool = true, format : Bool = true)
+  # Code...
+end
+
+ +
+
+ + [View source] + +
+
+ +
+
+ + def before_check(v : Check::Validation, required : Bool = true, format : Bool = true) + + # +
+ +
+ +

Lifecycle method triggered before each call of #check.

+ +
# Triggered on instance: `user.check`
+def before_check(v : Check::Validation, required : Bool = true, format : Bool = true)
+  # Code...
+end
+
+ +
+
+ + [View source] + +
+
+ +
+
+ + def check(required : Bool = true, format : Bool = true) : Validation + + # +
+ +
+ +

Checks the instance fields and clean them.

+ +

It instantiates a Check::Validation (if not provided) and calls all methods +related to rules and then methods defined with annotation Checker.

+ +

Lifecycle methods #before_check and #after_check that are triggered +respectively at the beginning and at the end of the process.

+ +

format is used to tell cleaners generated by Check.rules +to execute format method if it has been defined.

+
+ +
+
+ + [View source] + +
+
+ +
+
+ + def check(v : Check::Validation, required : Bool = true, format : Bool = true) : Validation + + # +
+ +
+ +

Checks the instance fields and clean them.

+ +

It instantiates a Check::Validation (if not provided) and calls all methods +related to rules and then methods defined with annotation Checker.

+ +

Lifecycle methods #before_check and #after_check that are triggered +respectively at the beginning and at the end of the process.

+ +

format is used to tell cleaners generated by Check.rules +to execute format method if it has been defined.

+
+ +
+
+ + [View source] + +
+
+ + + + + +
+ + + diff --git a/docs/Check/CheckableStatic.html b/docs/Check/CheckableStatic.html new file mode 100644 index 0000000..c09d3ec --- /dev/null +++ b/docs/Check/CheckableStatic.html @@ -0,0 +1,489 @@ + + + + + + + + + + + + + + + + + Check::CheckableStatic - validator master + + + + + + + +
+

+ + module Check::CheckableStatic + +

+ + + + + +

+ + + + Overview +

+ +

Mixin that adds .check method to be used with a Hash. +The idea is to check a Hash against rules defined with Check.rules +plus executing custom checkers defined with Checker annotation.

+ + + + + + + + + + + + + + +

+ + + + Defined in: +

+ + + + checkable.cr + + +
+ + + + + + + + + + +

+ + + + Instance Method Summary +

+ + + + + + +
+ +
+ + + + + + +

+ + + + Instance Method Detail +

+ +
+
+ + def after_check(v : Check::Validation, h : Hash, cleaned_h : Hash, required : Bool = true, format : Bool = true) : Hash + + # +
+ +
+ +

Lifecycle method triggered after each call of .check.

+ +

This method (in static call) must returns the cleaned Hash +which is provided in the third argument. +You can update this cleaned hash but you have to return it.

+ +
# Triggered on a static call: `User.check(h)` (with a `Hash` or `JSON::Any`)
+def self.after_check(v : Check::Validation, h, cleaned_h, required : Bool = true, format : Bool = true) : Hash
+  # Code...
+  pp cleaned_h
+  cleaned_h # <= returns cleaned_h!
+end
+
+ +
+
+ + [View source] + +
+
+ +
+
+ + def before_check(v : Check::Validation, h : Hash, required : Bool = true, format : Bool = true) + + # +
+ +
+ +

Lifecycle method triggered before each call of .check.

+ +
# Triggered on a static call: `User.check(h)` (with a `Hash` or `JSON::Any`)
+def self.before_check(v : Check::Validation, h, required : Bool = true, format : Bool = true)
+  # Code...
+  pp h
+end
+
+ +
+
+ + [View source] + +
+
+ +
+
+ + def check(v : Check::Validation, h : Hash, required : Bool = true, format : Bool = true) + + # +
+ +
+ +

Checks and clean the Hash for its fields corresponding +to class variables that have a .check_{{field}} method.

+ +

It instantiates a Check::Validation (if not provided) and calls all methods +related to .rules and then methods defined with annotation Checker.

+ +

Lifecycle methods .before_check and .after_check that are called +respectively at the beginning and at the end of the process.

+ +

format is used to tell cleaners generated by Check.rules +to execute format method if it has been defined.

+
+ +
+
+ + [View source] + +
+
+ +
+
+ + def check(h : Hash, required : Bool = true, format : Bool = true) + + # +
+ +
+ +

Checks and clean the Hash for its fields corresponding +to class variables that have a .check_{{field}} method.

+ +

It instantiates a Check::Validation (if not provided) and calls all methods +related to .rules and then methods defined with annotation Checker.

+ +

Lifecycle methods .before_check and .after_check that are called +respectively at the beginning and at the end of the process.

+ +

format is used to tell cleaners generated by Check.rules +to execute format method if it has been defined.

+
+ +
+
+ + [View source] + +
+
+ +
+
+ + def h_from_json(json : String | IO) + + # +
+ +
+ +

Returns a Hash from a JSON input. +The return type is a tuple with a bool as a first argument indicating +that the JSON.parse has been processed successfully or not and the 2nd +argument is the json Hash.

+ +
ok, user_h = User.h_from_json(json) # => true, {"username" => "Bob", "email" => "user@example.com"}
+
+ +
+
+ + [View source] + +
+
+ +
+
+ + def map_json_keys : Hash(String, String) + + # +
+ +
+ +

Macro that returns the mapping of the JSON fields

+
+ +
+
+ + [View source] + +
+
+ +
+
+ + def to_crystal_h(h : Hash) : Hash + + # +
+ +
+ +

Returns a new Hash with all JSON keys converted to Crystal keys.

+
+ +
+
+ + [View source] + +
+
+ +
+
+ + def to_json_h(h : Hash) : Hash + + # +
+ +
+ +

Returns a new Hash with all Crystal keys converted to JSON keys.

+
+ +
+
+ + [View source] + +
+
+ + + + + +
+ + + diff --git a/docs/Check/Checker.html b/docs/Check/Checker.html new file mode 100644 index 0000000..fa2c68b --- /dev/null +++ b/docs/Check/Checker.html @@ -0,0 +1,214 @@ + + + + + + + + + + + + + + + + + Check::Checker - validator master + + + + + + + +
+

+ + annotation Check::Checker + +

+ + + + + +

+ + + + Overview +

+ +

Declare a method as a checker.

+ +
# Triggered by the instance.
+@[Check::Checker]
+def custom_checker(v : Check::Validation, required : Bool, format : Bool)
+  puts "custom checker triggered on instance"
+end
+
+# Triggered statically.
+@[Check::Checker]
+def self.custom_checker(v : Check::Validation, h, cleaned_h, required : Bool, format : Bool)
+  puts "custom checker triggered statically"
+  cleaned_h
+end
+ +

When .check and #check are called, the custom checkers are triggered respectively.

+ + + + + + + + + + + + + + +

+ + + + Defined in: +

+ + + + checkable.cr + + +
+ + + + + + + + + + + + + + +
+ +
+ + + + + + + + + +
+ + + diff --git a/docs/Check/Errors.html b/docs/Check/Errors.html new file mode 100644 index 0000000..2cd3c65 --- /dev/null +++ b/docs/Check/Errors.html @@ -0,0 +1,213 @@ + + + + + + + + + + + + + + + + + Check::Errors - validator master + + + + + + + +
+

+ + alias Check::Errors + +

+ + + + + +

+ + + + Overview +

+ +

Validation errors. +It's a Hash used as a container of errors, in order to handle them easily.

+ +
v = Check.new_validation
+pp v.errors
+ + + +

+ + + + Alias Definition +

+ Hash(String | Symbol, Array(String)) + + + + + + + + + + + + +

+ + + + Defined in: +

+ + + + check.cr + + +
+ + + + + + + + + + + + + + +
+ +
+ + + + + + + + + +
+ + + diff --git a/docs/Check/Validation.html b/docs/Check/Validation.html new file mode 100644 index 0000000..7bf5119 --- /dev/null +++ b/docs/Check/Validation.html @@ -0,0 +1,730 @@ + + + + + + + + + + + + + + + + + Check::Validation - validator master + + + + + + + +
+

+ + class Check::Validation + +

+ + + + + + + +

+ + + + Overview +

+ +

Combines a series of checks into one validation instance, +with a customized error message for each case.

+ +

A Validation instance provides the means to write sequential checks, +fine-tune each micro-validation with their own rules and custom error message, +the possibility to retrieve all error messages, etc.

+ +
Validation is also used with Check.rules and Check.checkable +that provide a powerful and productive system of validation rules +which makes data cleaning and data validation in Crystal very easy. +With self-generated granular methods for cleaning and checking data.
+ +

To use the checker (#check) includes in the Validation class:

+ +
require "validator/check"
+
+# Validates the *user* data received in the HTTP controller or other.
+def validate_user(user : Hash) : Check::Validation
+  v = Check.new_validation
+
+  # -- email
+
+  # Hash key can be a String or a Symbol
+  v.check :email, "The email is required.", is :presence?, :email, user
+
+  v.check "email", "The email is required.", is :presence?, "email", user
+  v.check "email", "#{user["email"]} is an invalid email.", is :email?, user["email"]
+
+  # -- username
+
+  v.check "username", "The username is required.", is :presence?, "username", user
+
+  v.check(
+    "username",
+    "The username must contain at least 2 characters.",
+    is :min?, user["username"], 2
+  )
+
+  v.check(
+    "username",
+    "The username must contain a maximum of 20 characters.",
+    is :max?, user["username"], 20
+  )
+end
+
+v = validate_user user
+
+pp v.valid? # => true (or false)
+
+# Inverse of v.valid?
+if v.errors.empty?
+  return "no error"
+end
+
+# display all the errors (if any)
+pp v.errors
+
+# It's a Hash of Array
+errors = v.errors
+
+puts errors.size
+puts errors.first_value
+
+errors.each do |key, messages|
+  puts key      # => "username"
+  puts messages # => ["The username is required.", "etc..."]
+end
+ +

3 methods #check:

+ +
# check(key : Symbol | String, valid : Bool)
+# Using default standard error message
+v.check(
+  "username",
+  is(:min?, user["username"], 2)
+)
+
+# check(key : Symbol | String, message : String, valid : Bool)
+# Using custom error message
+v.check(
+  "username",
+  "The username must contain at least 2 characters.",
+  is(:min?, user["username"], 2)
+)
+
+# check(key : Symbol | String, valid : Bool, message : String)
+# Using custom error message
+v.check(
+  "username",
+  is(:min?, user["username"], 2),
+  "The username must contain at least 2 characters."
+)
+ +

Check is a simple and lightweight wrapper. +Check::Validation is agnostic of the checked data, +of the context (model, controller, CSV file, HTTP data, socket data, JSON, etc).

+ +
Use case example: + Before saving to the database or process user data for a particular task, + the custom error messages can be used for the end user response.
+ +

But a Validation instance can be used just to store validation errors:

+ +
v = Check.new_validation
+v.add_error("foo", "foo error!")
+pp v.errors # => {"foo" => ["foo error!"]}
+ +
See also Check.rules and Check.checkable.
+ +

Let your imagination run wild to add your logic around it.

+ + + + + + + + + + + + + + +

+ + + + Defined in: +

+ + + + check.cr + + +
+ + + + + + +

+ + + + Constructors +

+ + + + + + +

+ + + + Instance Method Summary +

+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + +
+ + +

+ + + + Constructor Detail +

+ +
+
+ + def self.new(errors : Errors) + + # +
+ +
+ +

Initializes a validation using an existing errors Hash (Check::Errors).

+ +
v = Check::Validation.new
+ +

Same as:

+ +
v = Check.new_validation
+
+ +
+
+ + [View source] + +
+
+ +
+
+ + def self.new + + # +
+ +
+ +

Initializes a validation.

+ +
v = Check::Validation.new
+ +

Same as:

+ +
v = Check.new_validation
+
+ +
+
+ + [View source] + +
+
+ + + + + + +

+ + + + Instance Method Detail +

+ +
+
+ + def add_error(key : Symbol | String, message : String) : Validation + + # +
+ +
+ +

Add a validation error.

+ +
v = Check.new_validation
+v.add_error(:foo, "Foo error!")
+pp v.errors # => {:foo => ["Foo error!"]}
+ +

See also: Errors

+
+ +
+
+ + [View source] + +
+
+ +
+
+ + def add_error(key : Symbol | String) : Validation + + # +
+ +
+ +

Add a validation error.

+ +
By default a standard message is used.
+ +
v = Check.new_validation
+v.add_error(:foo)
+pp v.errors # => {:foo => ["\"foo\" is not valid."]}
+ +

See also: Errors

+
+ +
+
+ + [View source] + +
+
+ +
+
+ + def check(key : Symbol | String, message : String, valid : Bool) : Validation + + # +
+ +
+ +

Checks a validation, often used in sequence.

+ +

If valid is false, the error message is added in the #errors. +Nothing if valid is true.

+ +
v = Check.new_validation
+
+# -- email
+
+v.check :email, "The email is required.", is :presence?, :email, user
+v.check :email, "#{user[:email]} is an invalid email.", is :email?, user[:email]?
+
+# -- username
+
+v.check :username, "The username is required.", is :presence?, :username, user
+
+v.check(
+  :username,
+  "The username must contain at least 2 characters.",
+  is :min?, user[:username]?, 2
+)
+
+v.check(
+  :username,
+  "The username must contain a maximum of 20 characters.",
+  is :max?, user[:username]?, 20
+)
+
+# Print all errors
+pp v.errors
+
+ +
+
+ + [View source] + +
+
+ +
+
+ + def check(key : Symbol | String, valid : Bool, message : String) : Validation + + # +
+ +
+ +

Checks a validation, often used in sequence.

+ +

If valid is false, the error message is added in the #errors. +Nothing if valid is true.

+ +
v = Check.new_validation
+
+# -- email
+
+v.check(:email, is(:presence?, :email, user), "The email is required.")
+v.check(:email, is(:email?, user[:email]?), "#{user[:email]} is an invalid email.")
+
+# -- username
+
+v.check(:username, is(:presence?, :username, user), "The username is required.")
+
+v.check(
+  :username,
+  is :min?, user[:username]?, 2,
+    "The username must contain at least 2 characters."
+)
+
+v.check(
+  :username,
+  is :max?, user[:username]?, 20,
+    "The username must contain a maximum of 20 characters."
+)
+
+# Print all errors
+pp v.errors
+
+ +
+
+ + [View source] + +
+
+ +
+
+ + def check(key : Symbol | String, valid : Bool) : Validation + + # +
+ +
+ +

Checks a validation, often used in sequence.

+ +

If valid is false, an error message is added in the #errors. +Nothing if valid is true.

+ +
Unlike other #check methods, with this one a default standard message is used.
+ +
v = Check.new_validation
+
+v.check("email", Valid.presence?("email", user))
+v.check("email", Valid.email?(user["email"]?))
+
+# Print all errors
+pp v.errors
+
+ +
+
+ + [View source] + +
+
+ +
+
+ + def errors : Errors + + # +
+ +
+ +

Errors container.

+ +
v = Check.new_validation
+pp v.errors
+
+ +
+
+ + [View source] + +
+
+ +
+
+ + def valid? + + # +
+ +
+ +

Returns true if there is no error, false if there is one or more errors.

+ +
pp v.errors if !v.valid?
+# or with another flavor ;-)
+pp v.errors unless v.valid?
+
+ +
+
+ + [View source] + +
+
+ + + + + +
+ + + diff --git a/docs/Valid.html b/docs/Valid.html new file mode 100644 index 0000000..632ec04 --- /dev/null +++ b/docs/Valid.html @@ -0,0 +1,228 @@ + + + + + + + + + + + + + + + + + Valid - validator master + + + + + + + +
+

+ + alias Valid + +

+ + + + + +

+ + + + Overview +

+ +

Alias of Validator

+ + + +

+ + + + Alias Definition +

+ Validator + + + + + + + + + + + + +

+ + + + Defined in: +

+ + + + validator.cr + + +
+ + + + + +

+ + + + Constant Summary +

+ +
+ +
+ VERSION = {{ (`shards version \"/media/data/lab/dev/work/projects/nicolab/crystal/crystal-validator/src\"`).chomp.stringify.downcase }} +
+ + +
+ + + + + + + + + + + +
+ +
+ + + + + + + + + +
+ + + diff --git a/docs/Validator.html b/docs/Validator.html new file mode 100644 index 0000000..4f7b991 --- /dev/null +++ b/docs/Validator.html @@ -0,0 +1,2807 @@ + + + + + + + + + + + + + + + + + Validator - validator master + + + + + + + +
+

+ + module Validator + +

+ + + + + +

+ + + + Overview +

+ +

∠(・.-)―〉 →◎ validator is a Crystal data validation module. +Very simple and efficient, all validations return true or false.

+ +

Also validator/check +(not exposed by default) provides error message handling intended for the end user.

+ +

There are 2 main ways to use validator:

+ + + +

By default the validator module expose only Validator and Valid (alias) in the scope:

+ +
require "validator"
+
+Valid.email? "contact@example.org"                        # => true
+Valid.url? "https://github.com/Nicolab/crystal-validator" # => true
+Valid.my_validator? "value to validate", "hello", 42      # => true
+ +

An (optional) expressive validation flavor, is available as an alternative. \ +Not exposed by default, it must be imported:

+ +
require "validator/is"
+
+is :email?, "contact@example.org"                        # => true
+is :url?, "https://github.com/Nicolab/crystal-validator" # => true
+is :my_validator?, "value to validate", "hello", 42      # => true
+
+# raises an error if the email is not valid
+is! :email?, "contact@@example..org" # => Validator::Error
+ +

is is a macro, no overhead during the runtime 🚀 + By the nature of the macros, you can't pass the validator name dynamically + with a variable like that is(validator_name, "my value to validate", arg). + But of course you can pass arguments with variables is(:validator_name?, arg1, arg2).

+ +

+ +Check

+ +

Make a series of checks, with a customized error message for each case.

+ +
require "validator/check"
+
+check = Check.new
+
+check("email", "The email is required.", is :absence?, "email", user)
+ +

+ +Custom validator

+ +

Just add your own method to register a custom validator or to overload an existing validator.

+ +
module Validator
+  # My custom validator
+  def self.my_validator?(value, arg : String, another_arg : Int32) : Bool
+    # write here the logic of your validator...
+    return true
+  end
+end
+
+# Call it
+puts Valid.my_validator?("value to validate", "hello", 42) # => true
+
+# or with the `is` flavor
+puts is :my_validator?, "value to validate", "hello", 42 # => true
+ +

Check is a simple and lightweight wrapper, let your imagination run wild to add your logic around it.

+ +

Using the custom validator with the validation rules:

+ +
require "validator/check"
+
+class Article
+  # Mixin
+  Check.checkable
+
+  property title : String
+  property content : String
+
+  Check.rules(
+    content: {
+      # Now the custom validator is available
+      check: {
+        my_validator: {"My validator error message"},
+        between:      {"The article content must be between 10 and 20 000 characters", 10, 20_000},
+        # ...
+      },
+    },
+  )
+end
+
+# Triggered with all data
+v, article = Article.check(input_data)
+
+# Triggered with one value
+v, content = Article.check_content(input_data["content"]?)
+ + + + + + + + + + + + + + +

+ + + + Defined in: +

+ + + + validator.cr + + +
+ + + + validators/alpha_num.cr + + +
+ + + + validators/case_sensitive.cr + + +
+ + + + validators/comparisons.cr + + +
+ + + + validators/format.cr + + +
+ + + + validators/geo.cr + + +
+ + + + validators/presence.cr + + +
+ + + + validators/uri.cr + + +
+ + + + + +

+ + + + Constant Summary +

+ +
+ +
+ VERSION = {{ (`shards version \"/media/data/lab/dev/work/projects/nicolab/crystal/crystal-validator/src\"`).chomp.stringify.downcase }} +
+ + +
+ + + + + +

+ + + + Class Method Summary +

+ + + + + + + + +
+ +
+ + + + +

+ + + + Class Method Detail +

+ +
+
+ + def self.absence?(key : String | Symbol, list : NamedTuple) : Bool + + # +
+ +
+ +

Validates the absence of the value.

+ + +
+ +
+
+ + [View source] + +
+
+ +
+
+ + def self.absence?(key : String | Symbol | Number, list : Hash) : Bool + + # +
+ +
+ +

Validates the absence of the value.

+ + +
+ +
+
+ + [View source] + +
+
+ +
+
+ + def self.accepted?(value : String) : Bool + + # +
+ +
+ +

Validates that the value String is the representation of an acceptance.

+ +
One of: "yes", "y", "on", "o", "ok", "1", "true"
+ + +
+ +
+
+ + [View source] + +
+
+ +
+
+ + def self.accepted?(value) : Bool + + # +
+ +
+ +

Validates that the value is the representation of an acceptance.

+ +
One of: "yes", "y", "on", "o", "ok", "1", "true"
+ +

value must implements #to_s method.

+ + +
+ +
+
+ + [View source] + +
+
+ +
+
+ + def self.ascii_only?(value : String) : Bool + + # +
+ +
+ +

Validates that the value String +is comprised in its entirety by ASCII characters.

+
+ +
+
+ + [View source] + +
+
+ +
+
+ + def self.ascii_only?(values : Array(String)) : Bool + + # +
+ +
+ +

Validates that all the String in the values Array +are comprised in their entirety by ASCII characters.

+
+ +
+
+ + [View source] + +
+
+ +
+
+ + def self.base64?(value : String) : Bool + + # +
+ +
+ +

Validates that the value has the format base64.

+
+ +
+
+ + [View source] + +
+
+ +
+
+ + def self.between?(value, min, max) : Bool + + # +
+ +
+ +

Validates that the value is between (inclusive) min and max.

+
+ +
+
+ + [View source] + +
+
+ +
+
+ + def self.between?(value : String | Array, min : Int, max : Int) : Bool + + # +
+ +
+ +

Validates that the size of the value (String or Array) is between +(inclusive) min and max.

+ + +
+ +
+
+ + [View source] + +
+
+ +
+
+ + def self.domain?(value : String) : Bool + + # +
+ +
+
+ + [View source] + +
+
+ +
+
+ + def self.email?(value : String) : Bool + + # +
+ +
+ +

Validates that the value is an email. +This method is stricter than the standard allows. +It is subjectively based on the common addresses +of organisations (@enterprise.ltd, ...) +and mail services suck as Gmail, Hotmail, Yahoo !, ...

+
+ +
+
+ + [View source] + +
+
+ +
+
+ + def self.empty?(value) : Bool + + # +
+ +
+ +

Validates that the value is empty.

+ + +
+ +
+
+ + [View source] + +
+
+ +
+
+ + def self.ends?(value : String, search : String) : Bool + + # +
+ +
+ +

Validates that the String value ends with search.

+ + +
+ +
+
+ + [View source] + +
+
+ +
+
+ + def self.ends?(value : String, search : Char) : Bool + + # +
+ +
+ +

Validates that the String value ends with search.

+ + +
+ +
+
+ + [View source] + +
+
+ +
+
+ + def self.ends?(value : String, search : Regex) : Bool + + # +
+ +
+ +

Validates that the String value ends with search.

+ + +
+ +
+
+ + [View source] + +
+
+ +
+
+ + def self.eq?(value, another_value) : Bool + + # +
+ +
+ +

Validates that the value is equal to another_value.

+
+ +
+
+ + [View source] + +
+
+ +
+
+ + def self.gt?(value, another_value) : Bool + + # +
+ +
+ +

Validates that the value is greater than another_value.

+
+ +
+
+ + [View source] + +
+
+ +
+
+ + def self.gt?(value : String | Array, limit : Int) : Bool + + # +
+ +
+ +

Validates that the size of the value (String or Array) +is greater than limit number.

+
+ +
+
+ + [View source] + +
+
+ +
+
+ + def self.gte?(value, another_value) : Bool + + # +
+ +
+ +

Validates that the value is equal to or greater than another_value.

+ +
Similar to #min.
+
+ +
+
+ + [View source] + +
+
+ +
+
+ + def self.gte?(value : String | Array, min : Int) : Bool + + # +
+ +
+ +

Validates that the size of the value (String or Array) +is greater than min number.

+ +
Similar to #min.
+
+ +
+
+ + [View source] + +
+
+ +
+
+ + def self.hex?(value : String) : Bool + + # +
+ +
+ +

Validates that the String value does denote +a representation of a hexadecimal string.

+
+ +
+
+ + [View source] + +
+
+ +
+
+ + def self.hex?(value : Bytes) : Bool + + # +
+ +
+ +

Validates that the Bytes value does denote +a representation of a hexadecimal slice of Bytes.

+
+ +
+
+ + [View source] + +
+
+ +
+
+ + def self.hex_color?(value : String) : Bool + + # +
+ +
+ +

Validates that the String value does denote +a representation of a hexadecimal color.

+ +
Valid.hex_color? "#fff" => true
+Valid.hex_color? "#ffffff" => true
+
+ +
+
+ + [View source] + +
+
+ +
+
+ + def self.in?(value, list : Array) : Bool + + # +
+ +
+ +

Validates that the (list) contains the value.

+ + +
+ +
+
+ + [View source] + +
+
+ +
+
+ + def self.in?(value : String, str : String) : Bool + + # +
+ +
+ +

Validates that the (str) String contains the value.

+ + +
+ +
+
+ + [View source] + +
+
+ +
+
+ + def self.in?(key : Symbol | String, list : Hash) : Bool + + # +
+ +
+ +

Validates that the (list) contains the value.

+ + +
+ +
+
+ + [View source] + +
+
+ +
+
+ + def self.in?(key : Symbol | String, list : NamedTuple) : Bool + + # +
+ +
+ +

Validates that the (list) contains the value.

+ + +
+ +
+
+ + [View source] + +
+
+ +
+
+ + def self.in?(value, list : Range) : Bool + + # +
+ +
+ +

Validates that the (list) contains the value.

+ + +
+ +
+
+ + [View source] + +
+
+ +
+
+ + def self.in?(value, list : Tuple) : Bool + + # +
+ +
+ +

Validates that the (list) contains the value.

+ + +
+ +
+
+ + [View source] + +
+
+ +
+
+ + def self.ip?(value : String) : Bool + + # +
+ +
+ +

Validates that the value is an IP (IPv4 or IPv6).

+
+ +
+
+ + [View source] + +
+
+ +
+
+ + def self.ipv4?(value : String) : Bool + + # +
+ +
+ +

Validates that the value is an IPv4.

+
+ +
+
+ + [View source] + +
+
+ +
+
+ + def self.ipv6?(value : String) : Bool + + # +
+ +
+ +

Validates that the value is an IPv6.

+
+ +
+
+ + [View source] + +
+
+ +
+
+ + def self.json?(value : String, strict : Bool = true) : Bool + + # +
+ +
+ +

Validates that the value represents a JSON string. +strict to true (default) to try to parse the JSON, +returns false if the parsing fails. +If strict is false, only the first char and the last char are checked.

+
+ +
+
+ + [View source] + +
+
+ +
+
+ + def self.jwt?(value : String) : Bool + + # +
+ +
+ +

Validates that the value is a JSON Web Token.

+
+ +
+
+ + [View source] + +
+
+ +
+
+ + def self.lat?(value : String | Float) : Bool + + # +
+ +
+ +

Validates that the value is a valid format representation of a geographical latitude.

+ + +
+ +
+
+ + [View source] + +
+
+ +
+
+ + def self.lat_lng?(value : String) : Bool + + # +
+ +
+ +

Validates that the value is a valid format representation of +a geographical position (given in latitude and longitude).

+ + +
+ +
+
+ + [View source] + +
+
+ +
+
+ + def self.lng?(value : String | Float) : Bool + + # +
+ +
+ +

Validates that the value is a valid format representation of a geographical longitude.

+ + +
+ +
+
+ + [View source] + +
+
+ +
+
+ + def self.lower?(value : String) : Bool + + # +
+ +
+ +

Validates that the value is in lower case.

+
+ +
+
+ + [View source] + +
+
+ +
+
+ + def self.lt?(value : String | Array, limit : Int) : Bool + + # +
+ +
+ +

Validates that the size of the value (String or Array) +is lesser than limit number.

+
+ +
+
+ + [View source] + +
+
+ +
+
+ + def self.lt?(value, another_value) : Bool + + # +
+ +
+ +

Validates that the value is lesser than another_value.

+
+ +
+
+ + [View source] + +
+
+ +
+
+ + def self.lte?(value : String | Array, max : Int) : Bool + + # +
+ +
+ +

Validates that the size of the value (String or Array) +is equal or lesser than max number.

+ +
Similar to #max.
+
+ +
+
+ + [View source] + +
+
+ +
+
+ + def self.lte?(value, another_value) : Bool + + # +
+ +
+ +

Validates that the value is equal to or lesser than another_value.

+ +
Similar to #max.
+
+ +
+
+ + [View source] + +
+
+ +
+
+ + def self.mac_addr?(value : String, no_colons : Bool = false) : Bool + + # +
+ +
+ +

Validates that the value is a MAC address.

+
+ +
+
+ + [View source] + +
+
+ +
+
+ + def self.magnet_uri?(value : String) : Bool + + # +
+ +
+ +

Validates that the value is a Magnet URI.

+
+ +
+
+ + [View source] + +
+
+ +
+
+ + def self.match?(value : Number, pattern : Regex) : Bool + + # +
+ +
+ +

Validates that the value matches the pattern.

+
+ +
+
+ + [View source] + +
+
+ +
+
+ + def self.match?(value : String, pattern : Regex) : Bool + + # +
+ +
+ +

Validates that the value matches the pattern.

+
+ +
+
+ + [View source] + +
+
+ +
+
+ + def self.max?(value, max) : Bool + + # +
+ +
+ +

Validates that the value is equal to or lesser than max (inclusive).

+ +
Similar to #lte.
+
+ +
+
+ + [View source] + +
+
+ +
+
+ + def self.max?(value : String | Array, max : Int) : Bool + + # +
+ +
+ +

:ditto:

+ +
Based on the size of the String.
+
+ +
+
+ + [View source] + +
+
+ +
+
+ + def self.md5?(value : String) : Bool + + # +
+ +
+ +

Validates that the value has the format md5.

+
+ +
+
+ + [View source] + +
+
+ +
+
+ + def self.min?(value, min) : Bool + + # +
+ +
+ +

Validates that the value is equal to or greater than min (inclusive).

+ +
Similar to #gte.
+
+ +
+
+ + [View source] + +
+
+ +
+
+ + def self.min?(value : String | Array, min : Int) : Bool + + # +
+ +
+ +

:ditto:

+ +
Based on the size of the String.
+
+ +
+
+ + [View source] + +
+
+ +
+
+ + def self.mongo_id?(value : Bytes) : Bool + + # +
+ +
+ +

Validates that the Bytes value does denote +a representation of a MongoID slice of Bytes.

+
+ +
+
+ + [View source] + +
+
+ +
+
+ + def self.mongo_id?(value : String) : Bool + + # +
+ +
+ +

Validates that the String value does denote +a representation of a MongoID string.

+
+ +
+
+ + [View source] + +
+
+ +
+
+ + def self.not_empty?(value) : Bool + + # +
+ +
+ +

Validates that the value is not empty.

+ + +
+ +
+
+ + [View source] + +
+
+ +
+
+ + def self.not_in?(value : String, str : String) : Bool + + # +
+ +
+ +

Validates that the (str) String does not contain the value.

+ + +
+ +
+
+ + [View source] + +
+
+ +
+
+ + def self.not_in?(value, list : Array) : Bool + + # +
+ +
+ +

Validates that the (list) does not contain the value.

+ + +
+ +
+
+ + [View source] + +
+
+ +
+
+ + def self.not_in?(value, list : Tuple) : Bool + + # +
+ +
+ +

Validates that the (list) does not contain the value.

+ + +
+ +
+
+ + [View source] + +
+
+ +
+
+ + def self.not_in?(value, list : Range) : Bool + + # +
+ +
+ +

Validates that the (list) does not contain the value.

+ + +
+ +
+
+ + [View source] + +
+
+ +
+
+ + def self.not_in?(key : Symbol | String, list : NamedTuple) : Bool + + # +
+ +
+ +

Validates that the (list) does not contain the value.

+ + +
+ +
+
+ + [View source] + +
+
+ +
+
+ + def self.not_in?(key : Symbol | String, list : Hash) : Bool + + # +
+ +
+ +

Validates that the (list) does not contain the value.

+ + +
+ +
+
+ + [View source] + +
+
+ +
+
+ + def self.not_null?(value) : Bool + + # +
+ +
+ +

Validates that the value is not null (nil).

+ + +
+ +
+
+ + [View source] + +
+
+ +
+
+ + def self.null?(value) : Bool + + # +
+ +
+ +

Validates that the value is null (nil).

+ + +
+ +
+
+ + [View source] + +
+
+ +
+
+ + def self.number?(value : String) : Bool + + # +
+ +
+ +

Validates that the value is a numeric String representation.

+
+ +
+
+ + [View source] + +
+
+ +
+
+ + def self.port?(value : String = "0", min : String = "1", max : String = "65535") : Bool + + # +
+ +
+ +

Validates that the value is in a valid port range, +between (inclusive) 1 / min and 65535 / max.

+
+ +
+
+ + [View source] + +
+
+ +
+
+ + def self.port?(value = 0, min = 1, max = 65535) : Bool + + # +
+ +
+ +

Validates that the value is in a valid port range, +between (inclusive) 1 / min and 65535 / max.

+
+ +
+
+ + [View source] + +
+
+ +
+
+ + def self.presence?(key : String | Symbol, list : NamedTuple) : Bool + + # +
+ +
+ +

Validates the presence of the value.

+ + +
+ +
+
+ + [View source] + +
+
+ +
+
+ + def self.presence?(key : String | Symbol | Number, list : Hash) : Bool + + # +
+ +
+ +

Validates the presence of the value.

+ + +
+ +
+
+ + [View source] + +
+
+ +
+
+ + def self.refused?(value) : Bool + + # +
+ +
+ +

Returns true if the value is the representation of a refusal.

+ +
One of: "no", "n", "off", "0", "false"
+ +

value must implements #to_s method.

+ + +
+ +
+
+ + [View source] + +
+
+ +
+
+ + def self.refused?(value : String) : Bool + + # +
+ +
+ +

Validates that the value String is the representation of a refusal.

+ +
One of: "no", "n", "off", "0", "false"
+ + +
+ +
+
+ + [View source] + +
+
+ +
+
+ + def self.size?(value, size : Array(String)) + + # +
+ +
+ +

Validates that the value is in the size array.

+ + +
+ +
+
+ + [View source] + +
+
+ +
+
+ + def self.size?(value, size : Array(Int)) + + # +
+ +
+ +

Validates that the value is in the size array.

+ + +
+ +
+
+ + [View source] + +
+
+ +
+
+ + def self.size?(value, size : Range) + + # +
+ +
+ +

Validates that the value is in the size range.

+ + +
+ +
+
+ + [View source] + +
+
+ +
+
+ + def self.size?(value, size : String) + + # +
+ +
+ +

Validates that the value is equal to the size.

+
+ +
+
+ + [View source] + +
+
+ +
+
+ + def self.size?(value, size : Int) + + # +
+ +
+ +

Validates that the value is equal to the size.

+
+ +
+
+ + [View source] + +
+
+ +
+
+ + def self.slug?(value : String, min = 1, max = 100) : Bool + + # +
+ +
+ +

Validates that the value is a slug.

+
+ +
+
+ + [View source] + +
+
+ +
+
+ + def self.starts?(value : String, search : Char) : Bool + + # +
+ +
+ +

Validates that the String value starts with search.

+ + +
+ +
+
+ + [View source] + +
+
+ +
+
+ + def self.starts?(value : String, search : Regex) : Bool + + # +
+ +
+ +

Validates that the String value starts with search.

+ + +
+ +
+
+ + [View source] + +
+
+ +
+
+ + def self.starts?(value : String, search : String) : Bool + + # +
+ +
+ +

Validates that the String value starts with search.

+ + +
+ +
+
+ + [View source] + +
+
+ +
+
+ + def self.time?(value : String) : Bool + + # +
+ +
+ +

Validates that the value is a time String representation.

+
+ +
+
+ + [View source] + +
+
+ +
+
+ + def self.upper?(value : String) : Bool + + # +
+ +
+ +

Validates that the value is in upper case.

+
+ +
+
+ + [View source] + +
+
+ +
+
+ + def self.url?(value : String) : Bool + + # +
+ +
+ +

Validates that the value is a URL.

+
+ +
+
+ + [View source] + +
+
+ +
+
+ + def self.uuid?(value : String, version = 0) : Bool + + # +
+ +
+ +

Validates that the value is a UUID +Versions: 0 (all), 3, 4 and 5. version by default is 0 (all).

+
+ +
+
+ + [View source] + +
+
+ + + + + + + +
+ + + diff --git a/docs/Validator/Error.html b/docs/Validator/Error.html new file mode 100644 index 0000000..f95d404 --- /dev/null +++ b/docs/Validator/Error.html @@ -0,0 +1,231 @@ + + + + + + + + + + + + + + + + + Validator::Error - validator master + + + + + + + +
+

+ + class Validator::Error + +

+ + + + + + + +

+ + + + Overview +

+ +

Used by is! when a validation is not true.

+ + + + + + + + + + + + + + +

+ + + + Defined in: +

+ + + + validator.cr + + +
+ + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + +
+ + + diff --git a/docs/css/style.css b/docs/css/style.css new file mode 100644 index 0000000..20bb084 --- /dev/null +++ b/docs/css/style.css @@ -0,0 +1,726 @@ +html, body { + background: #FFFFFF; + position: relative; + margin: 0; + padding: 0; + width: 100%; + height: 100%; + overflow: hidden; +} + +body { + font-family: "Avenir", "Tahoma", "Lucida Sans", "Lucida Grande", Verdana, Arial, sans-serif; + color: #333; + line-height: 1.5; +} + +a { + color: #263F6C; +} + +a:visited { + color: #112750; +} + +h1, h2, h3, h4, h5, h6 { + margin: 35px 0 25px; + color: #444444; +} + +h1.type-name { + color: #47266E; + margin: 20px 0 30px; + background-color: #F8F8F8; + padding: 10px 12px; + border: 1px solid #EBEBEB; + border-radius: 2px; +} + +h2 { + border-bottom: 1px solid #E6E6E6; + padding-bottom: 5px; +} + +body { + display: flex; +} + +.sidebar, .main-content { + overflow: auto; +} + +.sidebar { + width: 30em; + color: #F8F4FD; + background-color: #2E1052; + padding: 0 0 30px; + box-shadow: inset -3px 0 4px rgba(0,0,0,.35); + line-height: 1.2; + z-index: 0; +} + +.sidebar .search-box { + padding: 13px 9px; +} + +.sidebar input { + display: block; + box-sizing: border-box; + margin: 0; + padding: 5px; + font: inherit; + font-family: inherit; + line-height: 1.2; + width: 100%; + border: 0; + outline: 0; + border-radius: 2px; + box-shadow: 0px 3px 5px rgba(0,0,0,.25); + transition: box-shadow .12s; +} + +.sidebar input:focus { + box-shadow: 0px 5px 6px rgba(0,0,0,.5); +} + +.sidebar input::-webkit-input-placeholder { /* Chrome/Opera/Safari */ + color: #C8C8C8; + font-size: 14px; + text-indent: 2px; +} + +.sidebar input::-moz-placeholder { /* Firefox 19+ */ + color: #C8C8C8; + font-size: 14px; + text-indent: 2px; +} + +.sidebar input:-ms-input-placeholder { /* IE 10+ */ + color: #C8C8C8; + font-size: 14px; + text-indent: 2px; +} + +.sidebar input:-moz-placeholder { /* Firefox 18- */ + color: #C8C8C8; + font-size: 14px; + text-indent: 2px; +} + +.project-summary { + padding: 9px 15px 30px 30px; +} + +.project-name { + font-size: 1.4rem; + margin: 0; + color: #f4f4f4; + font-weight: 600; +} + +.project-version { + margin-top: 5px; + display: inline-block; + position: relative; +} + +.project-version > form::after { + position: absolute; + right: 0; + top: 0; + content: "\25BC"; + font-size: .6em; + line-height: 1.2rem; + z-index: -1; +} + +.project-versions-nav { + cursor: pointer; + margin: 0; + padding: 0 .9em 0 0; + border: none; + -moz-appearance: none; + -webkit-appearance: none; + appearance: none; + background-color: transparent; + color: inherit; + font-family: inherit; + font-size: inherit; + line-height: inherit; +} +.project-versions-nav:focus { + outline: none; +} + +.project-versions-nav > option { + color: initial; +} + +.sidebar ul { + margin: 0; + padding: 0; + list-style: none outside; +} + +.sidebar li { + display: block; + position: relative; +} + +.types-list li.hide { + display: none; +} + +.sidebar a { + text-decoration: none; + color: inherit; + transition: color .14s; +} +.types-list a { + display: block; + padding: 5px 15px 5px 30px; +} + +.types-list { + display: block; +} + +.sidebar a:focus { + outline: 1px solid #D1B7F1; +} + +.types-list a { + padding: 5px 15px 5px 30px; +} + +.sidebar .current > a, +.sidebar a:hover { + color: #866BA6; +} + +.types-list li ul { + overflow: hidden; + height: 0; + max-height: 0; + transition: 1s ease-in-out; +} + +.types-list li.parent { + padding-left: 30px; +} + +.types-list li.parent::before { + box-sizing: border-box; + content: "▼"; + display: block; + width: 30px; + height: 30px; + position: absolute; + top: 0; + left: 0; + text-align: center; + color: white; + font-size: 8px; + line-height: 30px; + transform: rotateZ(-90deg); + cursor: pointer; + transition: .2s linear; +} + + +.types-list li.parent > a { + padding-left: 0; +} + +.types-list li.parent.open::before { + transform: rotateZ(0); +} + +.types-list li.open > ul { + height: auto; + max-height: 1000em; +} + +.main-content { + padding: 0 30px 30px 30px; + width: 100%; +} + +.kind { + font-size: 60%; + color: #866BA6; +} + +.superclass-hierarchy { + margin: -15px 0 30px 0; + padding: 0; + list-style: none outside; + font-size: 80%; +} + +.superclass-hierarchy .superclass { + display: inline-block; + margin: 0 7px 0 0; + padding: 0; +} + +.superclass-hierarchy .superclass + .superclass::before { + content: "<"; + margin-right: 7px; +} + +.other-types-list li { + display: inline-block; +} + +.other-types-list, +.list-summary { + margin: 0 0 30px 0; + padding: 0; + list-style: none outside; +} + +.entry-const { + font-family: Menlo, Monaco, Consolas, 'Courier New', Courier, monospace; +} + +.entry-const code { + white-space: pre-wrap; +} + +.entry-summary { + padding-bottom: 4px; +} + +.superclass-hierarchy .superclass a, +.other-type a, +.entry-summary .signature { + padding: 4px 8px; + margin-bottom: 4px; + display: inline-block; + background-color: #f8f8f8; + color: #47266E; + border: 1px solid #f0f0f0; + text-decoration: none; + border-radius: 3px; + font-family: Menlo, Monaco, Consolas, 'Courier New', Courier, monospace; + transition: background .15s, border-color .15s; +} + +.superclass-hierarchy .superclass a:hover, +.other-type a:hover, +.entry-summary .signature:hover { + background: #D5CAE3; + border-color: #624288; +} + +.entry-summary .summary { + padding-left: 32px; +} + +.entry-summary .summary p { + margin: 12px 0 16px; +} + +.entry-summary a { + text-decoration: none; +} + +.entry-detail { + padding: 30px 0; +} + +.entry-detail .signature { + position: relative; + padding: 5px 15px; + margin-bottom: 10px; + display: block; + border-radius: 5px; + background-color: #f8f8f8; + color: #47266E; + border: 1px solid #f0f0f0; + font-family: Menlo, Monaco, Consolas, 'Courier New', Courier, monospace; + transition: .2s ease-in-out; +} + +.entry-detail:target .signature { + background-color: #D5CAE3; + border: 1px solid #624288; +} + +.entry-detail .signature .method-permalink { + position: absolute; + top: 0; + left: -35px; + padding: 5px 15px; + text-decoration: none; + font-weight: bold; + color: #624288; + opacity: .4; + transition: opacity .2s; +} + +.entry-detail .signature .method-permalink:hover { + opacity: 1; +} + +.entry-detail:target .signature .method-permalink { + opacity: 1; +} + +.methods-inherited { + padding-right: 10%; + line-height: 1.5em; +} + +.methods-inherited h3 { + margin-bottom: 4px; +} + +.methods-inherited a { + display: inline-block; + text-decoration: none; + color: #47266E; +} + +.methods-inherited a:hover { + text-decoration: underline; + color: #6C518B; +} + +.methods-inherited .tooltip>span { + background: #D5CAE3; + padding: 4px 8px; + border-radius: 3px; + margin: -4px -8px; +} + +.methods-inherited .tooltip * { + color: #47266E; +} + +pre { + padding: 10px 20px; + margin-top: 4px; + border-radius: 3px; + line-height: 1.45; + overflow: auto; + color: #333; + background: #fdfdfd; + font-size: 14px; + border: 1px solid #eee; +} + +code { + font-family: Menlo, Monaco, Consolas, 'Courier New', Courier, monospace; +} + +:not(pre) > code { + background-color: rgba(40,35,30,0.05); + padding: 0.2em 0.4em; + font-size: 85%; + border-radius: 3px; +} + +span.flag { + padding: 2px 4px 1px; + border-radius: 3px; + margin-right: 3px; + font-size: 11px; + border: 1px solid transparent; +} + +span.flag.orange { + background-color: #EE8737; + color: #FCEBDD; + border-color: #EB7317; +} + +span.flag.yellow { + background-color: #E4B91C; + color: #FCF8E8; + border-color: #B69115; +} + +span.flag.green { + background-color: #469C14; + color: #E2F9D3; + border-color: #34700E; +} + +span.flag.red { + background-color: #BF1919; + color: #F9ECEC; + border-color: #822C2C; +} + +span.flag.purple { + background-color: #2E1052; + color: #ECE1F9; + border-color: #1F0B37; +} + +span.flag.lime { + background-color: #a3ff00; + color: #222222; + border-color: #00ff1e; +} + +.tooltip>span { + position: absolute; + opacity: 0; + display: none; + pointer-events: none; +} + +.tooltip:hover>span { + display: inline-block; + opacity: 1; +} + +.c { + color: #969896; +} + +.n { + color: #0086b3; +} + +.t { + color: #0086b3; +} + +.s { + color: #183691; +} + +.i { + color: #7f5030; +} + +.k { + color: #a71d5d; +} + +.o { + color: #a71d5d; +} + +.m { + color: #795da3; +} + +.hidden { + display: none; +} +.search-results { + font-size: 90%; + line-height: 1.3; +} + +.search-results mark { + color: inherit; + background: transparent; + font-weight: bold; +} +.search-result { + padding: 5px 8px 5px 5px; + cursor: pointer; + border-left: 5px solid transparent; + transform: translateX(-3px); + transition: all .2s, background-color 0s, border .02s; + min-height: 3.2em; +} +.search-result.current { + border-left-color: #ddd; + background-color: rgba(200,200,200,0.4); + transform: translateX(0); + transition: all .2s, background-color .5s, border 0s; +} +.search-result.current:hover, +.search-result.current:focus { + border-left-color: #866BA6; +} +.search-result:not(.current):nth-child(2n) { + background-color: rgba(255,255,255,.06); +} +.search-result__title { + font-size: 105%; + word-break: break-all; + line-height: 1.1; + padding: 3px 0; +} +.search-result__title strong { + font-weight: normal; +} +.search-results .search-result__title > a { + padding: 0; + display: block; +} +.search-result__title > a > .args { + color: #dddddd; + font-weight: 300; + transition: inherit; + font-size: 88%; + line-height: 1.2; + letter-spacing: -.02em; +} +.search-result__title > a > .args * { + color: inherit; +} + +.search-result a, +.search-result a:hover { + color: inherit; +} +.search-result:not(.current):hover .search-result__title > a, +.search-result:not(.current):focus .search-result__title > a, +.search-result__title > a:focus { + color: #866BA6; +} +.search-result:not(.current):hover .args, +.search-result:not(.current):focus .args { + color: #6a5a7d; +} + +.search-result__type { + color: #e8e8e8; + font-weight: 300; +} +.search-result__doc { + color: #bbbbbb; + font-size: 90%; +} +.search-result__doc p { + margin: 0; + text-overflow: ellipsis; + display: -webkit-box; + -webkit-box-orient: vertical; + -webkit-line-clamp: 2; + overflow: hidden; + line-height: 1.2em; + max-height: 2.4em; +} + +.js-modal-visible .modal-background { + display: flex; +} +.main-content { + position: relative; +} +.modal-background { + position: absolute; + display: none; + height: 100%; + width: 100%; + background: rgba(120,120,120,.4); + z-index: 100; + align-items: center; + justify-content: center; +} +.usage-modal { + max-width: 90%; + background: #fff; + border: 2px solid #ccc; + border-radius: 9px; + padding: 5px 15px 20px; + min-width: 50%; + color: #555; + position: relative; + transform: scale(.5); + transition: transform 200ms; +} +.js-modal-visible .usage-modal { + transform: scale(1); +} +.usage-modal > .close-button { + position: absolute; + right: 15px; + top: 8px; + color: #aaa; + font-size: 27px; + cursor: pointer; +} +.usage-modal > .close-button:hover { + text-shadow: 2px 2px 2px #ccc; + color: #999; +} +.modal-title { + margin: 0; + text-align: center; + font-weight: normal; + color: #666; + border-bottom: 2px solid #ddd; + padding: 10px; +} +.usage-list { + padding: 0; + margin: 13px; +} +.usage-list > li { + padding: 5px 2px; + overflow: auto; + padding-left: 100px; + min-width: 12em; +} +.usage-modal kbd { + background: #eee; + border: 1px solid #ccc; + border-bottom-width: 2px; + border-radius: 3px; + padding: 3px 8px; + font-family: monospace; + margin-right: 2px; + display: inline-block; +} +.usage-key { + float: left; + clear: left; + margin-left: -100px; + margin-right: 12px; +} +.doc-inherited { + font-weight: bold; +} + +.anchor { + float: left; + padding-right: 4px; + margin-left: -20px; +} + +.main-content .anchor .octicon-link { + width: 16px; + height: 16px; +} + +.main-content .anchor:focus { + outline: none +} + +.main-content h1:hover .anchor, +.main-content h2:hover .anchor, +.main-content h3:hover .anchor, +.main-content h4:hover .anchor, +.main-content h5:hover .anchor, +.main-content h6:hover .anchor { + text-decoration: none +} + +.main-content h1 .octicon-link, +.main-content h2 .octicon-link, +.main-content h3 .octicon-link, +.main-content h4 .octicon-link, +.main-content h5 .octicon-link, +.main-content h6 .octicon-link { + visibility: hidden +} + +.main-content h1:hover .anchor .octicon-link, +.main-content h2:hover .anchor .octicon-link, +.main-content h3:hover .anchor .octicon-link, +.main-content h4:hover .anchor .octicon-link, +.main-content h5:hover .anchor .octicon-link, +.main-content h6:hover .anchor .octicon-link { + visibility: visible +} diff --git a/docs/index.html b/docs/index.html new file mode 100644 index 0000000..f8e7ff9 --- /dev/null +++ b/docs/index.html @@ -0,0 +1,661 @@ + + + + + + + + + + + + + + + + + validator master + + + + + + + +
+

+ +validator

+ +

Build Status GitHub release Docs

+ +

∠(・.-)―〉 →◎ validator is a Crystal data validation module.<br> +Very simple and efficient, all validations return true or false.

+ +

Also validator/check (not exposed by default) provides:

+ + + +

Validator respects the KISS principle and the Unix Philosophy. It's a great basis tool for doing your own validation logic on top of it.

+ +

+ +Installation

+ +
  1. Add the dependency to your shard.yml:
+ +
dependencies:
+  validator:
+    github: nicolab/crystal-validator
+    version: ~> 1.1.0 # Check the latest version!
+ +
  1. Run shards install
+ +

+ +Usage

+ + + +

There are 3 main ways to use validator:

+ + + +

By default the validator module expose only Validator and Valid (alias) in the scope:

+ +
require "validator"
+
+Valid.email? "contact@example.org" # => true
+Valid.url? "https://github.com/Nicolab/crystal-validator" # => true
+Valid.my_validator? "value to validate", "hello", 42 # => true
+ +

An (optional) expressive validation flavor, is available as an alternative. +Not exposed by default, it must be imported:

+ +
require "validator/is"
+
+is :email?, "contact@example.org" # => true
+is :url?, "https://github.com/Nicolab/crystal-validator" # => true
+is :my_validator?, "value to validate", "hello", 42 # => true
+
+
+# raises an error if the email is not valid
+is! :email?, "contact@@example..org" # => Validator::Error
+ +

is is a macro, no overhead during the runtime 🚀 + By the nature of the macros, you can't pass the validator name dynamically with a variable like that is(validator_name, "my value to validate", arg). + But of course you can pass arguments with variables is(:validator_name?, arg1, arg2).

+ + + +

+ +Validation rules

+ +
require "validator/check"
+
+class User
+    # Mixin
+    Check.checkable
+
+    property email : String
+    property age : Int32
+    property bio : String?
+
+    Check.rules(
+      # required
+      email: {
+        required: true,
+
+        # Checker (all validators are supported)
+        check: {
+          not_empty: {"Email is required"},
+          email:     {"It is not a valid email"},
+        },
+
+        # Cleaner
+        clean: {
+          # Data type
+          type: String,
+
+          # Converter (if union or other) to the expected value type.
+          # Example if the input value is i32, but i64 is expected
+          # Here is a String
+          to: :to_s,
+
+          # Formatter (any Crystal Proc)
+          format: ->self.format_email(String),
+
+          # Error message
+          # Default is "Wrong type" but it can be customized
+          message: "Oops! Wrong type.",
+        },
+      },
+
+      # required
+      age: {
+        required: true,
+        check: {
+          min:     {"Age should be more than 18", 18},
+          between: {"Age should be between 25 and 35", 25, 35},
+        },
+        clean: {type: Int32, to: :to_i32, message: "Unable to cast to Int32"},
+      },
+
+      # nilable
+      bio: {
+        check: {
+          between: {"The user bio must be between 2 and 400 characters.", 2, 400},
+        },
+        clean: {
+          type: String,
+          to: :to_s,
+          # `nilable` means omited if not provided,
+          # regardless of Crystal type (nilable or not)
+          nilable: true
+        },
+      },
+    )
+
+    def initialize(@email, @age); end
+
+    # ---------------------------------------------------------------------------
+    # Lifecycle methods (hooks)
+    # ---------------------------------------------------------------------------
+
+    # Triggered on instance: `user.check`
+    def before_check(v : Check::Validation, required : Bool, format : Bool)
+      # Code...
+    end
+
+    # Triggered on instance: `user.check`
+    def after_check(v : Check::Validation, required : Bool, format : Bool)
+      # Code...
+    end
+
+    # Triggered on a static call: `User.check(h)` (with a `Hash` or `JSON::Any`)
+    def self.before_check(v : Check::Validation, h, required : Bool, format : Bool)
+      # Code...
+      pp h
+    end
+
+    # Triggered on a static call: `User.check(h)` (with a `Hash` or `JSON::Any`)
+    def self.after_check(v : Check::Validation, h, cleaned_h, required : Bool, format : Bool)
+      # Code...
+      pp cleaned_h
+      cleaned_h # <= returns cleaned_h!
+    end
+
+    # --------------------------------------------------------------------------
+    #  Custom checkers
+    # --------------------------------------------------------------------------
+
+    # Triggered on instance: `user.check`
+    @[Check::Checker]
+    def custom_checker(v : Check::Validation, required : Bool, format : Bool)
+      self.custom_checker_called = true
+    end
+
+     # Triggered on a static call: `User.check(h)` (with a `Hash` or `JSON::Any`)
+    @[Check::Checker]
+    def self.custom_checker(v : Check::Validation, h, cleaned_h, required : Bool, format : Bool)
+      @@custom_checker_called = true
+      cleaned_h # <= returns cleaned_h!
+    end
+
+    # --------------------------------------------------------------------------
+    #  Formatters
+    # --------------------------------------------------------------------------
+
+    # Format (convert) email.
+    def self.format_email(email)
+      puts "mail stripped"
+      email.strip
+    end
+
+    # --------------------------------------------------------------------------
+    # Normal methods
+    # --------------------------------------------------------------------------
+
+    def foo()
+      # Code...
+    end
+
+    def self.bar(v)
+      # Code...
+    end
+
+    # ...
+  end
+ +

Check with this example class (User):

+ +
# Check a Hash (statically)
+v, user_h = User.check(input_h)
+
+pp v # => Validation instance
+pp v.valid?
+pp v.errors
+
+pp user_h # => Casted and cleaned Hash
+
+# Check a Hash (on instance)
+user = user.new("demo@example.org", 38)
+
+v = user.check # => Validation instance
+pp v.valid?
+pp v.errors
+
+# Check field
+v, email = User.check_email(value: "demo@example.org")
+v, age = User.check_age(value: 42)
+
+v, email = User.check_email(value: "demo@example.org ", format: true)
+v, email = User.check_email(value: "demo@example.org ", format: false)
+
+# Using an existing Validation instance
+v = Check.new_validation
+v, email = User.check_email(v, value: "demo@example.org")
+ +

Clean with this example class (User):

+ +
# `check` method cleans all values of the Hash (or JSON::Any),
+# before executing the validation rules
+v, user_h = User.check(input_h)
+
+pp v # => Validation instance
+pp v.valid?
+pp v.errors
+
+pp user_h # => Casted and cleaned Hash
+
+# Cast and clean field
+ok, email = User.clean_email(value: "demo@example.org")
+ok, age = User.clean_age(value: 42)
+
+ok, email = User.clean_email(value: "demo@example.org ", format: true)
+ok, email = User.clean_email(value: "demo@example.org ", format: false)
+
+puts "${email} is casted and cleaned" if ok
+# or
+puts "Email type error" unless ok
+ + + +

More details about cleaning, casting, formatting and return values:

+ +

By default format is true, to disable:

+ +
ok, email = User.clean_email(value: "demo@example.org", format: false)
+# or
+ok, email = User.clean_email("demo@example.org", false)
+ +

Always use named argument if there is only one (the value):

+ +
ok, email = User.clean_email(value: "demo@example.org")
+ +

ok is a boolean value that reports whether the cast succeeded. Like the type assertions in Go (lang). +But the ok value is returned in first (like in Elixir lang) for easy handling of multiple return values (Tuple).

+ +

Example with multiple values returned:

+ +
ok, value1, value2 = User.clean_my_tuple({1, 2, 3})
+ +

Considering the example class above (User). +As a reminder, the email field has been defined with the formatter below:

+ +
Check.rules(
+  email: {
+    clean: {
+      type:    String,
+      to:      :to_s,
+      format:  ->self.format_email(String), # <= Here!
+      message: "Wrong type",
+    },
+  },
+)
+
+# ...
+
+# Format (convert) email.
+def self.format_email(email)
+  puts "mail stripped"
+  email.strip
+end
+ +

So clean_email cast to String and strip the value " demo@example.org ":

+ +
# Email value with one space before and one space after
+ok, email = User.clean_email(value: " demo@example.org ")
+
+puts email # => "demo@example.org"
+ +

If the email was taken from a union type (json["email"]?), the returned email variable would be a String too.

+ +

See more examples.

+ +
NOTE: Require more explanations about required, nilable rules. +> Also about the converters JSON / Crystal Hash: h_from_json, to_json_h, to_crystal_h. +> In the meantime see the API doc.
+ +

+ +Validation#check

+ +

To perform a series of validations with error handling, the validator/check module offers this possibility 👍

+ +

A Validation instance provides the means to write sequential checks, fine-tune each micro-validation with their own rules and custom error message, the possibility to retrieve all error messages, etc.

+ +
Validation is also used with Check.rules and Check.checkable + that provide a powerful and productive system of validation rules + which makes data cleaning and data validation in Crystal very easy. + With self-generated granular methods for cleaning and checking data.
+ +

To use the checker (check) includes in the Validation class:

+ +
require "validator/check"
+
+# Validates the *user* data received in the HTTP controller or other.
+def validate_user(user : Hash) : Check::Validation
+  v = Check.new_validation
+
+  # -- email
+
+  # Hash key can be a String or a Symbol
+  v.check :email, "The email is required.", is :presence?, :email, user
+
+  v.check "email", "The email is required.", is :presence?, "email", user
+  v.check "email", "#{user["email"]} is an invalid email.", is :email?, user["email"]
+
+  # -- username
+
+  v.check "username", "The username is required.", is :presence?, "username", user
+
+  v.check(
+    "username",
+    "The username must contain at least 2 characters.",
+    is :min?, user["username"], 2
+  )
+
+  v.check(
+    "username",
+    "The username must contain a maximum of 20 characters.",
+    is :max?, user["username"], 20
+  )
+end
+
+v = validate_user user
+
+pp v.valid? # => true (or false)
+
+# Inverse of v.valid?
+if v.errors.empty?
+  return "no error"
+end
+
+# Print all the errors (if any)
+pp v.errors
+
+# It's a Hash of Array
+errors = v.errors
+
+puts errors.size
+puts errors.first_value
+
+errors.each do |key, messages|
+  puts key   # => "username"
+  puts messages # => ["The username is required.", "etc..."]
+end
+ +

3 methods #check:

+ +
# check(key : Symbol | String, valid : Bool)
+# Using default error message
+v.check(
+  "username",
+  is(:min?, user["username"], 2)
+)
+
+# check(key : Symbol | String, message : String, valid : Bool)
+# Using custom error message
+v.check(
+  "username",
+  "The username must contain at least 2 characters.",
+  is(:min?, user["username"], 2)
+)
+
+# check(key : Symbol | String, valid : Bool, message : String)
+# Using custom error message
+v.check(
+  "username",
+  is(:min?, user["username"], 2),
+  "The username must contain at least 2 characters."
+)
+ +

Check is a simple and lightweight wrapper. +The Check::Validation is agnostic of the checked data, +of the context (model, controller, CSV file, HTTP data, socket data, JSON, etc).

+ +
Use case example: + Before saving to the database or process user data for a particular task, + the custom error messages can be used for the end user response.
+ +

But a Validation instance can be used just to store validation errors:

+ +
v = Check.new_validation
+v.add_error("foo", "foo error!")
+pp v.errors # => {"foo" => ["foo error!"]}
+ +
See also Check.rules and Check.checkable.
+ +

Let your imagination run wild to add your logic around it.

+ +

+ +Custom validator

+ +

Just add your own method to register a custom validator or to overload an existing validator.

+ +
module Validator
+  # My custom validator
+  def self.my_validator?(value, arg : String, another_arg : Int32) : Bool
+    # write here the logic of your validator...
+    return true
+  end
+end
+
+# Call it
+puts Valid.my_validator?("value to validate", "hello", 42) # => true
+
+# or with the `is` flavor
+puts is :my_validator?, "value to validate", "hello", 42 # => true
+ +

Using the custom validator with the validation rules:

+ +
require "validator/check"
+
+class Article
+  # Mixin
+  Check.checkable
+
+  property title : String
+  property content : String
+
+  Check.rules(
+    content: {
+      # Now the custom validator is available
+      check: {
+        my_validator: {"My validator error message"},
+        between: {"The article content must be between 10 and 20 000 characters", 10, 20_000},
+        # ...
+      },
+    },
+  )
+end
+
+# Triggered with all data
+v, article = Article.check(input_data)
+
+# Triggered with one value
+v, content = Article.check_content(input_data["content"]?)
+ +

+ +Conventions

+ + + +

+ +Development

+ +
crystal spec
+crystal tool format
+ +
TODO: add ameba?
+ +

+ +Contributing

+ +
  1. Fork it (<https://github.com/nicolab/crystal-validator/fork>)
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request
+ +

+ +LICENSE

+ +

MIT (c) 2020, Nicolas Talle.

+ +

+ +Author

+ +

| Nicolas Tallefourtane - Nicolab.net | +|---| +| Nicolas Talle | +| Make a donation via Paypal |

+ +
Thanks to ilourt for his great work on checkable mixins (clean_, check_, ...).
+
+ + diff --git a/docs/index.json b/docs/index.json new file mode 100644 index 0000000..7a67937 --- /dev/null +++ b/docs/index.json @@ -0,0 +1 @@ +{"repository_name":"validator","body":"# validator\n\n[![Build Status](https://travis-ci.com/Nicolab/crystal-validator.svg?branch=master)](https://travis-ci.com/Nicolab/crystal-validator) [![GitHub release](https://img.shields.io/github/release/Nicolab/crystal-validator.svg)](https://github.com/Nicolab/crystal-validator/releases) [![Docs](https://img.shields.io/badge/docs-available-brightgreen.svg)](https://nicolab.github.io/crystal-validator/)\n\n∠(・.-)―〉 →◎ `validator` is a [Crystal](https://crystal-lang.org) data validation module.
\nVery simple and efficient, all validations return `true` or `false`.\n\nAlso [validator/check](#check) (not exposed by default) provides:\n\n* Error message handling intended for the end user.\n* Also (optional) a powerful and productive system of validation rules.\n With self-generated granular methods for cleaning and checking data.\n\n**Validator** respects the [KISS principle](https://en.wikipedia.org/wiki/KISS_principle) and the [Unix Philosophy](https://en.wikipedia.org/wiki/Unix_philosophy). It's a great basis tool for doing your own validation logic on top of it.\n\n## Installation\n\n1. Add the dependency to your `shard.yml`:\n\n```yaml\ndependencies:\n validator:\n github: nicolab/crystal-validator\n version: ~> 1.1.0 # Check the latest version!\n```\n\n2. Run `shards install`\n\n## Usage\n\n* [Validator - API docs](https://nicolab.github.io/crystal-validator/)\n\nThere are 3 main ways to use *validator*:\n\n* As a simple validator to check rules (eg: email, url, min, max, presence, in, ...) which return a boolean.\n* As a more advanced validation system which will check a series of rules and returns all validation errors encountered with custom or standard messages.\n* As a system of validation rules (inspired by the _Laravel framework's Validator_)\n which makes data cleaning and data validation in Crystal very easy!\n With self-generated granular methods for cleaning and checking data of each field.\n\nBy default the **validator** module expose only `Validator` and `Valid` (alias) in the scope:\n\n```crystal\nrequire \"validator\"\n\nValid.email? \"contact@example.org\" # => true\nValid.url? \"https://github.com/Nicolab/crystal-validator\" # => true\nValid.my_validator? \"value to validate\", \"hello\", 42 # => true\n```\n\nAn (optional) expressive validation flavor, `is` available as an alternative.\nNot exposed by default, it must be imported:\n\n```crystal\nrequire \"validator/is\"\n\nis :email?, \"contact@example.org\" # => true\nis :url?, \"https://github.com/Nicolab/crystal-validator\" # => true\nis :my_validator?, \"value to validate\", \"hello\", 42 # => true\n\n\n# raises an error if the email is not valid\nis! :email?, \"contact@@example..org\" # => Validator::Error\n```\n\n`is` is a macro, no overhead during the runtime 🚀\n By the nature of the macros, you can't pass the *validator* name dynamically with a variable like that `is(validator_name, \"my value to validate\", arg)`.\n But of course you can pass arguments with variables `is(:validator_name?, arg1, arg2)`.\n\n* [Validator - API docs](https://nicolab.github.io/crystal-validator/)\n\n### Validation rules\n\n```crystal\nrequire \"validator/check\"\n\nclass User\n # Mixin\n Check.checkable\n\n property email : String\n property age : Int32\n property bio : String?\n\n Check.rules(\n # required\n email: {\n required: true,\n\n # Checker (all validators are supported)\n check: {\n not_empty: {\"Email is required\"},\n email: {\"It is not a valid email\"},\n },\n\n # Cleaner\n clean: {\n # Data type\n type: String,\n\n # Converter (if union or other) to the expected value type.\n # Example if the input value is i32, but i64 is expected\n # Here is a String\n to: :to_s,\n\n # Formatter (any Crystal Proc)\n format: ->self.format_email(String),\n\n # Error message\n # Default is \"Wrong type\" but it can be customized\n message: \"Oops! Wrong type.\",\n },\n },\n\n # required\n age: {\n required: true,\n check: {\n min: {\"Age should be more than 18\", 18},\n between: {\"Age should be between 25 and 35\", 25, 35},\n },\n clean: {type: Int32, to: :to_i32, message: \"Unable to cast to Int32\"},\n },\n\n # nilable\n bio: {\n check: {\n between: {\"The user bio must be between 2 and 400 characters.\", 2, 400},\n },\n clean: {\n type: String,\n to: :to_s,\n # `nilable` means omited if not provided,\n # regardless of Crystal type (nilable or not)\n nilable: true\n },\n },\n )\n\n def initialize(@email, @age); end\n\n # ---------------------------------------------------------------------------\n # Lifecycle methods (hooks)\n # ---------------------------------------------------------------------------\n\n # Triggered on instance: `user.check`\n def before_check(v : Check::Validation, required : Bool, format : Bool)\n # Code...\n end\n\n # Triggered on instance: `user.check`\n def after_check(v : Check::Validation, required : Bool, format : Bool)\n # Code...\n end\n\n # Triggered on a static call: `User.check(h)` (with a `Hash` or `JSON::Any`)\n def self.before_check(v : Check::Validation, h, required : Bool, format : Bool)\n # Code...\n pp h\n end\n\n # Triggered on a static call: `User.check(h)` (with a `Hash` or `JSON::Any`)\n def self.after_check(v : Check::Validation, h, cleaned_h, required : Bool, format : Bool)\n # Code...\n pp cleaned_h\n cleaned_h # <= returns cleaned_h!\n end\n\n # --------------------------------------------------------------------------\n # Custom checkers\n # --------------------------------------------------------------------------\n\n # Triggered on instance: `user.check`\n @[Check::Checker]\n def custom_checker(v : Check::Validation, required : Bool, format : Bool)\n self.custom_checker_called = true\n end\n\n # Triggered on a static call: `User.check(h)` (with a `Hash` or `JSON::Any`)\n @[Check::Checker]\n def self.custom_checker(v : Check::Validation, h, cleaned_h, required : Bool, format : Bool)\n @@custom_checker_called = true\n cleaned_h # <= returns cleaned_h!\n end\n\n # --------------------------------------------------------------------------\n # Formatters\n # --------------------------------------------------------------------------\n\n # Format (convert) email.\n def self.format_email(email)\n puts \"mail stripped\"\n email.strip\n end\n\n # --------------------------------------------------------------------------\n # Normal methods\n # --------------------------------------------------------------------------\n\n def foo()\n # Code...\n end\n\n def self.bar(v)\n # Code...\n end\n\n # ...\n end\n```\n\n__Check__ with this example class (`User`):\n\n```crystal\n# Check a Hash (statically)\nv, user_h = User.check(input_h)\n\npp v # => Validation instance\npp v.valid?\npp v.errors\n\npp user_h # => Casted and cleaned Hash\n\n# Check a Hash (on instance)\nuser = user.new(\"demo@example.org\", 38)\n\nv = user.check # => Validation instance\npp v.valid?\npp v.errors\n\n# Check field\nv, email = User.check_email(value: \"demo@example.org\")\nv, age = User.check_age(value: 42)\n\nv, email = User.check_email(value: \"demo@example.org \", format: true)\nv, email = User.check_email(value: \"demo@example.org \", format: false)\n\n# Using an existing Validation instance\nv = Check.new_validation\nv, email = User.check_email(v, value: \"demo@example.org\")\n```\n\n__Clean__ with this example class (`User`):\n\n```crystal\n# `check` method cleans all values of the Hash (or JSON::Any),\n# before executing the validation rules\nv, user_h = User.check(input_h)\n\npp v # => Validation instance\npp v.valid?\npp v.errors\n\npp user_h # => Casted and cleaned Hash\n\n# Cast and clean field\nok, email = User.clean_email(value: \"demo@example.org\")\nok, age = User.clean_age(value: 42)\n\nok, email = User.clean_email(value: \"demo@example.org \", format: true)\nok, email = User.clean_email(value: \"demo@example.org \", format: false)\n\nputs \"${email} is casted and cleaned\" if ok\n# or\nputs \"Email type error\" unless ok\n```\n\n* `clean_*` methods are useful to caste a union value (like `Hash` or `JSON::Any`).\n* Also `clean_*` methods are optional and handy for formatting values, such as the strip on the email in the example `User` class.\n\nMore details about cleaning, casting, formatting and return values:\n\nBy default `format` is `true`, to disable:\n\n```crystal\nok, email = User.clean_email(value: \"demo@example.org\", format: false)\n# or\nok, email = User.clean_email(\"demo@example.org\", false)\n```\n\nAlways use named argument if there is only one (the `value`):\n\n```crystal\nok, email = User.clean_email(value: \"demo@example.org\")\n```\n\n`ok` is a boolean value that reports whether the cast succeeded. Like the type assertions in _Go_ (lang).\nBut the `ok` value is returned in first (like in _Elixir_ lang) for easy handling of multiple return values (`Tuple`).\n\nExample with multiple values returned:\n\n```crystal\nok, value1, value2 = User.clean_my_tuple({1, 2, 3})\n```\n\nConsidering the example class above (`User`).\nAs a reminder, the email field has been defined with the formatter below:\n\n```crystal\nCheck.rules(\n email: {\n clean: {\n type: String,\n to: :to_s,\n format: ->self.format_email(String), # <= Here!\n message: \"Wrong type\",\n },\n },\n)\n\n# ...\n\n# Format (convert) email.\ndef self.format_email(email)\n puts \"mail stripped\"\n email.strip\nend\n```\n\nSo `clean_email` cast to `String` and strip the value `\" demo@example.org \"`:\n\n```crystal\n# Email value with one space before and one space after\nok, email = User.clean_email(value: \" demo@example.org \")\n\nputs email # => \"demo@example.org\"\n```\n\nIf the email was taken from a union type (`json[\"email\"]?`), the returned `email` variable would be a `String` too.\n\nSee [more examples](https://github.com/Nicolab/crystal-validator/tree/master/examples).\n\n> NOTE: Require more explanations about `required`, `nilable` rules.\n> Also about the converters JSON / Crystal Hash: `h_from_json`, `to_json_h`, `to_crystal_h`.\n> In the meantime see the [API doc](https://nicolab.github.io/crystal-validator/Check/Checkable.html).\n\n### Validation#check\n\nTo perform a series of validations with error handling, the [validator/check](https://nicolab.github.io/crystal-validator/Check.html) module offers this possibility 👍\n\nA [Validation](https://nicolab.github.io/crystal-validator/Check/Validation.html) instance provides the means to write sequential checks, fine-tune each micro-validation with their own rules and custom error message, the possibility to retrieve all error messages, etc.\n\n> `Validation` is also used with `Check.rules` and `Check.checkable`\n that provide a powerful and productive system of validation rules\n which makes data cleaning and data validation in Crystal very easy.\n With self-generated granular methods for cleaning and checking data.\n\nTo use the checker (`check`) includes in the `Validation` class:\n\n```crystal\nrequire \"validator/check\"\n\n# Validates the *user* data received in the HTTP controller or other.\ndef validate_user(user : Hash) : Check::Validation\n v = Check.new_validation\n\n # -- email\n\n # Hash key can be a String or a Symbol\n v.check :email, \"The email is required.\", is :presence?, :email, user\n\n v.check \"email\", \"The email is required.\", is :presence?, \"email\", user\n v.check \"email\", \"#{user[\"email\"]} is an invalid email.\", is :email?, user[\"email\"]\n\n # -- username\n\n v.check \"username\", \"The username is required.\", is :presence?, \"username\", user\n\n v.check(\n \"username\",\n \"The username must contain at least 2 characters.\",\n is :min?, user[\"username\"], 2\n )\n\n v.check(\n \"username\",\n \"The username must contain a maximum of 20 characters.\",\n is :max?, user[\"username\"], 20\n )\nend\n\nv = validate_user user\n\npp v.valid? # => true (or false)\n\n# Inverse of v.valid?\nif v.errors.empty?\n return \"no error\"\nend\n\n# Print all the errors (if any)\npp v.errors\n\n# It's a Hash of Array\nerrors = v.errors\n\nputs errors.size\nputs errors.first_value\n\nerrors.each do |key, messages|\n puts key # => \"username\"\n puts messages # => [\"The username is required.\", \"etc...\"]\nend\n```\n\n3 methods [#check](https://nicolab.github.io/crystal-validator/Check/Validation.html#instance-method-summary):\n\n```crystal\n# check(key : Symbol | String, valid : Bool)\n# Using default error message\nv.check(\n \"username\",\n is(:min?, user[\"username\"], 2)\n)\n\n# check(key : Symbol | String, message : String, valid : Bool)\n# Using custom error message\nv.check(\n \"username\",\n \"The username must contain at least 2 characters.\",\n is(:min?, user[\"username\"], 2)\n)\n\n# check(key : Symbol | String, valid : Bool, message : String)\n# Using custom error message\nv.check(\n \"username\",\n is(:min?, user[\"username\"], 2),\n \"The username must contain at least 2 characters.\"\n)\n```\n\n`Check` is a simple and lightweight wrapper.\nThe `Check::Validation` is agnostic of the checked data,\nof the context (model, controller, CSV file, HTTP data, socket data, JSON, etc).\n\n> Use case example:\n Before saving to the database or process user data for a particular task,\n the custom error messages can be used for the end user response.\n\nBut a `Validation` instance can be used just to store validation errors:\n\n```crystal\nv = Check.new_validation\nv.add_error(\"foo\", \"foo error!\")\npp v.errors # => {\"foo\" => [\"foo error!\"]}\n```\n\n> See also `Check.rules` and `Check.checkable`.\n\nLet your imagination run wild to add your logic around it.\n\n### Custom validator\n\nJust add your own method to register a custom *validator* or to overload an existing *validator*.\n\n```crystal\nmodule Validator\n # My custom validator\n def self.my_validator?(value, arg : String, another_arg : Int32) : Bool\n # write here the logic of your validator...\n return true\n end\nend\n\n# Call it\nputs Valid.my_validator?(\"value to validate\", \"hello\", 42) # => true\n\n# or with the `is` flavor\nputs is :my_validator?, \"value to validate\", \"hello\", 42 # => true\n```\n\nUsing the custom validator with the validation rules:\n\n```crystal\nrequire \"validator/check\"\n\nclass Article\n # Mixin\n Check.checkable\n\n property title : String\n property content : String\n\n Check.rules(\n content: {\n # Now the custom validator is available\n check: {\n my_validator: {\"My validator error message\"},\n between: {\"The article content must be between 10 and 20 000 characters\", 10, 20_000},\n # ...\n },\n },\n )\nend\n\n# Triggered with all data\nv, article = Article.check(input_data)\n\n# Triggered with one value\nv, content = Article.check_content(input_data[\"content\"]?)\n```\n\n## Conventions\n\n* The word \"validator\" is the method to make a \"validation\" (value validation).\n* A *validator* returns `true` if the value (or/and the condition) is valid, `false` if not.\n* The first argument(s) is (are) the value(s) to be validated.\n* Always add the `Bool` return type to a *validator*.\n* Always add the suffix `?` to the method name of a *validator*.\n* If possible, indicates the type of the *validator* arguments.\n* Spec: Battle tested.\n* [KISS](https://en.wikipedia.org/wiki/KISS_principle) and [Unix Philosophy](https://en.wikipedia.org/wiki/Unix_philosophy).\n\n## Development\n\n```sh\ncrystal spec\ncrystal tool format\n```\n\n> TODO: add `ameba`?\n\n## Contributing\n\n1. Fork it ()\n2. Create your feature branch (`git checkout -b my-new-feature`)\n3. Commit your changes (`git commit -am 'Add some feature'`)\n4. Push to the branch (`git push origin my-new-feature`)\n5. Create a new Pull Request\n\n## LICENSE\n\n[MIT](https://github.com/Nicolab/crystal-validator/blob/master/LICENSE) (c) 2020, Nicolas Talle.\n\n## Author\n\n| [![Nicolas Tallefourtane - Nicolab.net](https://www.gravatar.com/avatar/d7dd0f4769f3aa48a3ecb308f0b457fc?s=64)](https://github.com/sponsors/Nicolab) |\n|---|\n| [Nicolas Talle](https://github.com/sponsors/Nicolab) |\n| [![Make a donation via Paypal](https://www.paypalobjects.com/en_US/i/btn/btn_donate_SM.gif)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=PGRH4ZXP36GUC) |\n\n> Thanks to [ilourt](https://github.com/ilourt) for his great work on `checkable` mixins (clean_*, check_*, ...).\n","program":{"html_id":"validator/toplevel","path":"toplevel.html","kind":"module","full_name":"Top Level Namespace","name":"Top Level Namespace","abstract":false,"superclass":null,"ancestors":[],"locations":[],"repository_name":"validator","program":true,"enum":false,"alias":false,"aliased":"","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":null,"doc":null,"summary":null,"class_methods":[],"constructors":[],"instance_methods":[],"macros":[{"id":"is(name,*args)-macro","html_id":"is(name,*args)-macro","name":"is","doc":"An (optional) expressive flavor of `Validator` (or `Valid` alias).\nNot exposed by default, must be imported:\n\n```\nrequire \"validator/is\"\n\nis :email?, \"contact@example.org\" # => true\nis \"email?\", \"contact@example.org\" # => true\nis :url?, \"https://github.com/Nicolab/crystal-validator\" # => true\n```","summary":"

An (optional) expressive flavor of Validator (or Valid alias).

","abstract":false,"args":[{"name":"name","doc":null,"default_value":"","external_name":"name","restriction":""},{"name":"args","doc":null,"default_value":"","external_name":"args","restriction":""}],"args_string":"(name, *args)","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/is.cr#L18","def":{"name":"is","args":[{"name":"name","doc":null,"default_value":"","external_name":"name","restriction":""},{"name":"args","doc":null,"default_value":"","external_name":"args","restriction":""}],"double_splat":null,"splat_index":1,"block_arg":null,"visibility":"Public","body":" \n# Symbol ? String\n\n Valid.\n{{ name.id }}\n \n{{ args.splat }}\n\n\n"}},{"id":"is!(name,*args)-macro","html_id":"is!(name,*args)-macro","name":"is!","doc":"Same as `is` but `raise` a `Validator::Error`\ndisplaying an inspection if the validation is `false`.\nUseful for the unit tests :)","summary":"

Same as is but raise a Validator::Error displaying an inspection if the validation is false.

","abstract":false,"args":[{"name":"name","doc":null,"default_value":"","external_name":"name","restriction":""},{"name":"args","doc":null,"default_value":"","external_name":"args","restriction":""}],"args_string":"(name, *args)","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/is.cr#L26","def":{"name":"is!","args":[{"name":"name","doc":null,"default_value":"","external_name":"name","restriction":""},{"name":"args","doc":null,"default_value":"","external_name":"args","restriction":""}],"double_splat":null,"splat_index":1,"block_arg":null,"visibility":"Public","body":" \n# Symbol ? String\n\n valid = Valid.\n{{ name.id }}\n \n{{ args.splat }}\n\n\n if valid == false\n raise Validator::Error.new \"Is not \\\"#{\n{{ name }}\n}\\\":\\n#{\n{{ args.stringify }}\n}\"\n \nend\n\n true\n\n"}}],"types":[{"html_id":"validator/Check","path":"Check.html","kind":"module","full_name":"Check","name":"Check","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/check.cr","line_number":11,"url":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/check.cr#L11"},{"filename":"src/checkable.cr","line_number":9,"url":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/checkable.cr#L9"}],"repository_name":"validator","program":false,"enum":false,"alias":false,"aliased":"","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":null,"doc":"Standalone check module that provides a practical workflow for validations.","summary":"

Standalone check module that provides a practical workflow for validations.

","class_methods":[{"id":"new_validation(errors:Errors)-class-method","html_id":"new_validation(errors:Errors)-class-method","name":"new_validation","doc":"Initializes a new `Validation` instance to combine\na series of checks (`Validation#check`).\nusing an existing *errors* `Hash` (`Check::Errors`).\n\n```\nv = Check.new_validation existing_errors\n```\n\nSame as:\n\n```\nv = Check::Validation.new existing_errors\n```\n\nExample to combine two hashes of validation errors:\n\n```\npreview_validation = Check.new_validation\nv = Check.new_validation preview_validation.errors\n```","summary":"

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)","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/check.cr#L359","def":{"name":"new_validation","args":[{"name":"errors","doc":null,"default_value":"","external_name":"errors","restriction":"Errors"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"Validation.new(errors)"}},{"id":"new_validation-class-method","html_id":"new_validation-class-method","name":"new_validation","doc":"Initializes a new `Validation` instance to combine\na series of checks (`Validation#check`).\n\n```\nv = Check.new_validation\n```\n\nSame as:\n\n```\nv = Check::Validation.new\n```","summary":"

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

","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/check.cr#L335","def":{"name":"new_validation","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"Validation.new"}}],"constructors":[],"instance_methods":[],"macros":[{"id":"checkable-macro","html_id":"checkable-macro","name":"checkable","doc":"A mixin to make a class checkable.\nThis mixin includes `Checkable` and `CheckableStatic`.\nIt must be used in conjonction with `Check.rules`.\n\n```\nrequire \"validator/check\"\n\nclass Article\n # Mixin\n Check.checkable\n\n property title : String\n property content : String\n\n Check.rules(\n content: {\n check: {\n not_empty: {\"Article content is required\"},\n between: {\"The article content must be between 10 and 20 000 characters\", 10, 20_000},\n # ...\n },\n clean: {\n type: String,\n to: :to_s,\n format: ->(content : String) { content.strip },\n message: \"Wrong type\",\n },\n },\n )\nend\n\n# Triggered on all data\nv, article = Article.check(input_data)\n\n# Triggered on a value\nv, content = Article.check_content(input_data[\"content\"]?)\n```","summary":"

A mixin to make a class checkable.

","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/checkable.cr#L67","def":{"name":"checkable","args":[],"double_splat":null,"splat_index":null,"block_arg":null,"visibility":"Public","body":" include Check::Checkable\n \nextend Check::CheckableStatic\n \n"}},{"id":"rules(**fields)-macro","html_id":"rules(**fields)-macro","name":"rules","doc":"Generates `check`, `check_{{field}}` and `clean_{{field}}` methods for *fields* (class variables).\n\n```\nrequire \"validator/check\"\n\nclass Article\n # Mixin\n Check.checkable\n\n property title : String\n property content : String\n property url : String?\n\n Check.rules(\n content: {\n required: true,\n check: {\n not_empty: {\"Article content is required\"},\n between: {\"The article content must be between 10 and 20 000 characters\", 10, 20_000},\n # ...\n },\n clean: {\n type: String,\n to: :to_s,\n format: ->(content : String) { content.strip },\n message: \"Wrong type\",\n },\n },\n url: {\n check: {\n url: {\"Article URL is invalid\"},\n },\n clean: {\n # `nilable` means omited if not provided,\n # regardless of Crystal type (nilable or not)\n nilable: true,\n # Crystal type\n type: String,\n # Converter to the expected typed value\n to: :to_s,\n },\n },\n # ...\n)\nend\n\n# Triggered on all data\nv, article = Article.check(input_data)\n\n# Triggered on all fields of an instance\narticle = Article.new(title: \"foo\", content: \"bar\")\nv = article.check\n\n# Triggered on a value\nv, content = Article.check_content(input_data[\"content\"]?)\n\n# Cast and clean a value\nok, content = Article.clean_content(input_data[\"content\"]?)\n```\n\nSee also `Check.checkable`.","summary":"

Generates check, check_{{field}} and clean_{{field}} methods for fields (class variables).

","abstract":false,"args":[],"args_string":"(**fields)","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/checkable.cr#L133","def":{"name":"rules","args":[],"double_splat":{"name":"fields","doc":null,"default_value":"","external_name":"fields","restriction":""},"splat_index":null,"block_arg":null,"visibility":"Public","body":" private def self.validation_rules\n \n{{ fields }}\n\n \nend\n\n private def self.validation_required?(field) : Bool\n fields = self.validation_rules\n return false if fields[field].nil?\n fields[field].fetch(\"required\", false).as(Bool)\n \nend\n\n private def self.validation_nilable?(field) : Bool\n fields = self.validation_rules\n return false if fields[field].nil? || fields[field][\"clean\"].nil?\n fields[field][\"clean\"].fetch(\"nilable\", false).as(Bool)\n \nend\n\n \n{% for field, rules in fields %}\n {% clean = rules[\"clean\"] %}\n {% check = rules[\"check\"] %}\n {% type = clean[\"type\"] %}\n {% nilable = clean[\"nilable\"] %}\n\n # Returns *{{ field }}* with the good type and formatted if *format* is `true`.\n # The return type is a tuple with a bool as a first argument indicating\n # that the clean has been processed successfully or not and the 2nd\n # argument is the *value* cleaned.\n #\n # ```\n # ok, email = Checkable.clean_email(user_input[\"email\"]) # => true, user@example.com\n # ```\n def self.clean_{{ field }}(value, format = true) : Tuple(Bool, {{ type }} | Nil)\n # force real Nil type (hack for JSON::Any and equivalent)\n value = nil if value == nil\n\n {% if to = clean[\"to\"] %}\n # Check if the *value* has the method `{{ to }}` and execute it if\n # exists to cast the value in the good type (except if the value is nil and nilable).\n if value.responds_to? {{ to }} {% if nilable %} && !value.nil?{% end %}\n begin\n value = value.{{ to.id }}\n rescue\n return false, nil\n end\n end\n {% end %}\n\n # Format if the value as the correct (Crystal) type.\n # `| Nil` allows to format in the case of a nilable value (example `String?`)\n # where the `type` option of `clean` rules has been defined on the precise\n # Crystal type (example `String`).\n if value.is_a? {{ type }} | Nil\n {% if format = clean[\"format\"] %}\n # If *format* is true then call it to format *value*.\n if format\n begin\n return true, {{ format }}.call(value)\n rescue\n return false, nil\n end\n else\n return true, value\n end\n {% else %}\n return true, value\n {% end %}\n end\n\n {false, nil}\n end\n\n # Create a new `Check::Validation` and checks *{{ field }}*.\n # For more infos check `.check_{{ field }}(v : Check::Validation, value, format : Bool = true)`\n def self.check_{{ field }}(\n *,\n value,\n required : Bool = true,\n format : Bool = true\n ) : Tuple(Check::Validation, {{ type }} | Nil)\n v = Check.new_validation\n self.check_{{ field }}(v, value, required, format)\n end\n\n # Cleans and check *value*.\n # If *format* is `true` it tells `.clean_{{ field }}` to execute the `format` function\n # for this field if it has been defined with `Check.rules`.\n def self.check_{{ field }}(\n v : Check::Validation,\n value,\n required : Bool = true,\n format : Bool = true\n ) : Tuple(Check::Validation, {{ type }} | Nil)\n # Cleans and formats the *value*\n ok, value = self.clean_{{ field }}(value, format)\n\n # If clean has encountered an error, add error message and stop check here.\n if ok == false\n {% msg = clean[\"message\"] || \"Wrong type\" %}\n v.add_error {{ field.stringify }}, {{ msg }} {% if nilable || (check[\"not_null\"].nil? && check[\"not_empty\"].nil?) %}unless value.nil?{% end %}\n return v, value\n end\n\n # Check against each rule provided.\n # Each rule is executed if *value* is not `nil` except for `not_null` and `not_empty`\n # which is executed even if the *value* is `nil`\n {% for name, args in check %}\n v.check(\n {{ field.stringify }},\n {{ args[0] }},\n {% if args.size <= 1 %}\n Valid.{{ name.id }}? value\n {% else %}\n Valid.{{ name.id }}? value, {{ args[1..-1].splat }}\n {% end %}\n ) {% if (nilable || (check[\"not_null\"].nil? && check[\"not_empty\"].nil?)) || ((name != \"not_null\") && (name != \"not_empty\")) %}unless value.nil?{% end %}\n {% end %}\n\n {v, value}\n end\n {% end %}\n\n \n"}}],"types":[{"html_id":"validator/Check/Checkable","path":"Check/Checkable.html","kind":"module","full_name":"Check::Checkable","name":"Checkable","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/checkable.cr","line_number":411,"url":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/checkable.cr#L411"}],"repository_name":"validator","program":false,"enum":false,"alias":false,"aliased":"","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"validator/Check","kind":"module","full_name":"Check","name":"Check"},"doc":"Mixin that adds `#check` method to be used with variables of an instance of the class including it.\nThe idea is to check the instance variables of the class extending it\nagainst rules defined with `Check.rules` plus executing custom checkers defined with `Checker`.","summary":"

Mixin that adds #check method to be used with variables of an instance of the class including it.

","class_methods":[],"constructors":[],"instance_methods":[{"id":"after_check(v:Check::Validation,required:Bool=true,format:Bool=true)-instance-method","html_id":"after_check(v:Check::Validation,required:Bool=true,format:Bool=true)-instance-method","name":"after_check","doc":"Lifecycle method triggered after each call of `#check`.\n\n```\n# Triggered on instance: `user.check`\ndef after_check(v : Check::Validation, required : Bool = true, format : Bool = true)\n # Code...\nend\n```","summary":"

Lifecycle method triggered after each call of #check.

","abstract":false,"args":[{"name":"v","doc":null,"default_value":"","external_name":"v","restriction":"Check::Validation"},{"name":"required","doc":null,"default_value":"true","external_name":"required","restriction":"Bool"},{"name":"format","doc":null,"default_value":"true","external_name":"format","restriction":"Bool"}],"args_string":"(v : Check::Validation, required : Bool = true, format : Bool = true)","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/checkable.cr#L434","def":{"name":"after_check","args":[{"name":"v","doc":null,"default_value":"","external_name":"v","restriction":"Check::Validation"},{"name":"required","doc":null,"default_value":"true","external_name":"required","restriction":"Bool"},{"name":"format","doc":null,"default_value":"true","external_name":"format","restriction":"Bool"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":""}},{"id":"before_check(v:Check::Validation,required:Bool=true,format:Bool=true)-instance-method","html_id":"before_check(v:Check::Validation,required:Bool=true,format:Bool=true)-instance-method","name":"before_check","doc":"Lifecycle method triggered before each call of `#check`.\n\n```\n# Triggered on instance: `user.check`\ndef before_check(v : Check::Validation, required : Bool = true, format : Bool = true)\n # Code...\nend\n```","summary":"

Lifecycle method triggered before each call of #check.

","abstract":false,"args":[{"name":"v","doc":null,"default_value":"","external_name":"v","restriction":"Check::Validation"},{"name":"required","doc":null,"default_value":"true","external_name":"required","restriction":"Bool"},{"name":"format","doc":null,"default_value":"true","external_name":"format","restriction":"Bool"}],"args_string":"(v : Check::Validation, required : Bool = true, format : Bool = true)","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/checkable.cr#L420","def":{"name":"before_check","args":[{"name":"v","doc":null,"default_value":"","external_name":"v","restriction":"Check::Validation"},{"name":"required","doc":null,"default_value":"true","external_name":"required","restriction":"Bool"},{"name":"format","doc":null,"default_value":"true","external_name":"format","restriction":"Bool"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":""}},{"id":"check(required:Bool=true,format:Bool=true):Validation-instance-method","html_id":"check(required:Bool=true,format:Bool=true):Validation-instance-method","name":"check","doc":"Checks the instance fields and clean them.\n\nIt instantiates a `Check::Validation` (if not provided) and calls all methods\nrelated to rules and then methods defined with annotation `Checker`.\n\nLifecycle methods `#before_check` and `#after_check` that are triggered\nrespectively at the beginning and at the end of the process.\n\n*format* is used to tell cleaners generated by `Check.rules`\nto execute format method if it has been defined.","summary":"

Checks the instance fields and clean them.

","abstract":false,"args":[{"name":"required","doc":null,"default_value":"true","external_name":"required","restriction":"Bool"},{"name":"format","doc":null,"default_value":"true","external_name":"format","restriction":"Bool"}],"args_string":"(required : Bool = true, format : Bool = true) : Validation","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/checkable.cr#L480","def":{"name":"check","args":[{"name":"required","doc":null,"default_value":"true","external_name":"required","restriction":"Bool"},{"name":"format","doc":null,"default_value":"true","external_name":"format","restriction":"Bool"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Validation","visibility":"Public","body":"v = Check.new_validation\ncheck(v, required, format)\n"}},{"id":"check(v:Check::Validation,required:Bool=true,format:Bool=true):Validation-instance-method","html_id":"check(v:Check::Validation,required:Bool=true,format:Bool=true):Validation-instance-method","name":"check","doc":"Checks the instance fields and clean them.\n\nIt instantiates a `Check::Validation` (if not provided) and calls all methods\nrelated to rules and then methods defined with annotation `Checker`.\n\nLifecycle methods `#before_check` and `#after_check` that are triggered\nrespectively at the beginning and at the end of the process.\n\n*format* is used to tell cleaners generated by `Check.rules`\nto execute format method if it has been defined.","summary":"

Checks the instance fields and clean them.

","abstract":false,"args":[{"name":"v","doc":null,"default_value":"","external_name":"v","restriction":"Check::Validation"},{"name":"required","doc":null,"default_value":"true","external_name":"required","restriction":"Bool"},{"name":"format","doc":null,"default_value":"true","external_name":"format","restriction":"Bool"}],"args_string":"(v : Check::Validation, required : Bool = true, format : Bool = true) : Validation","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/checkable.cr#L450","def":{"name":"check","args":[{"name":"v","doc":null,"default_value":"","external_name":"v","restriction":"Check::Validation"},{"name":"required","doc":null,"default_value":"true","external_name":"required","restriction":"Bool"},{"name":"format","doc":null,"default_value":"true","external_name":"format","restriction":"Bool"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Validation","visibility":"Public","body":"{% if true %}\n\n # Call lifecycle method before check\n before_check v, required, format\n\n # Check all fields that have a method `#check_{field}`\n {% for ivar in @type.instance_vars.select do |ivar|\n @type.class.has_method?(\"check_#{ivar}\")\nend %}\n v, value = self.class.check_{{ ivar.name }}(v, {{ ivar.name }}, required, format)\n\n # If the field is not nilable and the value is nil,\n # it means that the clean method has failed\n # (to cast or an exception has been raised (and catched) in the formatter)\n # So ignore the nil value if the field is not nilable\n @{{ ivar.name }} = value.as({{ ivar.type }}) {% if !ivar.type.nilable? %} unless value.nil? {% end %}\n {% end %}\n\n # Check methods with `Check::Checker` annotation\n {% for method in @type.methods.select do |method|\n method.annotation(Checker)\nend %}\n {{ method.name }} v, required, format\n {% end %}\n\n # Call lifecycle method `#after_check`\n after_check v, required, format\n\n v\n {% end %}"}}],"macros":[],"types":[]},{"html_id":"validator/Check/CheckableStatic","path":"Check/CheckableStatic.html","kind":"module","full_name":"Check::CheckableStatic","name":"CheckableStatic","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/checkable.cr","line_number":261,"url":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/checkable.cr#L261"}],"repository_name":"validator","program":false,"enum":false,"alias":false,"aliased":"","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"validator/Check","kind":"module","full_name":"Check","name":"Check"},"doc":"Mixin that adds `.check` method to be used with a `Hash`.\nThe idea is to check a `Hash` against rules defined with `Check.rules`\nplus executing custom checkers defined with `Checker` annotation.","summary":"

Mixin that adds .check method to be used with a Hash.

","class_methods":[],"constructors":[],"instance_methods":[{"id":"after_check(v:Check::Validation,h:Hash,cleaned_h:Hash,required:Bool=true,format:Bool=true):Hash-instance-method","html_id":"after_check(v:Check::Validation,h:Hash,cleaned_h:Hash,required:Bool=true,format:Bool=true):Hash-instance-method","name":"after_check","doc":"Lifecycle method triggered after each call of `.check`.\n\nThis method (in static call) must returns the cleaned `Hash`\nwhich is provided in the third argument.\nYou can update this cleaned hash but you have to return it.\n\n```\n# Triggered on a static call: `User.check(h)` (with a `Hash` or `JSON::Any`)\ndef self.after_check(v : Check::Validation, h, cleaned_h, required : Bool = true, format : Bool = true) : Hash\n # Code...\n pp cleaned_h\n cleaned_h # <= returns cleaned_h!\nend\n```","summary":"

Lifecycle method triggered after each call of .check.

","abstract":false,"args":[{"name":"v","doc":null,"default_value":"","external_name":"v","restriction":"Check::Validation"},{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"Hash"},{"name":"cleaned_h","doc":null,"default_value":"","external_name":"cleaned_h","restriction":"Hash"},{"name":"required","doc":null,"default_value":"true","external_name":"required","restriction":"Bool"},{"name":"format","doc":null,"default_value":"true","external_name":"format","restriction":"Bool"}],"args_string":"(v : Check::Validation, h : Hash, cleaned_h : Hash, required : Bool = true, format : Bool = true) : Hash","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/checkable.cr#L341","def":{"name":"after_check","args":[{"name":"v","doc":null,"default_value":"","external_name":"v","restriction":"Check::Validation"},{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"Hash"},{"name":"cleaned_h","doc":null,"default_value":"","external_name":"cleaned_h","restriction":"Hash"},{"name":"required","doc":null,"default_value":"true","external_name":"required","restriction":"Bool"},{"name":"format","doc":null,"default_value":"true","external_name":"format","restriction":"Bool"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Hash","visibility":"Public","body":"cleaned_h"}},{"id":"before_check(v:Check::Validation,h:Hash,required:Bool=true,format:Bool=true)-instance-method","html_id":"before_check(v:Check::Validation,h:Hash,required:Bool=true,format:Bool=true)-instance-method","name":"before_check","doc":"Lifecycle method triggered before each call of `.check`.\n\n```\n# Triggered on a static call: `User.check(h)` (with a `Hash` or `JSON::Any`)\ndef self.before_check(v : Check::Validation, h, required : Bool = true, format : Bool = true)\n # Code...\n pp h\nend\n```","summary":"

Lifecycle method triggered before each call of .check.

","abstract":false,"args":[{"name":"v","doc":null,"default_value":"","external_name":"v","restriction":"Check::Validation"},{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"Hash"},{"name":"required","doc":null,"default_value":"true","external_name":"required","restriction":"Bool"},{"name":"format","doc":null,"default_value":"true","external_name":"format","restriction":"Bool"}],"args_string":"(v : Check::Validation, h : Hash, required : Bool = true, format : Bool = true)","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/checkable.cr#L320","def":{"name":"before_check","args":[{"name":"v","doc":null,"default_value":"","external_name":"v","restriction":"Check::Validation"},{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"Hash"},{"name":"required","doc":null,"default_value":"true","external_name":"required","restriction":"Bool"},{"name":"format","doc":null,"default_value":"true","external_name":"format","restriction":"Bool"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":""}},{"id":"check(v:Check::Validation,h:Hash,required:Bool=true,format:Bool=true)-instance-method","html_id":"check(v:Check::Validation,h:Hash,required:Bool=true,format:Bool=true)-instance-method","name":"check","doc":"Checks and clean the `Hash` for its fields corresponding\nto class variables that have a `.check_{{field}}` method.\n\nIt instantiates a `Check::Validation` (if not provided) and calls all methods\nrelated to `.rules` and then methods defined with annotation `Checker`.\n\nLifecycle methods `.before_check` and `.after_check` that are called\nrespectively at the beginning and at the end of the process.\n\n*format* is used to tell cleaners generated by `Check.rules`\nto execute format method if it has been defined.","summary":"

Checks and clean the Hash for its fields corresponding to class variables that have a .check_{{field}} method.

","abstract":false,"args":[{"name":"v","doc":null,"default_value":"","external_name":"v","restriction":"Check::Validation"},{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"Hash"},{"name":"required","doc":null,"default_value":"true","external_name":"required","restriction":"Bool"},{"name":"format","doc":null,"default_value":"true","external_name":"format","restriction":"Bool"}],"args_string":"(v : Check::Validation, h : Hash, required : Bool = true, format : Bool = true)","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/checkable.cr#L361","def":{"name":"check","args":[{"name":"v","doc":null,"default_value":"","external_name":"v","restriction":"Check::Validation"},{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"Hash"},{"name":"required","doc":null,"default_value":"true","external_name":"required","restriction":"Bool"},{"name":"format","doc":null,"default_value":"true","external_name":"format","restriction":"Bool"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"{% if true %}\n {% types = [] of Type %}\n {% fields = [] of String %}\n\n {% for ivar in @type.instance_vars.select do |ivar|\n @type.class.has_method?(\"check_#{ivar}\")\nend %}\n {% types << ivar.type %}\n {% fields << ivar.name %}\n {% end %}\n\n # Instantiate a `Hash` with keys as `String` and values as a union of\n # all types of fields which have a method `.check_{field}`\n cleaned_h = Hash(String, {{ (types.join(\"|\")).id }}).new\n\n # Call lifecycle method before check\n self.before_check v, h, required, format\n\n # Call check methods for fields that are present in *h*\n # and populate `cleaned_h`\n {% for field, i in fields %}\n {% field_name = field.stringify %}\n # if hash has the field or this field MUST be checked when required is `true`\n if h.has_key?({{ field_name }}) || (required && self.validation_required?({{ field_name }}))\n v, value = self.check_{{ field }}(v, h[{{ field_name }}]?, required, format)\n cleaned_h[{{ field_name }}] = value.as({{ types[i] }})\n end\n {% end %}\n\n # Check methods with `Check::Checker` annotation\n {% for method in @type.class.methods.select do |method|\n method.annotation(Checker)\nend %}\n cleaned_h = {{ method.name }} v, h, cleaned_h, required, format\n {% end %}\n\n # Call lifecycle method `.after_check`\n cleaned_h = self.after_check v, h, cleaned_h, required, format\n\n {v, cleaned_h}\n {% end %}"}},{"id":"check(h:Hash,required:Bool=true,format:Bool=true)-instance-method","html_id":"check(h:Hash,required:Bool=true,format:Bool=true)-instance-method","name":"check","doc":"Checks and clean the `Hash` for its fields corresponding\nto class variables that have a `.check_{{field}}` method.\n\nIt instantiates a `Check::Validation` (if not provided) and calls all methods\nrelated to `.rules` and then methods defined with annotation `Checker`.\n\nLifecycle methods `.before_check` and `.after_check` that are called\nrespectively at the beginning and at the end of the process.\n\n*format* is used to tell cleaners generated by `Check.rules`\nto execute format method if it has been defined.","summary":"

Checks and clean the Hash for its fields corresponding to class variables that have a .check_{{field}} method.

","abstract":false,"args":[{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"Hash"},{"name":"required","doc":null,"default_value":"true","external_name":"required","restriction":"Bool"},{"name":"format","doc":null,"default_value":"true","external_name":"format","restriction":"Bool"}],"args_string":"(h : Hash, required : Bool = true, format : Bool = true)","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/checkable.cr#L402","def":{"name":"check","args":[{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"Hash"},{"name":"required","doc":null,"default_value":"true","external_name":"required","restriction":"Bool"},{"name":"format","doc":null,"default_value":"true","external_name":"format","restriction":"Bool"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"v = Check.new_validation\ncheck(v, h, required, format)\n"}},{"id":"h_from_json(json:String|IO)-instance-method","html_id":"h_from_json(json:String|IO)-instance-method","name":"h_from_json","doc":"Returns a `Hash` from a JSON input.\nThe return type is a tuple with a bool as a first argument indicating\nthat the `JSON.parse` has been processed successfully or not and the 2nd\nargument is the *json* Hash.\n\n```\nok, user_h = User.h_from_json(json) # => true, {\"username\" => \"Bob\", \"email\" => \"user@example.com\"}\n```","summary":"

Returns a Hash from a JSON input.

","abstract":false,"args":[{"name":"json","doc":null,"default_value":"","external_name":"json","restriction":"String | IO"}],"args_string":"(json : String | IO)","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/checkable.cr#L305","def":{"name":"h_from_json","args":[{"name":"json","doc":null,"default_value":"","external_name":"json","restriction":"String | IO"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"begin\n return {true, self.to_crystal_h((JSON.parse(json)).as_h)}\nrescue\n return {false, nil}\nend"}},{"id":"map_json_keys:Hash(String,String)-instance-method","html_id":"map_json_keys:Hash(String,String)-instance-method","name":"map_json_keys","doc":"Macro that returns the mapping of the JSON fields","summary":"

Macro that returns the mapping of the JSON fields

","abstract":false,"args":[],"args_string":" : Hash(String, String)","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/checkable.cr#L263","def":{"name":"map_json_keys","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Hash(String, String)","visibility":"Public","body":"map = {} of String => String\n{% if true %}\n {% for ivar in @type.instance_vars %}\n {% ann = ivar.annotation(::JSON::Field) %}\n {% if ann && ann[:ignore] %}{% else %}\n map[{{ ((ann && ann[:key]) || ivar).id.stringify }}] = {{ ivar.id.stringify }}\n {% end %}\n {% end %}\n {% end %}\nmap\n"}},{"id":"to_crystal_h(h:Hash):Hash-instance-method","html_id":"to_crystal_h(h:Hash):Hash-instance-method","name":"to_crystal_h","doc":"Returns a new `Hash` with all JSON keys converted to Crystal keys.","summary":"

Returns a new Hash with all JSON keys converted to Crystal keys.

","abstract":false,"args":[{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"Hash"}],"args_string":"(h : Hash) : Hash","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/checkable.cr#L278","def":{"name":"to_crystal_h","args":[{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"Hash"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Hash","visibility":"Public","body":"cr_keys = map_json_keys\nh.transform_keys do |cr_k|\n cr_keys[cr_k]? || cr_k\nend\n"}},{"id":"to_json_h(h:Hash):Hash-instance-method","html_id":"to_json_h(h:Hash):Hash-instance-method","name":"to_json_h","doc":"Returns a new `Hash` with all Crystal keys converted to JSON keys.","summary":"

Returns a new Hash with all Crystal keys converted to JSON keys.

","abstract":false,"args":[{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"Hash"}],"args_string":"(h : Hash) : Hash","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/checkable.cr#L288","def":{"name":"to_json_h","args":[{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"Hash"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Hash","visibility":"Public","body":"cr_keys = map_json_keys\nh.transform_keys do |json_k|\n cr_keys.key_for?(json_k || json_k)\nend\n"}}],"macros":[],"types":[]},{"html_id":"validator/Check/Checker","path":"Check/Checker.html","kind":"annotation","full_name":"Check::Checker","name":"Checker","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/checkable.cr","line_number":28,"url":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/checkable.cr#L28"}],"repository_name":"validator","program":false,"enum":false,"alias":false,"aliased":"","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"validator/Check","kind":"module","full_name":"Check","name":"Check"},"doc":"Declare a method as a checker.\n\n```\n# Triggered by the instance.\n@[Check::Checker]\ndef custom_checker(v : Check::Validation, required : Bool, format : Bool)\n puts \"custom checker triggered on instance\"\nend\n\n# Triggered statically.\n@[Check::Checker]\ndef self.custom_checker(v : Check::Validation, h, cleaned_h, required : Bool, format : Bool)\n puts \"custom checker triggered statically\"\n cleaned_h\nend\n```\n\nWhen `.check` and `#check` are called, the custom checkers are triggered respectively.","summary":"

Declare a method as a checker.

","class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[]},{"html_id":"validator/Check/Errors","path":"Check/Errors.html","kind":"alias","full_name":"Check::Errors","name":"Errors","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/check.cr","line_number":19,"url":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/check.cr#L19"}],"repository_name":"validator","program":false,"enum":false,"alias":true,"aliased":"Hash(String | Symbol, Array(String))","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"validator/Check","kind":"module","full_name":"Check","name":"Check"},"doc":"Validation errors.\nIt's a `Hash` used as a container of errors, in order to handle them easily.\n\n```\nv = Check.new_validation\npp v.errors\n```","summary":"

Validation errors.

","class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[]},{"html_id":"validator/Check/Validation","path":"Check/Validation.html","kind":"class","full_name":"Check::Validation","name":"Validation","abstract":false,"superclass":{"html_id":"validator/Reference","kind":"class","full_name":"Reference","name":"Reference"},"ancestors":[{"html_id":"validator/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"validator/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"src/check.cr","line_number":139,"url":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/check.cr#L139"}],"repository_name":"validator","program":false,"enum":false,"alias":false,"aliased":"","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"validator/Check","kind":"module","full_name":"Check","name":"Check"},"doc":"Combines a series of checks into one validation instance,\nwith a customized error message for each case.\n\nA `Validation` instance provides the means to write sequential checks,\nfine-tune each micro-validation with their own rules and custom error message,\nthe possibility to retrieve all error messages, etc.\n\n> `Validation` is also used with `Check.rules` and `Check.checkable`\nthat provide a powerful and productive system of validation rules\nwhich makes data cleaning and data validation in Crystal very easy.\nWith self-generated granular methods for cleaning and checking data.\n\n\nTo use the checker (`check`) includes in the `Validation` class:\n\n```\nrequire \"validator/check\"\n\n# Validates the *user* data received in the HTTP controller or other.\ndef validate_user(user : Hash) : Check::Validation\n v = Check.new_validation\n\n # -- email\n\n # Hash key can be a String or a Symbol\n v.check :email, \"The email is required.\", is :presence?, :email, user\n\n v.check \"email\", \"The email is required.\", is :presence?, \"email\", user\n v.check \"email\", \"#{user[\"email\"]} is an invalid email.\", is :email?, user[\"email\"]\n\n # -- username\n\n v.check \"username\", \"The username is required.\", is :presence?, \"username\", user\n\n v.check(\n \"username\",\n \"The username must contain at least 2 characters.\",\n is :min?, user[\"username\"], 2\n )\n\n v.check(\n \"username\",\n \"The username must contain a maximum of 20 characters.\",\n is :max?, user[\"username\"], 20\n )\nend\n\nv = validate_user user\n\npp v.valid? # => true (or false)\n\n# Inverse of v.valid?\nif v.errors.empty?\n return \"no error\"\nend\n\n# display all the errors (if any)\npp v.errors\n\n# It's a Hash of Array\nerrors = v.errors\n\nputs errors.size\nputs errors.first_value\n\nerrors.each do |key, messages|\n puts key # => \"username\"\n puts messages # => [\"The username is required.\", \"etc...\"]\nend\n```\n\n3 methods [#check](https://nicolab.github.io/crystal-validator/Check/Validation.html#instance-method-summary):\n\n```\n# check(key : Symbol | String, valid : Bool)\n# Using default standard error message\nv.check(\n \"username\",\n is(:min?, user[\"username\"], 2)\n)\n\n# check(key : Symbol | String, message : String, valid : Bool)\n# Using custom error message\nv.check(\n \"username\",\n \"The username must contain at least 2 characters.\",\n is(:min?, user[\"username\"], 2)\n)\n\n# check(key : Symbol | String, valid : Bool, message : String)\n# Using custom error message\nv.check(\n \"username\",\n is(:min?, user[\"username\"], 2),\n \"The username must contain at least 2 characters.\"\n)\n```\n\n`Check` is a simple and lightweight wrapper.\n`Check::Validation` is agnostic of the checked data,\nof the context (model, controller, CSV file, HTTP data, socket data, JSON, etc).\n\n> Use case example:\n Before saving to the database or process user data for a particular task,\n the custom error messages can be used for the end user response.\n\nBut a `Validation` instance can be used just to store validation errors:\n\n```\nv = Check.new_validation\nv.add_error(\"foo\", \"foo error!\")\npp v.errors # => {\"foo\" => [\"foo error!\"]}\n```\n\n> See also `Check.rules` and `Check.checkable`.\n\nLet your imagination run wild to add your logic around it.\n","summary":"

Combines a series of checks into one validation instance, with a customized error message for each case.

","class_methods":[],"constructors":[{"id":"new(errors:Errors)-class-method","html_id":"new(errors:Errors)-class-method","name":"new","doc":"Initializes a validation using an existing *errors* `Hash` (`Check::Errors`).\n\n```\nv = Check::Validation.new\n```\n\nSame as:\n\n```\nv = Check.new_validation\n```","summary":"

Initializes a validation using an existing errors Hash (Check::Errors).

","abstract":false,"args":[{"name":"errors","doc":null,"default_value":"","external_name":"errors","restriction":"Errors"}],"args_string":"(errors : Errors)","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/check.cr#L168","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":"","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/check.cr#L153","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","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/check.cr#L191","def":{"name":"add_error","args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"Symbol | String"},{"name":"message","doc":null,"default_value":"","external_name":"message","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Validation","visibility":"Public","body":"if message.blank?\n message = \"\\\"#{key}\\\" is not valid.\"\nend\nif @errors.has_key?(key)\nelse\n @errors[key] = Array(String).new\nend\n@errors[key] << message\nself\n"}},{"id":"add_error(key:Symbol|String):Validation-instance-method","html_id":"add_error(key:Symbol|String):Validation-instance-method","name":"add_error","doc":"Add a validation error.\n\n> By default a standard message is used.\n\n```\nv = Check.new_validation\nv.add_error(:foo)\npp v.errors # => {:foo => [\"\\\"foo\\\" is not valid.\"]}\n```\n\nSee also: `Errors`","summary":"

Add a validation error.

","abstract":false,"args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"Symbol | String"}],"args_string":"(key : Symbol | String) : Validation","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/check.cr#L211","def":{"name":"add_error","args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"Symbol | String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Validation","visibility":"Public","body":"add_error(key, \"\")\nself\n"}},{"id":"check(key:Symbol|String,message:String,valid:Bool):Validation-instance-method","html_id":"check(key:Symbol|String,message:String,valid:Bool):Validation-instance-method","name":"check","doc":"Checks a validation, often used in sequence.\n\nIf *valid* is `false`, the error *message* is added in the `errors`.\nNothing if *valid* is `true`.\n\n```\nv = Check.new_validation\n\n# -- email\n\nv.check :email, \"The email is required.\", is :presence?, :email, user\nv.check :email, \"#{user[:email]} is an invalid email.\", is :email?, user[:email]?\n\n# -- username\n\nv.check :username, \"The username is required.\", is :presence?, :username, user\n\nv.check(\n :username,\n \"The username must contain at least 2 characters.\",\n is :min?, user[:username]?, 2\n)\n\nv.check(\n :username,\n \"The username must contain a maximum of 20 characters.\",\n is :max?, user[:username]?, 20\n)\n\n# Print all errors\npp v.errors\n```","summary":"

Checks a validation, often used in sequence.

","abstract":false,"args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"Symbol | String"},{"name":"message","doc":null,"default_value":"","external_name":"message","restriction":"String"},{"name":"valid","doc":null,"default_value":"","external_name":"valid","restriction":"Bool"}],"args_string":"(key : Symbol | String, message : String, valid : Bool) : Validation","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/check.cr#L259","def":{"name":"check","args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"Symbol | String"},{"name":"message","doc":null,"default_value":"","external_name":"message","restriction":"String"},{"name":"valid","doc":null,"default_value":"","external_name":"valid","restriction":"Bool"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Validation","visibility":"Public","body":"if valid\nelse\n add_error(key, message)\nend\nself\n"}},{"id":"check(key:Symbol|String,valid:Bool,message:String):Validation-instance-method","html_id":"check(key:Symbol|String,valid:Bool,message:String):Validation-instance-method","name":"check","doc":"Checks a validation, often used in sequence.\n\nIf *valid* is `false`, the error *message* is added in the `errors`.\nNothing if *valid* is `true`.\n\n```\nv = Check.new_validation\n\n# -- email\n\nv.check(:email, is(:presence?, :email, user), \"The email is required.\")\nv.check(:email, is(:email?, user[:email]?), \"#{user[:email]} is an invalid email.\")\n\n# -- username\n\nv.check(:username, is(:presence?, :username, user), \"The username is required.\")\n\nv.check(\n :username,\n is :min?, user[:username]?, 2,\n \"The username must contain at least 2 characters.\"\n)\n\nv.check(\n :username,\n is :max?, user[:username]?, 20,\n \"The username must contain a maximum of 20 characters.\"\n)\n\n# Print all errors\npp v.errors\n```","summary":"

Checks a validation, often used in sequence.

","abstract":false,"args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"Symbol | String"},{"name":"valid","doc":null,"default_value":"","external_name":"valid","restriction":"Bool"},{"name":"message","doc":null,"default_value":"","external_name":"message","restriction":"String"}],"args_string":"(key : Symbol | String, valid : Bool, message : String) : Validation","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/check.cr#L296","def":{"name":"check","args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"Symbol | String"},{"name":"valid","doc":null,"default_value":"","external_name":"valid","restriction":"Bool"},{"name":"message","doc":null,"default_value":"","external_name":"message","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Validation","visibility":"Public","body":"if valid\nelse\n add_error(key, message)\nend\nself\n"}},{"id":"check(key:Symbol|String,valid:Bool):Validation-instance-method","html_id":"check(key:Symbol|String,valid:Bool):Validation-instance-method","name":"check","doc":"Checks a validation, often used in sequence.\n\nIf *valid* is `false`, an error message is added in the `errors`.\nNothing if *valid* is `true`.\n\n> Unlike other `check` methods, with this one a default standard message is used.\n\n```\nv = Check.new_validation\n\nv.check(\"email\", Valid.presence?(\"email\", user))\nv.check(\"email\", Valid.email?(user[\"email\"]?))\n\n# Print all errors\npp v.errors\n```","summary":"

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","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/check.cr#L317","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","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/check.cr#L178","def":{"name":"errors","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Errors","visibility":"Public","body":"@errors"}},{"id":"valid?-instance-method","html_id":"valid?-instance-method","name":"valid?","doc":"Returns `true` if there is no error, `false` if there is one or more errors.\n\n```\npp v.errors if !v.valid?\n# or with another flavor ;-)\npp v.errors unless v.valid?\n```","summary":"

Returns true if there is no error, false if there is one or more errors.

","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/check.cr#L223","def":{"name":"valid?","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@errors.empty?"}}],"macros":[],"types":[]}]},{"html_id":"validator/Valid","path":"Valid.html","kind":"alias","full_name":"Valid","name":"Valid","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/validator.cr","line_number":124,"url":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validator.cr#L124"}],"repository_name":"validator","program":false,"enum":false,"alias":true,"aliased":"Validator","const":false,"constants":[{"id":"VERSION","name":"VERSION","value":"{{ (`shards version \\\"/media/data/lab/dev/work/projects/nicolab/crystal/crystal-validator/src\\\"`).chomp.stringify.downcase }}","doc":null,"summary":null}],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":null,"doc":"Alias of `Validator`","summary":"

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":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validator.cr#L116"},{"filename":"src/validators/alpha_num.cr","line_number":8,"url":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/alpha_num.cr#L8"},{"filename":"src/validators/case_sensitive.cr","line_number":8,"url":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/case_sensitive.cr#L8"},{"filename":"src/validators/comparisons.cr","line_number":8,"url":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/comparisons.cr#L8"},{"filename":"src/validators/format.cr","line_number":8,"url":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/format.cr#L8"},{"filename":"src/validators/geo.cr","line_number":8,"url":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/geo.cr#L8"},{"filename":"src/validators/presence.cr","line_number":8,"url":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/presence.cr#L8"},{"filename":"src/validators/uri.cr","line_number":8,"url":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/uri.cr#L8"}],"repository_name":"validator","program":false,"enum":false,"alias":false,"aliased":"","const":false,"constants":[{"id":"VERSION","name":"VERSION","value":"{{ (`shards version \\\"/media/data/lab/dev/work/projects/nicolab/crystal/crystal-validator/src\\\"`).chomp.stringify.downcase }}","doc":null,"summary":null}],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":null,"doc":"∠(・.-)―〉 →◎ `validator` is a [Crystal](https://crystal-lang.org) data validation module.\nVery simple and efficient, all validations return `true` or `false`.\n\nAlso [validator/check](https://nicolab.github.io/crystal-validator/Check.html)\n(not exposed by default) provides error message handling intended for the end user.\n\nThere are 2 main ways to use *validator*:\n\n- As a simple validator to check rules (eg: email, url, min, max, presence, in, ...) which return a boolean.\n- As a more advanced validation system which will check a series of rules\n and returns all validation errors encountered with custom or standard messages.\n\nBy default the **validator** module expose only `Validator` and `Valid` (alias) in the scope:\n\n```\nrequire \"validator\"\n\nValid.email? \"contact@example.org\" # => true\nValid.url? \"https://github.com/Nicolab/crystal-validator\" # => true\nValid.my_validator? \"value to validate\", \"hello\", 42 # => true\n```\n\nAn (optional) expressive validation flavor, `is` available as an alternative. \\\nNot exposed by default, it must be imported:\n\n```\nrequire \"validator/is\"\n\nis :email?, \"contact@example.org\" # => true\nis :url?, \"https://github.com/Nicolab/crystal-validator\" # => true\nis :my_validator?, \"value to validate\", \"hello\", 42 # => true\n\n# raises an error if the email is not valid\nis! :email?, \"contact@@example..org\" # => Validator::Error\n```\n\n`is` is a macro, no overhead during the runtime 🚀\n By the nature of the macros, you can't pass the *validator* name dynamically\n with a variable like that `is(validator_name, \"my value to validate\", arg)`.\n But of course you can pass arguments with variables `is(:validator_name?, arg1, arg2)`.\n\n\n## Check\n\nMake a series of checks, with a customized error message for each case.\n\n```crystal\nrequire \"validator/check\"\n\ncheck = Check.new\n\ncheck(\"email\", \"The email is required.\", is :absence?, \"email\", user)\n```\n## Custom validator\n\nJust add your own method to register a custom *validator* or to overload an existing *validator*.\n\n```crystal\nmodule Validator\n # My custom validator\n def self.my_validator?(value, arg : String, another_arg : Int32) : Bool\n # write here the logic of your validator...\n return true\n end\nend\n\n# Call it\nputs Valid.my_validator?(\"value to validate\", \"hello\", 42) # => true\n\n# or with the `is` flavor\nputs is :my_validator?, \"value to validate\", \"hello\", 42 # => true\n```\n\n`Check` is a simple and lightweight wrapper, let your imagination run wild to add your logic around it.\n\nUsing the custom validator with the validation rules:\n\n```\nrequire \"validator/check\"\n\nclass Article\n # Mixin\n Check.checkable\n\n property title : String\n property content : String\n\n Check.rules(\n content: {\n # Now the custom validator is available\n check: {\n my_validator: {\"My validator error message\"},\n between: {\"The article content must be between 10 and 20 000 characters\", 10, 20_000},\n # ...\n },\n },\n )\nend\n\n# Triggered with all data\nv, article = Article.check(input_data)\n\n# Triggered with one value\nv, content = Article.check_content(input_data[\"content\"]?)\n```","summary":"

∠(・.-)―〉 →◎ validator is a Crystal data validation module.

","class_methods":[{"id":"absence?(key:String|Symbol,list:NamedTuple):Bool-class-method","html_id":"absence?(key:String|Symbol,list:NamedTuple):Bool-class-method","name":"absence?","doc":"Validates the absence of the value.\n- See also `#not_in?`.\n- See also `#empty?`.","summary":"

Validates the absence of the value.

","abstract":false,"args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"String | Symbol"},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"NamedTuple"}],"args_string":"(key : String | Symbol, list : NamedTuple) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/presence.cr#L47","def":{"name":"absence?","args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"String | Symbol"},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"NamedTuple"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"self.empty?(list[key]?)"}},{"id":"absence?(key:String|Symbol|Number,list:Hash):Bool-class-method","html_id":"absence?(key:String|Symbol|Number,list:Hash):Bool-class-method","name":"absence?","doc":"Validates the absence of the value.\n- See also `#not_in?`.\n- See also `#empty?`.","summary":"

Validates the absence of the value.

","abstract":false,"args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"String | Symbol | Number"},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Hash"}],"args_string":"(key : String | Symbol | Number, list : Hash) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/presence.cr#L42","def":{"name":"absence?","args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"String | Symbol | Number"},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Hash"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"self.empty?(list[key]?)"}},{"id":"accepted?(value:String):Bool-class-method","html_id":"accepted?(value:String):Bool-class-method","name":"accepted?","doc":"Validates that the *value* `String` is the representation of an acceptance.\n> One of: \"yes\", \"y\", \"on\", \"o\", \"ok\", \"1\", \"true\"\n- See also `#refused?`.","summary":"

Validates that the 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","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/presence.cr#L180","def":{"name":"accepted?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"self.in?(value.downcase, [\"yes\", \"y\", \"on\", \"o\", \"ok\", \"1\", \"true\"])"}},{"id":"accepted?(value):Bool-class-method","html_id":"accepted?(value):Bool-class-method","name":"accepted?","doc":"Validates that the *value* is the representation of an acceptance.\n> One of: \"yes\", \"y\", \"on\", \"o\", \"ok\", \"1\", \"true\"\n\n*value* must implements *#to_s* method.\n- See also `#refused?`.","summary":"

Validates that the value is the representation of an acceptance.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"args_string":"(value) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/presence.cr#L189","def":{"name":"accepted?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"self.accepted?(value.to_s)"}},{"id":"ascii_only?(value:String):Bool-class-method","html_id":"ascii_only?(value:String):Bool-class-method","name":"ascii_only?","doc":"Validates that the *value* `String`\nis comprised in its entirety by ASCII characters.","summary":"

Validates that the 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","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/format.cr#L41","def":{"name":"ascii_only?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value.ascii_only?"}},{"id":"ascii_only?(values:Array(String)):Bool-class-method","html_id":"ascii_only?(values:Array(String)):Bool-class-method","name":"ascii_only?","doc":"Validates that all the `String` in the *values* `Array`\nare comprised in their entirety by ASCII characters.","summary":"

Validates that all the String in the 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","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/format.cr#L47","def":{"name":"ascii_only?","args":[{"name":"values","doc":null,"default_value":"","external_name":"values","restriction":"Array(String)"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"size = value.size\nwhile size\n size = size - 1\n if value.ascii_only?(values[i])\n else\n return false\n end\nend\ntrue\n"}},{"id":"base64?(value:String):Bool-class-method","html_id":"base64?(value:String):Bool-class-method","name":"base64?","doc":"Validates that the *value* has the format *base64*.","summary":"

Validates that the value has the format base64.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/format.cr#L87","def":{"name":"base64?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"if (value.match(@@rx_base64)) && ((value.size % 4) === 0)\n return true\nend\nfalse\n"}},{"id":"between?(value,min,max):Bool-class-method","html_id":"between?(value,min,max):Bool-class-method","name":"between?","doc":"Validates that the *value* is between (inclusive) *min* and *max*.","summary":"

Validates that the value is between (inclusive) min and max.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"min","doc":null,"default_value":"","external_name":"min","restriction":""},{"name":"max","doc":null,"default_value":"","external_name":"max","restriction":""}],"args_string":"(value, min, max) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/comparisons.cr#L87","def":{"name":"between?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"min","doc":null,"default_value":"","external_name":"min","restriction":""},{"name":"max","doc":null,"default_value":"","external_name":"max","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value >= min && value <= max"}},{"id":"between?(value:String|Array,min:Int,max:Int):Bool-class-method","html_id":"between?(value:String|Array,min:Int,max:Int):Bool-class-method","name":"between?","doc":"Validates that the size of the *value* (`String` or `Array`) is between\n(inclusive) *min* and *max*.\n- See also `#size?`.","summary":"

Validates that the size of the value (String or Array) is between (inclusive) min and max.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String | Array"},{"name":"min","doc":null,"default_value":"","external_name":"min","restriction":"Int"},{"name":"max","doc":null,"default_value":"","external_name":"max","restriction":"Int"}],"args_string":"(value : String | Array, min : Int, max : Int) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/comparisons.cr#L94","def":{"name":"between?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String | Array"},{"name":"min","doc":null,"default_value":"","external_name":"min","restriction":"Int"},{"name":"max","doc":null,"default_value":"","external_name":"max","restriction":"Int"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"size = value.size\nsize >= min && size <= max\n"}},{"id":"domain?(value:String):Bool-class-method","html_id":"domain?(value:String):Bool-class-method","name":"domain?","doc":null,"summary":null,"abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/uri.cr#L23","def":{"name":"domain?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"size = value.size\nif size > 75 || size < 4\n return false\nend\nif value.includes?(\"..\")\n return false\nend\nif m = value.match(@@rx_domain)\nelse\n return false\nend\next_size = m[\"ext\"].size\nif ext_size < 2 || ext_size > 12\n return false\nend\ntrue\n"}},{"id":"email?(value:String):Bool-class-method","html_id":"email?(value:String):Bool-class-method","name":"email?","doc":"Validates that the *value* is an email.\nThis method is stricter than the standard allows.\nIt is subjectively based on the common addresses\nof organisations (@enterprise.ltd, ...)\nand mail services suck as Gmail, Hotmail, Yahoo !, ...","summary":"

Validates that the value is an email.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/uri.cr#L158","def":{"name":"email?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"size = value.size\nif size > 60 || size < 7\n return false\nend\nif value.includes?(\"..\")\n return false\nend\nif value.includes?(\"--\")\n return false\nend\nif value.includes?(\"___\")\n return false\nend\nif m = value.match(@@rx_email)\nelse\n return false\nend\nself.domain?(\"#{m[\"name\"]}.#{m[\"ext\"]}\")\n"}},{"id":"empty?(value):Bool-class-method","html_id":"empty?(value):Bool-class-method","name":"empty?","doc":"Validates that the *value* is empty.\n- See also `#absence?`.\n- See also `#not_in?`.","summary":"

Validates that the value is empty.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"args_string":"(value) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/presence.cr#L58","def":{"name":"empty?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"case value\nwhen .nil?\n true\nwhen .is_a?(String)\n value.presence.nil?\nwhen .is_a?(Number)\n value == 0\nwhen .responds_to?(:size)\n value.size == 0\nelse\n false\nend"}},{"id":"ends?(value:String,search:String):Bool-class-method","html_id":"ends?(value:String,search:String):Bool-class-method","name":"ends?","doc":"Validates that the `String` *value* ends with *search*.\n- See also `#starts?`.\n- See also `#match?`.\n- See also `#in?`.","summary":"

Validates that the 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","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/presence.cr#L243","def":{"name":"ends?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"search","doc":null,"default_value":"","external_name":"search","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value.ends_with?(search)"}},{"id":"ends?(value:String,search:Char):Bool-class-method","html_id":"ends?(value:String,search:Char):Bool-class-method","name":"ends?","doc":"Validates that the `String` *value* ends with *search*.\n- See also `#starts?`.\n- See also `#match?`.\n- See also `#in?`.","summary":"

Validates that the 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","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/presence.cr#L248","def":{"name":"ends?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"search","doc":null,"default_value":"","external_name":"search","restriction":"Char"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value.ends_with?(search)"}},{"id":"ends?(value:String,search:Regex):Bool-class-method","html_id":"ends?(value:String,search:Regex):Bool-class-method","name":"ends?","doc":"Validates that the `String` *value* ends with *search*.\n- See also `#starts?`.\n- See also `#match?`.\n- See also `#in?`.","summary":"

Validates that the 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","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/presence.cr#L253","def":{"name":"ends?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"search","doc":null,"default_value":"","external_name":"search","restriction":"Regex"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value.ends_with?(search)"}},{"id":"eq?(value,another_value):Bool-class-method","html_id":"eq?(value,another_value):Bool-class-method","name":"eq?","doc":"Validates that the *value* is equal to *another_value*.","summary":"

Validates that the value is equal to another_value.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"another_value","doc":null,"default_value":"","external_name":"another_value","restriction":""}],"args_string":"(value, another_value) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/comparisons.cr#L10","def":{"name":"eq?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"another_value","doc":null,"default_value":"","external_name":"another_value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value == another_value"}},{"id":"gt?(value,another_value):Bool-class-method","html_id":"gt?(value,another_value):Bool-class-method","name":"gt?","doc":"Validates that the *value* is greater than *another_value*.","summary":"

Validates that the value is greater than another_value.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"another_value","doc":null,"default_value":"","external_name":"another_value","restriction":""}],"args_string":"(value, another_value) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/comparisons.cr#L15","def":{"name":"gt?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"another_value","doc":null,"default_value":"","external_name":"another_value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value > another_value"}},{"id":"gt?(value:String|Array,limit:Int):Bool-class-method","html_id":"gt?(value:String|Array,limit:Int):Bool-class-method","name":"gt?","doc":"Validates that the size of the *value* (`String` or `Array`)\nis greater than *limit* number.","summary":"

Validates that the size of the value (String or Array) is greater than limit number.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String | Array"},{"name":"limit","doc":null,"default_value":"","external_name":"limit","restriction":"Int"}],"args_string":"(value : String | Array, limit : Int) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/comparisons.cr#L21","def":{"name":"gt?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String | Array"},{"name":"limit","doc":null,"default_value":"","external_name":"limit","restriction":"Int"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value.size > limit"}},{"id":"gte?(value,another_value):Bool-class-method","html_id":"gte?(value,another_value):Bool-class-method","name":"gte?","doc":"Validates that the *value* is equal to or greater than *another_value*.\n> Similar to `#min`.","summary":"

Validates that the value is equal to or greater than another_value.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"another_value","doc":null,"default_value":"","external_name":"another_value","restriction":""}],"args_string":"(value, another_value) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/comparisons.cr#L27","def":{"name":"gte?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"another_value","doc":null,"default_value":"","external_name":"another_value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value >= another_value"}},{"id":"gte?(value:String|Array,min:Int):Bool-class-method","html_id":"gte?(value:String|Array,min:Int):Bool-class-method","name":"gte?","doc":"Validates that the size of the *value* (`String` or `Array`)\nis greater than *min* number.\n> Similar to `#min`.","summary":"

Validates that the size of the value (String or Array) is greater than min number.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String | Array"},{"name":"min","doc":null,"default_value":"","external_name":"min","restriction":"Int"}],"args_string":"(value : String | Array, min : Int) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/comparisons.cr#L34","def":{"name":"gte?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String | Array"},{"name":"min","doc":null,"default_value":"","external_name":"min","restriction":"Int"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value.size >= min"}},{"id":"hex?(value:String):Bool-class-method","html_id":"hex?(value:String):Bool-class-method","name":"hex?","doc":"Validates that the `String` *value* does denote\na representation of a hexadecimal string.","summary":"

Validates that the 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","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/format.cr#L112","def":{"name":"hex?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!value.match(@@rx_hex).nil?"}},{"id":"hex?(value:Bytes):Bool-class-method","html_id":"hex?(value:Bytes):Bool-class-method","name":"hex?","doc":"Validates that the `Bytes` *value* does denote\na representation of a hexadecimal slice of Bytes.","summary":"

Validates that the 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","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/format.cr#L118","def":{"name":"hex?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"Bytes"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!(String.new(value)).match(@@rx_hex).nil?"}},{"id":"hex_color?(value:String):Bool-class-method","html_id":"hex_color?(value:String):Bool-class-method","name":"hex_color?","doc":"Validates that the `String` *value* does denote\na representation of a hexadecimal color.\n\n```\nValid.hex_color? \"#fff\" => true\nValid.hex_color? \"#ffffff\" => true\n```","summary":"

Validates that the 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","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/format.cr#L129","def":{"name":"hex_color?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!value.match(@@rx_hex_color).nil?"}},{"id":"in?(value,list:Array):Bool-class-method","html_id":"in?(value,list:Array):Bool-class-method","name":"in?","doc":"Validates that the (*list*) contains the *value*.\n- See also `#presence?`.\n- See also `#not_in?`.\n- See also `#not_empty?`.","summary":"

Validates that the (list) contains the value.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Array"}],"args_string":"(value, list : Array) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/presence.cr#L109","def":{"name":"in?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Array"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"list.includes?(value)"}},{"id":"in?(value:String,str:String):Bool-class-method","html_id":"in?(value:String,str:String):Bool-class-method","name":"in?","doc":"Validates that the (*str*) `String` contains the *value*.\n- See also `#presence?`.\n- See also `#not_in?`.\n- See also `#not_empty?`.","summary":"

Validates that the (str) String contains the value.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"str","doc":null,"default_value":"","external_name":"str","restriction":"String"}],"args_string":"(value : String, str : String) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/presence.cr#L101","def":{"name":"in?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"str","doc":null,"default_value":"","external_name":"str","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"str.includes?(value)"}},{"id":"in?(key:Symbol|String,list:Hash):Bool-class-method","html_id":"in?(key:Symbol|String,list:Hash):Bool-class-method","name":"in?","doc":"Validates that the (*list*) contains the *value*.\n- See also `#presence?`.\n- See also `#not_in?`.\n- See also `#not_empty?`.","summary":"

Validates that the (list) contains the value.

","abstract":false,"args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"Symbol | String"},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Hash"}],"args_string":"(key : Symbol | String, list : Hash) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/presence.cr#L129","def":{"name":"in?","args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"Symbol | String"},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Hash"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"list.has_key?(key)"}},{"id":"in?(key:Symbol|String,list:NamedTuple):Bool-class-method","html_id":"in?(key:Symbol|String,list:NamedTuple):Bool-class-method","name":"in?","doc":"Validates that the (*list*) contains the *value*.\n- See also `#presence?`.\n- See also `#not_in?`.\n- See also `#not_empty?`.","summary":"

Validates that the (list) contains the value.

","abstract":false,"args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"Symbol | String"},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"NamedTuple"}],"args_string":"(key : Symbol | String, list : NamedTuple) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/presence.cr#L124","def":{"name":"in?","args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"Symbol | String"},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"NamedTuple"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"list.has_key?(key)"}},{"id":"in?(value,list:Range):Bool-class-method","html_id":"in?(value,list:Range):Bool-class-method","name":"in?","doc":"Validates that the (*list*) contains the *value*.\n- See also `#presence?`.\n- See also `#not_in?`.\n- See also `#not_empty?`.","summary":"

Validates that the (list) contains the value.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Range"}],"args_string":"(value, list : Range) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/presence.cr#L119","def":{"name":"in?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Range"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"list.includes?(value)"}},{"id":"in?(value,list:Tuple):Bool-class-method","html_id":"in?(value,list:Tuple):Bool-class-method","name":"in?","doc":"Validates that the (*list*) contains the *value*.\n- See also `#presence?`.\n- See also `#not_in?`.\n- See also `#not_empty?`.","summary":"

Validates that the (list) contains the value.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Tuple"}],"args_string":"(value, list : Tuple) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/presence.cr#L114","def":{"name":"in?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Tuple"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"list.includes?(value)"}},{"id":"ip?(value:String):Bool-class-method","html_id":"ip?(value:String):Bool-class-method","name":"ip?","doc":"Validates that the *value* is an IP (IPv4 or IPv6).","summary":"

Validates that the value is an IP (IPv4 or IPv6).

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/uri.cr#L77","def":{"name":"ip?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"(self.ipv4?(value)) || (self.ipv6?(value))"}},{"id":"ipv4?(value:String):Bool-class-method","html_id":"ipv4?(value:String):Bool-class-method","name":"ipv4?","doc":"Validates that the *value* is an IPv4.","summary":"

Validates that the value is an IPv4.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/uri.cr#L82","def":{"name":"ipv4?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!value.match(@@rx_ipv4).nil?"}},{"id":"ipv6?(value:String):Bool-class-method","html_id":"ipv6?(value:String):Bool-class-method","name":"ipv6?","doc":"Validates that the *value* is an IPv6.","summary":"

Validates that the value is an IPv6.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/uri.cr#L87","def":{"name":"ipv6?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"addr_and_zone = [value]\nif value.includes?('%')\n addr_and_zone = value.split('%')\n if addr_and_zone.size == 2\n else\n return false\n end\n if addr_and_zone[0].includes?(':')\n else\n return false\n end\n if addr_and_zone[1] == \"\"\n return false\n end\nend\nblocks = addr_and_zone[0].split(':')\nfound_omission_block = false\nfound_ipv4_transition_block = self.ipv4?(blocks[blocks.size - 1])\nexpected_number_of_blocks = found_ipv4_transition_block ? 7 : 8\nif blocks.size > expected_number_of_blocks\n return false\nend\nif value == \"::\"\n return true\nend\nif value[0...2] == \"::\"\n blocks.shift(2)\n found_omission_block = true\nelse\n if value[(value.size - 2)..] == \"::\"\n blocks.pop(2)\n found_omission_block = true\n end\nend\ni = 0\nwhile i < blocks.size\n if ((blocks[i] === \"\") && i > 0) && i < (blocks.size - 1)\n if found_omission_block\n return false\n end\n found_omission_block = true\n else\n if (!(found_ipv4_transition_block && (i == (blocks.size - 1)))) && blocks[i].match(@@rx_ipv6_block).nil?\n return false\n end\n end\n i = i + 1\nend\nif found_omission_block\n return blocks.size >= 1\nend\nblocks.size == expected_number_of_blocks\n"}},{"id":"json?(value:String,strict:Bool=true):Bool-class-method","html_id":"json?(value:String,strict:Bool=true):Bool-class-method","name":"json?","doc":"Validates that the *value* represents a JSON string.\n*strict* to `true` (default) to try to parse the JSON,\nreturns `false` if the parsing fails.\nIf *strict* is `false`, only the first char and the last char are checked.","summary":"

Validates that the value represents a JSON string.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"strict","doc":null,"default_value":"true","external_name":"strict","restriction":"Bool"}],"args_string":"(value : String, strict : Bool = true) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/format.cr#L64","def":{"name":"json?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"strict","doc":null,"default_value":"true","external_name":"strict","restriction":"Bool"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"if strict\n begin\n JSON.parse(value)\n rescue err\n return false\n else\n return true\n end\nend\n((self.starts?(value, \"{\")) && (self.ends?(value, \"}\"))) || ((self.starts?(value, \"[\")) && (self.ends?(value, \"]\")))\n"}},{"id":"jwt?(value:String):Bool-class-method","html_id":"jwt?(value:String):Bool-class-method","name":"jwt?","doc":"Validates that the *value* is a *JSON Web Token*.","summary":"

Validates that the value is a JSON Web Token.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/format.cr#L95","def":{"name":"jwt?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!value.match(@@rx_jwt).nil?"}},{"id":"lat?(value:String|Float):Bool-class-method","html_id":"lat?(value:String|Float):Bool-class-method","name":"lat?","doc":"Validates that the *value* is a valid format representation of a geographical latitude.\n- See also `#lng?`.\n- See also `#lat_lng?`.","summary":"

Validates that the value is a valid format representation of a geographical latitude.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String | Float"}],"args_string":"(value : String | Float) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/geo.cr#L31","def":{"name":"lat?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String | Float"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!value.to_s.match(@@rx_geo_lat).nil?"}},{"id":"lat_lng?(value:String):Bool-class-method","html_id":"lat_lng?(value:String):Bool-class-method","name":"lat_lng?","doc":"Validates that the *value* is a valid format representation of\na geographical position (given in latitude and longitude).\n- See also `#lat?`.\n- See also `#lng?`.","summary":"

Validates that the value is a valid format representation of a geographical position (given in latitude and longitude).

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/geo.cr#L16","def":{"name":"lat_lng?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"if !(value.includes?(\",\"))\n return false\nend\nlat, lng = value.split(\",\")\nif lat && lng\nelse\n return false\nend\nif ((lat.starts_with?('(')) && (!(lng.ends_with?(')'))))\n return false\nend\nif ((lng.ends_with?(')')) && (!(lat.starts_with?('('))))\n return false\nend\nif (lat.match(@@rx_geo_lat)) && (lng.match(@@rx_geo_lng))\n return true\nend\nfalse\n"}},{"id":"lng?(value:String|Float):Bool-class-method","html_id":"lng?(value:String|Float):Bool-class-method","name":"lng?","doc":"Validates that the *value* is a valid format representation of a geographical longitude.\n- See also `#lat?`.\n- See also `#lat_lng?`.","summary":"

Validates that the value is a valid format representation of a geographical longitude.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String | Float"}],"args_string":"(value : String | Float) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/geo.cr#L38","def":{"name":"lng?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String | Float"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!value.to_s.match(@@rx_geo_lng).nil?"}},{"id":"lower?(value:String):Bool-class-method","html_id":"lower?(value:String):Bool-class-method","name":"lower?","doc":"Validates that the *value* is in lower case.","summary":"

Validates that the value is in lower case.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/case_sensitive.cr#L10","def":{"name":"lower?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"(!value.blank?) && (value.downcase === value)"}},{"id":"lt?(value:String|Array,limit:Int):Bool-class-method","html_id":"lt?(value:String|Array,limit:Int):Bool-class-method","name":"lt?","doc":"Validates that the size of the *value* (`String` or `Array`)\nis lesser than *limit* number.","summary":"

Validates that the size of the value (String or Array) is lesser than limit number.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String | Array"},{"name":"limit","doc":null,"default_value":"","external_name":"limit","restriction":"Int"}],"args_string":"(value : String | Array, limit : Int) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/comparisons.cr#L45","def":{"name":"lt?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String | Array"},{"name":"limit","doc":null,"default_value":"","external_name":"limit","restriction":"Int"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value.size < limit"}},{"id":"lt?(value,another_value):Bool-class-method","html_id":"lt?(value,another_value):Bool-class-method","name":"lt?","doc":"Validates that the *value* is lesser than *another_value*.","summary":"

Validates that the value is lesser than another_value.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"another_value","doc":null,"default_value":"","external_name":"another_value","restriction":""}],"args_string":"(value, another_value) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/comparisons.cr#L39","def":{"name":"lt?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"another_value","doc":null,"default_value":"","external_name":"another_value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value < another_value"}},{"id":"lte?(value:String|Array,max:Int):Bool-class-method","html_id":"lte?(value:String|Array,max:Int):Bool-class-method","name":"lte?","doc":"Validates that the size of the *value* (`String` or `Array`)\nis equal or lesser than *max* number.\n> Similar to `#max`.","summary":"

Validates that the size of the value (String or Array) is equal or lesser than max number.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String | Array"},{"name":"max","doc":null,"default_value":"","external_name":"max","restriction":"Int"}],"args_string":"(value : String | Array, max : Int) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/comparisons.cr#L58","def":{"name":"lte?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String | Array"},{"name":"max","doc":null,"default_value":"","external_name":"max","restriction":"Int"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value.size <= max"}},{"id":"lte?(value,another_value):Bool-class-method","html_id":"lte?(value,another_value):Bool-class-method","name":"lte?","doc":"Validates that the *value* is equal to or lesser than *another_value*.\n> Similar to `#max`.","summary":"

Validates that the value is equal to or lesser than another_value.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"another_value","doc":null,"default_value":"","external_name":"another_value","restriction":""}],"args_string":"(value, another_value) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/comparisons.cr#L51","def":{"name":"lte?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"another_value","doc":null,"default_value":"","external_name":"another_value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value <= another_value"}},{"id":"mac_addr?(value:String,no_colons:Bool=false):Bool-class-method","html_id":"mac_addr?(value:String,no_colons:Bool=false):Bool-class-method","name":"mac_addr?","doc":"Validates that the *value* is a MAC address.","summary":"

Validates that the value is a MAC address.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"no_colons","doc":null,"default_value":"false","external_name":"no_colons","restriction":"Bool"}],"args_string":"(value : String, no_colons : Bool = false) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/uri.cr#L176","def":{"name":"mac_addr?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"no_colons","doc":null,"default_value":"false","external_name":"no_colons","restriction":"Bool"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"if no_colons\n return !value.match(@@rx_mac_addr_no_colons).nil?\nend\n(((!value.match(@@rx_mac_addr).nil?) || (!value.match(@@rx_mac_addr_with_hyphen).nil?)) || (!value.match(@@rx_mac_addr_with_spaces).nil?)) || (!value.match(@@rx_mac_addr_with_dots).nil?)\n"}},{"id":"magnet_uri?(value:String):Bool-class-method","html_id":"magnet_uri?(value:String):Bool-class-method","name":"magnet_uri?","doc":"Validates that the *value* is a Magnet URI.","summary":"

Validates that the value is a Magnet URI.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/uri.cr#L186","def":{"name":"magnet_uri?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!value.match(@@rx_magnet_uri).nil?"}},{"id":"match?(value:Number,pattern:Regex):Bool-class-method","html_id":"match?(value:Number,pattern:Regex):Bool-class-method","name":"match?","doc":"Validates that the *value* matches the *pattern*.","summary":"

Validates that the value matches the pattern.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"Number"},{"name":"pattern","doc":null,"default_value":"","external_name":"pattern","restriction":"Regex"}],"args_string":"(value : Number, pattern : Regex) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/presence.cr#L15","def":{"name":"match?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"Number"},{"name":"pattern","doc":null,"default_value":"","external_name":"pattern","restriction":"Regex"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!value.to_s.match(pattern).nil?"}},{"id":"match?(value:String,pattern:Regex):Bool-class-method","html_id":"match?(value:String,pattern:Regex):Bool-class-method","name":"match?","doc":"Validates that the *value* matches the *pattern*.","summary":"

Validates that the value matches the pattern.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"pattern","doc":null,"default_value":"","external_name":"pattern","restriction":"Regex"}],"args_string":"(value : String, pattern : Regex) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/presence.cr#L10","def":{"name":"match?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"pattern","doc":null,"default_value":"","external_name":"pattern","restriction":"Regex"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!value.match(pattern).nil?"}},{"id":"max?(value,max):Bool-class-method","html_id":"max?(value,max):Bool-class-method","name":"max?","doc":"Validates that the *value* is equal to or lesser than *max* (inclusive).\n> Similar to `#lte`.","summary":"

Validates that the value is equal to or lesser than max (inclusive).

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"max","doc":null,"default_value":"","external_name":"max","restriction":""}],"args_string":"(value, max) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/comparisons.cr#L76","def":{"name":"max?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"max","doc":null,"default_value":"","external_name":"max","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value <= max"}},{"id":"max?(value:String|Array,max:Int):Bool-class-method","html_id":"max?(value:String|Array,max:Int):Bool-class-method","name":"max?","doc":":ditto:\n> Based on the size of the `String`.","summary":"

:ditto: > Based on the size of the String.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String | Array"},{"name":"max","doc":null,"default_value":"","external_name":"max","restriction":"Int"}],"args_string":"(value : String | Array, max : Int) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/comparisons.cr#L82","def":{"name":"max?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String | Array"},{"name":"max","doc":null,"default_value":"","external_name":"max","restriction":"Int"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value.size <= max"}},{"id":"md5?(value:String):Bool-class-method","html_id":"md5?(value:String):Bool-class-method","name":"md5?","doc":"Validates that the *value* has the format *md5*.","summary":"

Validates that the value has the format md5.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/format.cr#L82","def":{"name":"md5?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!value.match(@@rx_md5).nil?"}},{"id":"min?(value,min):Bool-class-method","html_id":"min?(value,min):Bool-class-method","name":"min?","doc":"Validates that the *value* is equal to or greater than *min* (inclusive).\n> Similar to `#gte`.","summary":"

Validates that the value is equal to or greater than min (inclusive).

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"min","doc":null,"default_value":"","external_name":"min","restriction":""}],"args_string":"(value, min) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/comparisons.cr#L64","def":{"name":"min?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"min","doc":null,"default_value":"","external_name":"min","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value >= min"}},{"id":"min?(value:String|Array,min:Int):Bool-class-method","html_id":"min?(value:String|Array,min:Int):Bool-class-method","name":"min?","doc":":ditto:\n> Based on the size of the `String`.","summary":"

:ditto: > Based on the size of the String.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String | Array"},{"name":"min","doc":null,"default_value":"","external_name":"min","restriction":"Int"}],"args_string":"(value : String | Array, min : Int) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/comparisons.cr#L70","def":{"name":"min?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String | Array"},{"name":"min","doc":null,"default_value":"","external_name":"min","restriction":"Int"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value.size >= min"}},{"id":"mongo_id?(value:Bytes):Bool-class-method","html_id":"mongo_id?(value:Bytes):Bool-class-method","name":"mongo_id?","doc":"Validates that the `Bytes` *value* does denote\na representation of a *MongoID* slice of Bytes.","summary":"

Validates that the 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","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/format.cr#L143","def":{"name":"mongo_id?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"Bytes"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"(self.hex?(value)) && (value.size == 24)"}},{"id":"mongo_id?(value:String):Bool-class-method","html_id":"mongo_id?(value:String):Bool-class-method","name":"mongo_id?","doc":"Validates that the `String` *value* does denote\na representation of a *MongoID* string.","summary":"

Validates that the 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","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/format.cr#L137","def":{"name":"mongo_id?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"(self.hex?(value)) && (value.size == 24)"}},{"id":"not_empty?(value):Bool-class-method","html_id":"not_empty?(value):Bool-class-method","name":"not_empty?","doc":"Validates that the *value* is not empty.\n- See also `#presence?`.\n- See also `#in?`.","summary":"

Validates that the value is not empty.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"args_string":"(value) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/presence.cr#L71","def":{"name":"not_empty?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"(self.empty?(value)) == false"}},{"id":"not_in?(value:String,str:String):Bool-class-method","html_id":"not_in?(value:String,str:String):Bool-class-method","name":"not_in?","doc":"Validates that the (*str*) `String` does not contain the *value*.\n- See also `#absence?`.\n- See also `#in?`.\n- See also `#empty?`.","summary":"

Validates that the (str) String does not contain the value.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"str","doc":null,"default_value":"","external_name":"str","restriction":"String"}],"args_string":"(value : String, str : String) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/presence.cr#L141","def":{"name":"not_in?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"str","doc":null,"default_value":"","external_name":"str","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!(str.includes?(value))"}},{"id":"not_in?(value,list:Array):Bool-class-method","html_id":"not_in?(value,list:Array):Bool-class-method","name":"not_in?","doc":"Validates that the (*list*) does not contain the *value*.\n- See also `#absence?`.\n- See also `#in?`.\n- See also `#empty?`.","summary":"

Validates that the (list) does not contain the value.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Array"}],"args_string":"(value, list : Array) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/presence.cr#L149","def":{"name":"not_in?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Array"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!(list.includes?(value))"}},{"id":"not_in?(value,list:Tuple):Bool-class-method","html_id":"not_in?(value,list:Tuple):Bool-class-method","name":"not_in?","doc":"Validates that the (*list*) does not contain the *value*.\n- See also `#absence?`.\n- See also `#in?`.\n- See also `#empty?`.","summary":"

Validates that the (list) does not contain the value.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Tuple"}],"args_string":"(value, list : Tuple) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/presence.cr#L154","def":{"name":"not_in?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Tuple"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!(list.includes?(value))"}},{"id":"not_in?(value,list:Range):Bool-class-method","html_id":"not_in?(value,list:Range):Bool-class-method","name":"not_in?","doc":"Validates that the (*list*) does not contain the *value*.\n- See also `#absence?`.\n- See also `#in?`.\n- See also `#empty?`.","summary":"

Validates that the (list) does not contain the value.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Range"}],"args_string":"(value, list : Range) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/presence.cr#L159","def":{"name":"not_in?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Range"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!(list.includes?(value))"}},{"id":"not_in?(key:Symbol|String,list:NamedTuple):Bool-class-method","html_id":"not_in?(key:Symbol|String,list:NamedTuple):Bool-class-method","name":"not_in?","doc":"Validates that the (*list*) does not contain the *value*.\n- See also `#absence?`.\n- See also `#in?`.\n- See also `#empty?`.","summary":"

Validates that the (list) does not contain the value.

","abstract":false,"args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"Symbol | String"},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"NamedTuple"}],"args_string":"(key : Symbol | String, list : NamedTuple) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/presence.cr#L164","def":{"name":"not_in?","args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"Symbol | String"},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"NamedTuple"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!(list.has_key?(key))"}},{"id":"not_in?(key:Symbol|String,list:Hash):Bool-class-method","html_id":"not_in?(key:Symbol|String,list:Hash):Bool-class-method","name":"not_in?","doc":"Validates that the (*list*) does not contain the *value*.\n- See also `#absence?`.\n- See also `#in?`.\n- See also `#empty?`.","summary":"

Validates that the (list) does not contain the value.

","abstract":false,"args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"Symbol | String"},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Hash"}],"args_string":"(key : Symbol | String, list : Hash) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/presence.cr#L169","def":{"name":"not_in?","args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"Symbol | String"},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Hash"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!(list.has_key?(key))"}},{"id":"not_null?(value):Bool-class-method","html_id":"not_null?(value):Bool-class-method","name":"not_null?","doc":"Validates that the *value* is not null (`nil`).\n- See also `#null?`.\n- See also `#not_empty?`.","summary":"

Validates that the value is not null (nil).

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"args_string":"(value) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/presence.cr#L89","def":{"name":"not_null?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!value.nil?"}},{"id":"null?(value):Bool-class-method","html_id":"null?(value):Bool-class-method","name":"null?","doc":"Validates that the *value* is null (`nil`).\n- See also `#empty?`.\n- See also `#not_null?`.","summary":"

Validates that the value is null (nil).

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"args_string":"(value) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/presence.cr#L82","def":{"name":"null?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value.nil?"}},{"id":"number?(value:String):Bool-class-method","html_id":"number?(value:String):Bool-class-method","name":"number?","doc":"Validates that the *value* is a numeric `String` representation.","summary":"

Validates that the value is a numeric String representation.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/alpha_num.cr#L12","def":{"name":"number?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"(!value.blank?) && (!value.match(@@rx_number).nil?)"}},{"id":"port?(value:String="0",min:String="1",max:String="65535"):Bool-class-method","html_id":"port?(value:String="0",min:String="1",max:String="65535"):Bool-class-method","name":"port?","doc":"Validates that the *value* is in a valid port range,\nbetween (inclusive) 1 / *min* and 65535 / *max*.","summary":"

Validates that the value is in a valid port range, between (inclusive) 1 / min and 65535 / max.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"\"0\"","external_name":"value","restriction":"String"},{"name":"min","doc":null,"default_value":"\"1\"","external_name":"min","restriction":"String"},{"name":"max","doc":null,"default_value":"\"65535\"","external_name":"max","restriction":"String"}],"args_string":"(value : String = "0", min : String = "1", max : String = "65535") : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/uri.cr#L44","def":{"name":"port?","args":[{"name":"value","doc":null,"default_value":"\"0\"","external_name":"value","restriction":"String"},{"name":"min","doc":null,"default_value":"\"1\"","external_name":"min","restriction":"String"},{"name":"max","doc":null,"default_value":"\"65535\"","external_name":"max","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"if (self.number?(min)) && (self.number?(max))\nelse\n return false\nend\nself.port?(value.to_i, min.to_i, max.to_i)\n"}},{"id":"port?(value=0,min=1,max=65535):Bool-class-method","html_id":"port?(value=0,min=1,max=65535):Bool-class-method","name":"port?","doc":"Validates that the *value* is in a valid port range,\nbetween (inclusive) 1 / *min* and 65535 / *max*.","summary":"

Validates that the value is in a valid port range, between (inclusive) 1 / min and 65535 / max.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"0","external_name":"value","restriction":""},{"name":"min","doc":null,"default_value":"1","external_name":"min","restriction":""},{"name":"max","doc":null,"default_value":"65535","external_name":"max","restriction":""}],"args_string":"(value = 0, min = 1, max = 65535) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/uri.cr#L38","def":{"name":"port?","args":[{"name":"value","doc":null,"default_value":"0","external_name":"value","restriction":""},{"name":"min","doc":null,"default_value":"1","external_name":"min","restriction":""},{"name":"max","doc":null,"default_value":"65535","external_name":"max","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"if self.between?(value, 1, 65535)\nelse\n return false\nend\nself.between?(value, min, max)\n"}},{"id":"presence?(key:String|Symbol,list:NamedTuple):Bool-class-method","html_id":"presence?(key:String|Symbol,list:NamedTuple):Bool-class-method","name":"presence?","doc":"Validates the presence of the value.\n- See also `#in?`.\n- See also `#not_empty?`.","summary":"

Validates the presence of the value.

","abstract":false,"args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"String | Symbol"},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"NamedTuple"}],"args_string":"(key : String | Symbol, list : NamedTuple) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/presence.cr#L31","def":{"name":"presence?","args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"String | Symbol"},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"NamedTuple"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"self.not_empty?(list[key]?)"}},{"id":"presence?(key:String|Symbol|Number,list:Hash):Bool-class-method","html_id":"presence?(key:String|Symbol|Number,list:Hash):Bool-class-method","name":"presence?","doc":"Validates the presence of the value.\n- See also `#in?`.\n- See also `#not_empty?`.","summary":"

Validates the presence of the value.

","abstract":false,"args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"String | Symbol | Number"},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Hash"}],"args_string":"(key : String | Symbol | Number, list : Hash) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/presence.cr#L26","def":{"name":"presence?","args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"String | Symbol | Number"},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Hash"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"self.not_empty?(list[key]?)"}},{"id":"refused?(value):Bool-class-method","html_id":"refused?(value):Bool-class-method","name":"refused?","doc":"Returns `true` if the *value* is the representation of a refusal.\n> One of: \"no\", \"n\", \"off\", \"0\", \"false\"\n\n*value* must implements *#to_s* method.\n- See also `#accepted?`.","summary":"

Returns true if the value is the representation of a refusal.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"args_string":"(value) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/presence.cr#L209","def":{"name":"refused?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"self.refused?(value.to_s)"}},{"id":"refused?(value:String):Bool-class-method","html_id":"refused?(value:String):Bool-class-method","name":"refused?","doc":"Validates that the *value* `String` is the representation of a refusal.\n> One of: \"no\", \"n\", \"off\", \"0\", \"false\"\n- See also `#accepted?`.","summary":"

Validates that the 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","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/presence.cr#L200","def":{"name":"refused?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"self.in?(value.downcase, [\"no\", \"n\", \"off\", \"0\", \"false\"])"}},{"id":"size?(value,size:Array(String))-class-method","html_id":"size?(value,size:Array(String))-class-method","name":"size?","doc":"Validates that the *value* is in the *size* array.\n- See also `#between?`.","summary":"

Validates that the value is in the size array.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"size","doc":null,"default_value":"","external_name":"size","restriction":"Array(String)"}],"args_string":"(value, size : Array(String))","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/comparisons.cr#L122","def":{"name":"size?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"size","doc":null,"default_value":"","external_name":"size","restriction":"Array(String)"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"size.includes?(value.size.to_s)"}},{"id":"size?(value,size:Array(Int))-class-method","html_id":"size?(value,size:Array(Int))-class-method","name":"size?","doc":"Validates that the *value* is in the *size* array.\n- See also `#between?`.","summary":"

Validates that the value is in the size array.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"size","doc":null,"default_value":"","external_name":"size","restriction":"Array(Int)"}],"args_string":"(value, size : Array(Int))","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/comparisons.cr#L117","def":{"name":"size?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"size","doc":null,"default_value":"","external_name":"size","restriction":"Array(Int)"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"size.includes?(value.size)"}},{"id":"size?(value,size:Range)-class-method","html_id":"size?(value,size:Range)-class-method","name":"size?","doc":"Validates that the *value* is in the *size* range.\n- See also `#between?`.","summary":"

Validates that the value is in the size range.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"size","doc":null,"default_value":"","external_name":"size","restriction":"Range"}],"args_string":"(value, size : Range)","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/comparisons.cr#L111","def":{"name":"size?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"size","doc":null,"default_value":"","external_name":"size","restriction":"Range"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"size.includes?(value.size)"}},{"id":"size?(value,size:String)-class-method","html_id":"size?(value,size:String)-class-method","name":"size?","doc":"Validates that the *value* is equal to the *size*.","summary":"

Validates that the value is equal to the size.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"size","doc":null,"default_value":"","external_name":"size","restriction":"String"}],"args_string":"(value, size : String)","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/comparisons.cr#L105","def":{"name":"size?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"size","doc":null,"default_value":"","external_name":"size","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"value.size.to_s == size"}},{"id":"size?(value,size:Int)-class-method","html_id":"size?(value,size:Int)-class-method","name":"size?","doc":"Validates that the *value* is equal to the *size*.","summary":"

Validates that the value is equal to the size.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"size","doc":null,"default_value":"","external_name":"size","restriction":"Int"}],"args_string":"(value, size : Int)","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/comparisons.cr#L100","def":{"name":"size?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"size","doc":null,"default_value":"","external_name":"size","restriction":"Int"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"value.size == size"}},{"id":"slug?(value:String,min=1,max=100):Bool-class-method","html_id":"slug?(value:String,min=1,max=100):Bool-class-method","name":"slug?","doc":"Validates that the *value* is a slug.","summary":"

Validates that the value is a slug.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"min","doc":null,"default_value":"1","external_name":"min","restriction":""},{"name":"max","doc":null,"default_value":"100","external_name":"max","restriction":""}],"args_string":"(value : String, min = 1, max = 100) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/uri.cr#L171","def":{"name":"slug?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"min","doc":null,"default_value":"1","external_name":"min","restriction":""},{"name":"max","doc":null,"default_value":"100","external_name":"max","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!value.match(/^([a-zA-Z0-9_-]{#{min},#{max}})$/).nil?"}},{"id":"starts?(value:String,search:Char):Bool-class-method","html_id":"starts?(value:String,search:Char):Bool-class-method","name":"starts?","doc":"Validates that the `String` *value* starts with *search*.\n- See also `#ends?`.\n- See also `#match?`.\n- See also `#in?`.","summary":"

Validates that the 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","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/presence.cr#L226","def":{"name":"starts?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"search","doc":null,"default_value":"","external_name":"search","restriction":"Char"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value.starts_with?(search)"}},{"id":"starts?(value:String,search:Regex):Bool-class-method","html_id":"starts?(value:String,search:Regex):Bool-class-method","name":"starts?","doc":"Validates that the `String` *value* starts with *search*.\n- See also `#ends?`.\n- See also `#match?`.\n- See also `#in?`.","summary":"

Validates that the 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","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/presence.cr#L231","def":{"name":"starts?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"search","doc":null,"default_value":"","external_name":"search","restriction":"Regex"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value.starts_with?(search)"}},{"id":"starts?(value:String,search:String):Bool-class-method","html_id":"starts?(value:String,search:String):Bool-class-method","name":"starts?","doc":"Validates that the `String` *value* starts with *search*.\n- See also `#ends?`.\n- See also `#match?`.\n- See also `#in?`.","summary":"

Validates that the 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","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/presence.cr#L221","def":{"name":"starts?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"search","doc":null,"default_value":"","external_name":"search","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value.starts_with?(search)"}},{"id":"time?(value:String):Bool-class-method","html_id":"time?(value:String):Bool-class-method","name":"time?","doc":"Validates that the *value* is a time `String` representation.","summary":"

Validates that the value is a time String representation.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/format.cr#L31","def":{"name":"time?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"(!value.blank?) && (!value.match(@@rx_time).nil?)"}},{"id":"upper?(value:String):Bool-class-method","html_id":"upper?(value:String):Bool-class-method","name":"upper?","doc":"Validates that the *value* is in upper case.","summary":"

Validates that the value is in upper case.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/case_sensitive.cr#L15","def":{"name":"upper?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"(!value.blank?) && (value.upcase === value)"}},{"id":"url?(value:String):Bool-class-method","html_id":"url?(value:String):Bool-class-method","name":"url?","doc":"Validates that the *value* is a URL.","summary":"

Validates that the value is a URL.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/uri.cr#L52","def":{"name":"url?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"size = value.size\nif ((size >= 2083 || size < 11) || (value.match(/[\\s<>]/))) || (value.starts_with?(\"mailto:\"))\n return false\nend\nif m = value.match(@@rx_url)\nelse\n return false\nend\nif self.domain?(\"#{m[\"name\"]}.#{m[\"ext\"]}\")\nelse\n return false\nend\nsp = (value.gsub(/^http(?:s)?:\\/\\//, \"\")).split(\":\")\nif sp.size > 1\n if m_port = sp[1].match(/^[0-9]+/)\n else\n return true\n end\n return self.port?(m_port[0])\nend\ntrue\n"}},{"id":"uuid?(value:String,version=0):Bool-class-method","html_id":"uuid?(value:String,version=0):Bool-class-method","name":"uuid?","doc":"Validates that the *value* is a *UUID*\nVersions: 0 (all), 3, 4 and 5. *version* by default is 0 (all).","summary":"

Validates that the value is a UUID Versions: 0 (all), 3, 4 and 5.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"version","doc":null,"default_value":"0","external_name":"version","restriction":""}],"args_string":"(value : String, version = 0) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/format.cr#L103","def":{"name":"uuid?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"version","doc":null,"default_value":"0","external_name":"version","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"if @@rx_uuid.has_key?(version)\nelse\n return false\nend\n!value.match(@@rx_uuid[version]).nil?\n"}}],"constructors":[],"instance_methods":[],"macros":[],"types":[{"html_id":"validator/Validator/Error","path":"Validator/Error.html","kind":"class","full_name":"Validator::Error","name":"Error","abstract":false,"superclass":{"html_id":"validator/Exception","kind":"class","full_name":"Exception","name":"Exception"},"ancestors":[{"html_id":"validator/Exception","kind":"class","full_name":"Exception","name":"Exception"},{"html_id":"validator/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"validator/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"src/validator.cr","line_number":120,"url":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validator.cr#L120"}],"repository_name":"validator","program":false,"enum":false,"alias":false,"aliased":"","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"validator/Validator","kind":"module","full_name":"Validator","name":"Validator"},"doc":"Used by `is!` when a validation is not `true`.","summary":"

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/js/doc.js b/docs/js/doc.js new file mode 100644 index 0000000..cdf43da --- /dev/null +++ b/docs/js/doc.js @@ -0,0 +1,1086 @@ +window.CrystalDocs = (window.CrystalDocs || {}); + +CrystalDocs.base_path = (CrystalDocs.base_path || ""); + +CrystalDocs.searchIndex = (CrystalDocs.searchIndex || false); +CrystalDocs.MAX_RESULTS_DISPLAY = 140; + +CrystalDocs.runQuery = function(query) { + function searchType(type, query, results) { + var matches = []; + var matchedFields = []; + var name = type.full_name; + var i = name.lastIndexOf("::"); + if (i > 0) { + name = name.substring(i + 2); + } + var nameMatches = query.matches(name); + if (nameMatches){ + matches = matches.concat(nameMatches); + matchedFields.push("name"); + } + + var namespaceMatches = query.matchesNamespace(type.full_name); + if(namespaceMatches){ + matches = matches.concat(namespaceMatches); + matchedFields.push("name"); + } + + var docMatches = query.matches(type.doc); + if(docMatches){ + matches = matches.concat(docMatches); + matchedFields.push("doc"); + } + if (matches.length > 0) { + results.push({ + id: type.id, + result_type: "type", + kind: type.kind, + name: name, + full_name: type.full_name, + href: type.path, + summary: type.summary, + matched_fields: matchedFields, + matched_terms: matches + }); + } + + type.instance_methods.forEach(function(method) { + searchMethod(method, type, "instance_method", query, results); + }) + type.class_methods.forEach(function(method) { + searchMethod(method, type, "class_method", query, results); + }) + type.constructors.forEach(function(constructor) { + searchMethod(constructor, type, "constructor", query, results); + }) + type.macros.forEach(function(macro) { + searchMethod(macro, type, "macro", query, results); + }) + type.constants.forEach(function(constant){ + searchConstant(constant, type, query, results); + }); + + type.types.forEach(function(subtype){ + searchType(subtype, query, results); + }); + }; + + function searchMethod(method, type, kind, query, results) { + var matches = []; + var matchedFields = []; + var nameMatches = query.matchesMethod(method.name, kind, type); + if (nameMatches){ + matches = matches.concat(nameMatches); + matchedFields.push("name"); + } + + method.args.forEach(function(arg){ + var argMatches = query.matches(arg.external_name); + if (argMatches) { + matches = matches.concat(argMatches); + matchedFields.push("args"); + } + }); + + var docMatches = query.matches(type.doc); + if(docMatches){ + matches = matches.concat(docMatches); + matchedFields.push("doc"); + } + + if (matches.length > 0) { + var typeMatches = query.matches(type.full_name); + if (typeMatches) { + matchedFields.push("type"); + matches = matches.concat(typeMatches); + } + results.push({ + id: method.id, + type: type.full_name, + result_type: kind, + name: method.name, + full_name: type.full_name + "#" + method.name, + args_string: method.args_string, + summary: method.summary, + href: type.path + "#" + method.id, + matched_fields: matchedFields, + matched_terms: matches + }); + } + } + + function searchConstant(constant, type, query, results) { + var matches = []; + var matchedFields = []; + var nameMatches = query.matches(constant.name); + if (nameMatches){ + matches = matches.concat(nameMatches); + matchedFields.push("name"); + } + var docMatches = query.matches(constant.doc); + if(docMatches){ + matches = matches.concat(docMatches); + matchedFields.push("doc"); + } + if (matches.length > 0) { + var typeMatches = query.matches(type.full_name); + if (typeMatches) { + matchedFields.push("type"); + matches = matches.concat(typeMatches); + } + results.push({ + id: constant.id, + type: type.full_name, + result_type: "constant", + name: constant.name, + full_name: type.full_name + "#" + constant.name, + value: constant.value, + summary: constant.summary, + href: type.path + "#" + constant.id, + matched_fields: matchedFields, + matched_terms: matches + }); + } + } + + var results = []; + searchType(CrystalDocs.searchIndex.program, query, results); + return results; +}; + +CrystalDocs.rankResults = function(results, query) { + function uniqueArray(ar) { + var j = {}; + + ar.forEach(function(v) { + j[v + "::" + typeof v] = v; + }); + + return Object.keys(j).map(function(v) { + return j[v]; + }); + } + + results = results.sort(function(a, b) { + var matchedTermsDiff = uniqueArray(b.matched_terms).length - uniqueArray(a.matched_terms).length; + var aHasDocs = b.matched_fields.includes("doc"); + var bHasDocs = b.matched_fields.includes("doc"); + + var aOnlyDocs = aHasDocs && a.matched_fields.length == 1; + var bOnlyDocs = bHasDocs && b.matched_fields.length == 1; + + if (a.result_type == "type" && b.result_type != "type" && !aOnlyDocs) { + if(CrystalDocs.DEBUG) { console.log("a is type b not"); } + return -1; + } else if (b.result_type == "type" && a.result_type != "type" && !bOnlyDocs) { + if(CrystalDocs.DEBUG) { console.log("b is type, a not"); } + return 1; + } + if (a.matched_fields.includes("name")) { + if (b.matched_fields.includes("name")) { + var a_name = (CrystalDocs.prefixForType(a.result_type) || "") + ((a.result_type == "type") ? a.full_name : a.name); + var b_name = (CrystalDocs.prefixForType(b.result_type) || "") + ((b.result_type == "type") ? b.full_name : b.name); + a_name = a_name.toLowerCase(); + b_name = b_name.toLowerCase(); + for(var i = 0; i < query.normalizedTerms.length; i++) { + var term = query.terms[i].replace(/^::?|::?$/, ""); + var a_orig_index = a_name.indexOf(term); + var b_orig_index = b_name.indexOf(term); + if(CrystalDocs.DEBUG) { console.log("term: " + term + " a: " + a_name + " b: " + b_name); } + if(CrystalDocs.DEBUG) { console.log(a_orig_index, b_orig_index, a_orig_index - b_orig_index); } + if (a_orig_index >= 0) { + if (b_orig_index >= 0) { + if(CrystalDocs.DEBUG) { console.log("both have exact match", a_orig_index > b_orig_index ? -1 : 1); } + if(a_orig_index != b_orig_index) { + if(CrystalDocs.DEBUG) { console.log("both have exact match at different positions", a_orig_index > b_orig_index ? 1 : -1); } + return a_orig_index > b_orig_index ? 1 : -1; + } + } else { + if(CrystalDocs.DEBUG) { console.log("a has exact match, b not"); } + return -1; + } + } else if (b_orig_index >= 0) { + if(CrystalDocs.DEBUG) { console.log("b has exact match, a not"); } + return 1; + } + } + } else { + if(CrystalDocs.DEBUG) { console.log("a has match in name, b not"); } + return -1; + } + } else if ( + !a.matched_fields.includes("name") && + b.matched_fields.includes("name") + ) { + return 1; + } + + if (matchedTermsDiff != 0 || (aHasDocs != bHasDocs)) { + if(CrystalDocs.DEBUG) { console.log("matchedTermsDiff: " + matchedTermsDiff, aHasDocs, bHasDocs); } + return matchedTermsDiff; + } + + var matchedFieldsDiff = b.matched_fields.length - a.matched_fields.length; + if (matchedFieldsDiff != 0) { + if(CrystalDocs.DEBUG) { console.log("matched to different number of fields: " + matchedFieldsDiff); } + return matchedFieldsDiff > 0 ? 1 : -1; + } + + var nameCompare = a.name.localeCompare(b.name); + if(nameCompare != 0){ + if(CrystalDocs.DEBUG) { console.log("nameCompare resulted in: " + a.name + "<=>" + b.name + ": " + nameCompare); } + return nameCompare > 0 ? 1 : -1; + } + + if(a.matched_fields.includes("args") && b.matched_fields.includes("args")) { + for(var i = 0; i < query.terms.length; i++) { + var term = query.terms[i]; + var aIndex = a.args_string.indexOf(term); + var bIndex = b.args_string.indexOf(term); + if(CrystalDocs.DEBUG) { console.log("index of " + term + " in args_string: " + aIndex + " - " + bIndex); } + if(aIndex >= 0){ + if(bIndex >= 0){ + if(aIndex != bIndex){ + return aIndex > bIndex ? 1 : -1; + } + }else{ + return -1; + } + }else if(bIndex >= 0) { + return 1; + } + } + } + + return 0; + }); + + if (results.length > 1) { + // if we have more than two search terms, only include results with the most matches + var bestMatchedTerms = uniqueArray(results[0].matched_terms).length; + + results = results.filter(function(result) { + return uniqueArray(result.matched_terms).length + 1 >= bestMatchedTerms; + }); + } + return results; +}; + +CrystalDocs.prefixForType = function(type) { + switch (type) { + case "instance_method": + return "#"; + + case "class_method": + case "macro": + case "constructor": + return "."; + + default: + return false; + } +}; + +CrystalDocs.displaySearchResults = function(results, query) { + function sanitize(html){ + return html.replace(/<(?!\/?code)[^>]+>/g, ""); + } + + // limit results + if (results.length > CrystalDocs.MAX_RESULTS_DISPLAY) { + results = results.slice(0, CrystalDocs.MAX_RESULTS_DISPLAY); + } + + var $frag = document.createDocumentFragment(); + var $resultsElem = document.querySelector(".search-list"); + $resultsElem.innerHTML = ""; + + results.forEach(function(result, i) { + var url = CrystalDocs.base_path + result.href; + var type = false; + + var title = query.highlight(result.result_type == "type" ? result.full_name : result.name); + + var prefix = CrystalDocs.prefixForType(result.result_type); + if (prefix) { + title = "" + prefix + "" + title; + } + + title = "" + title + ""; + + if (result.args_string) { + title += + "" + query.highlight(result.args_string) + ""; + } + + $elem = document.createElement("li"); + $elem.className = "search-result search-result--" + result.result_type; + $elem.dataset.href = url; + $elem.setAttribute("title", result.full_name + " docs page"); + + var $title = document.createElement("div"); + $title.setAttribute("class", "search-result__title"); + var $titleLink = document.createElement("a"); + $titleLink.setAttribute("href", url); + + $titleLink.innerHTML = title; + $title.appendChild($titleLink); + $elem.appendChild($title); + $elem.addEventListener("click", function() { + $titleLink.click(); + }); + + if (result.result_type !== "type") { + var $type = document.createElement("div"); + $type.setAttribute("class", "search-result__type"); + $type.innerHTML = query.highlight(result.type); + $elem.appendChild($type); + } + + if(result.summary){ + var $doc = document.createElement("div"); + $doc.setAttribute("class", "search-result__doc"); + $doc.innerHTML = query.highlight(sanitize(result.summary)); + $elem.appendChild($doc); + } + + $elem.appendChild(document.createComment(JSON.stringify(result))); + $frag.appendChild($elem); + }); + + $resultsElem.appendChild($frag); + + CrystalDocs.toggleResultsList(true); +}; + +CrystalDocs.toggleResultsList = function(visible) { + if (visible) { + document.querySelector(".types-list").classList.add("hidden"); + document.querySelector(".search-results").classList.remove("hidden"); + } else { + document.querySelector(".types-list").classList.remove("hidden"); + document.querySelector(".search-results").classList.add("hidden"); + } +}; + +CrystalDocs.Query = function(string) { + this.original = string; + this.terms = string.split(/\s+/).filter(function(word) { + return CrystalDocs.Query.stripModifiers(word).length > 0; + }); + + var normalized = this.terms.map(CrystalDocs.Query.normalizeTerm); + this.normalizedTerms = normalized; + + function runMatcher(field, matcher) { + if (!field) { + return false; + } + var normalizedValue = CrystalDocs.Query.normalizeTerm(field); + + var matches = []; + normalized.forEach(function(term) { + if (matcher(normalizedValue, term)) { + matches.push(term); + } + }); + return matches.length > 0 ? matches : false; + } + + this.matches = function(field) { + return runMatcher(field, function(normalized, term) { + if (term[0] == "#" || term[0] == ".") { + return false; + } + return normalized.indexOf(term) >= 0; + }); + }; + + function namespaceMatcher(normalized, term){ + var i = term.indexOf(":"); + if(i >= 0){ + term = term.replace(/^::?|::?$/, ""); + var index = normalized.indexOf(term); + if((index == 0) || (index > 0 && normalized[index-1] == ":")){ + return true; + } + } + return false; + } + this.matchesMethod = function(name, kind, type) { + return runMatcher(name, function(normalized, term) { + var i = term.indexOf("#"); + if(i >= 0){ + if (kind != "instance_method") { + return false; + } + }else{ + i = term.indexOf("."); + if(i >= 0){ + if (kind != "class_method" && kind != "macro" && kind != "constructor") { + return false; + } + }else{ + //neither # nor . + if(term.indexOf(":") && namespaceMatcher(normalized, term)){ + return true; + } + } + } + + var methodName = term; + if(i >= 0){ + var termType = term.substring(0, i); + methodName = term.substring(i+1); + + if(termType != "") { + if(CrystalDocs.Query.normalizeTerm(type.full_name).indexOf(termType) < 0){ + return false; + } + } + } + return normalized.indexOf(methodName) >= 0; + }); + }; + + this.matchesNamespace = function(namespace){ + return runMatcher(namespace, namespaceMatcher); + }; + + this.highlight = function(string) { + if (typeof string == "undefined") { + return ""; + } + function escapeRegExp(s) { + return s.replace(/[.*+?\^${}()|\[\]\\]/g, "\\$&").replace(/^[#\.:]+/, ""); + } + return string.replace( + new RegExp("(" + this.normalizedTerms.map(escapeRegExp).join("|") + ")", "gi"), + "$1" + ); + }; +}; +CrystalDocs.Query.normalizeTerm = function(term) { + return term.toLowerCase(); +}; +CrystalDocs.Query.stripModifiers = function(term) { + switch (term[0]) { + case "#": + case ".": + case ":": + return term.substr(1); + + default: + return term; + } +} + +CrystalDocs.search = function(string) { + if(!CrystalDocs.searchIndex) { + console.log("CrystalDocs search index not initialized, delaying search"); + + document.addEventListener("CrystalDocs:loaded", function listener(){ + document.removeEventListener("CrystalDocs:loaded", listener); + CrystalDocs.search(string); + }); + return; + } + + document.dispatchEvent(new Event("CrystalDocs:searchStarted")); + + var query = new CrystalDocs.Query(string); + var results = CrystalDocs.runQuery(query); + results = CrystalDocs.rankResults(results, query); + CrystalDocs.displaySearchResults(results, query); + + document.dispatchEvent(new Event("CrystalDocs:searchPerformed")); +}; + +CrystalDocs.initializeIndex = function(data) { + CrystalDocs.searchIndex = data; + + document.dispatchEvent(new Event("CrystalDocs:loaded")); +}; + +CrystalDocs.loadIndex = function() { + function loadJSON(file, callback) { + var xobj = new XMLHttpRequest(); + xobj.overrideMimeType("application/json"); + xobj.open("GET", file, true); + xobj.onreadystatechange = function() { + if (xobj.readyState == 4 && xobj.status == "200") { + callback(xobj.responseText); + } + }; + xobj.send(null); + } + + function loadScript(file) { + script = document.createElement("script"); + script.src = file; + document.body.appendChild(script); + } + + function parseJSON(json) { + CrystalDocs.initializeIndex(JSON.parse(json)); + } + + for(var i = 0; i < document.scripts.length; i++){ + var script = document.scripts[i]; + if (script.src && script.src.indexOf("js/doc.js") >= 0) { + if (script.src.indexOf("file://") == 0) { + // We need to support JSONP files for the search to work on local file system. + var jsonPath = script.src.replace("js/doc.js", "search-index.js"); + loadScript(jsonPath); + return; + } else { + var jsonPath = script.src.replace("js/doc.js", "index.json"); + loadJSON(jsonPath, parseJSON); + return; + } + } + } + console.error("Could not find location of js/doc.js"); +}; + +// Callback for jsonp +function crystal_doc_search_index_callback(data) { + CrystalDocs.initializeIndex(data); +} + +Navigator = function(sidebar, searchInput, list, leaveSearchScope){ + this.list = list; + var self = this; + + var performingSearch = false; + + document.addEventListener('CrystalDocs:searchStarted', function(){ + performingSearch = true; + }); + document.addEventListener('CrystalDocs:searchDebounceStarted', function(){ + performingSearch = true; + }); + document.addEventListener('CrystalDocs:searchPerformed', function(){ + performingSearch = false; + }); + document.addEventListener('CrystalDocs:searchDebounceStopped', function(event){ + performingSearch = false; + }); + + function delayWhileSearching(callback) { + if(performingSearch){ + document.addEventListener('CrystalDocs:searchPerformed', function listener(){ + document.removeEventListener('CrystalDocs:searchPerformed', listener); + + // add some delay to let search results display kick in + setTimeout(callback, 100); + }); + }else{ + callback(); + } + } + + function clearMoveTimeout() { + clearTimeout(self.moveTimeout); + self.moveTimeout = null; + } + + function startMoveTimeout(upwards){ + /*if(self.moveTimeout) { + clearMoveTimeout(); + } + + var go = function() { + if (!self.moveTimeout) return; + self.move(upwards); + self.moveTimout = setTimeout(go, 600); + }; + self.moveTimeout = setTimeout(go, 800);*/ + } + + function scrollCenter(element) { + var rect = element.getBoundingClientRect(); + var middle = sidebar.clientHeight / 2; + sidebar.scrollTop += rect.top + rect.height / 2 - middle; + } + + var move = this.move = function(upwards){ + if(!this.current){ + this.highlightFirst(); + return true; + } + var next = upwards ? this.current.previousElementSibling : this.current.nextElementSibling; + if(next && next.classList) { + this.highlight(next); + scrollCenter(next); + return true; + } + return false; + }; + + this.moveRight = function(){ + }; + this.moveLeft = function(){ + }; + + this.highlight = function(elem) { + if(!elem){ + return; + } + this.removeHighlight(); + + this.current = elem; + this.current.classList.add("current"); + }; + + this.highlightFirst = function(){ + this.highlight(this.list.querySelector('li:first-child')); + }; + + this.removeHighlight = function() { + if(this.current){ + this.current.classList.remove("current"); + } + this.current = null; + } + + this.openSelectedResult = function() { + if(this.current) { + this.current.click(); + } + } + + this.focus = function() { + searchInput.focus(); + searchInput.select(); + this.highlightFirst(); + } + + function handleKeyUp(event) { + switch(event.key) { + case "ArrowUp": + case "ArrowDown": + case "i": + case "j": + case "k": + case "l": + case "c": + case "h": + case "t": + case "n": + event.stopPropagation(); + clearMoveTimeout(); + } + } + + function handleKeyDown(event) { + switch(event.key) { + case "Enter": + event.stopPropagation(); + event.preventDefault(); + leaveSearchScope(); + self.openSelectedResult(); + break; + case "Escape": + event.stopPropagation(); + event.preventDefault(); + leaveSearchScope(); + break; + case "j": + case "c": + case "ArrowUp": + if(event.ctrlKey || event.key == "ArrowUp") { + event.stopPropagation(); + self.move(true); + startMoveTimeout(true); + } + break; + case "k": + case "h": + case "ArrowDown": + if(event.ctrlKey || event.key == "ArrowDown") { + event.stopPropagation(); + self.move(false); + startMoveTimeout(false); + } + break; + case "k": + case "t": + case "ArrowLeft": + if(event.ctrlKey || event.key == "ArrowLeft") { + event.stopPropagation(); + self.moveLeft(); + } + break; + case "l": + case "n": + case "ArrowRight": + if(event.ctrlKey || event.key == "ArrowRight") { + event.stopPropagation(); + self.moveRight(); + } + break; + } + } + + function handleInputKeyUp(event) { + switch(event.key) { + case "ArrowUp": + case "ArrowDown": + event.stopPropagation(); + event.preventDefault(); + clearMoveTimeout(); + } + } + + function handleInputKeyDown(event) { + switch(event.key) { + case "Enter": + event.stopPropagation(); + event.preventDefault(); + delayWhileSearching(function(){ + self.openSelectedResult(); + leaveSearchScope(); + }); + break; + case "Escape": + event.stopPropagation(); + event.preventDefault(); + // remove focus from search input + leaveSearchScope(); + sidebar.focus(); + break; + case "ArrowUp": + event.stopPropagation(); + event.preventDefault(); + self.move(true); + startMoveTimeout(true); + break; + + case "ArrowDown": + event.stopPropagation(); + event.preventDefault(); + self.move(false); + startMoveTimeout(false); + break; + } + } + + sidebar.tabIndex = 100; // set tabIndex to enable keylistener + sidebar.addEventListener('keyup', function(event) { + handleKeyUp(event); + }); + sidebar.addEventListener('keydown', function(event) { + handleKeyDown(event); + }); + searchInput.addEventListener('keydown', function(event) { + handleInputKeyDown(event); + }); + searchInput.addEventListener('keyup', function(event) { + handleInputKeyUp(event); + }); + this.move(); +}; + +CrystalDocs.initializeVersions = function () { + function loadJSON(file, callback) { + var xobj = new XMLHttpRequest(); + xobj.overrideMimeType("application/json"); + xobj.open("GET", file, true); + xobj.onreadystatechange = function() { + if (xobj.readyState == 4 && xobj.status == "200") { + callback(xobj.responseText); + } + }; + xobj.send(null); + } + + function parseJSON(json) { + CrystalDocs.loadConfig(JSON.parse(json)); + } + + $elem = document.querySelector("html > head > meta[name=\"crystal_docs.json_config_url\"]") + if ($elem == undefined) { + return + } + jsonURL = $elem.getAttribute("content") + if (jsonURL && jsonURL != "") { + loadJSON(jsonURL, parseJSON); + } +} + +CrystalDocs.loadConfig = function (config) { + var projectVersions = config["versions"] + var currentVersion = document.querySelector("html > head > meta[name=\"crystal_docs.project_version\"]").getAttribute("content") + + var currentVersionInList = projectVersions.find(function (element) { + return element.name == currentVersion + }) + + if (!currentVersionInList) { + projectVersions.unshift({ name: currentVersion, url: '#' }) + } + + $version = document.querySelector(".project-summary > .project-version") + $version.innerHTML = "" + + $select = document.createElement("select") + $select.classList.add("project-versions-nav") + $select.addEventListener("change", function () { + window.location.href = this.value + }) + projectVersions.forEach(function (version) { + $item = document.createElement("option") + $item.setAttribute("value", version.url) + $item.append(document.createTextNode(version.name)) + + if (version.name == currentVersion) { + $item.setAttribute("selected", true) + $item.setAttribute("disabled", true) + } + $select.append($item) + }); + $form = document.createElement("form") + $form.setAttribute("autocomplete", "off") + $form.append($select) + $version.append($form) +} + +document.addEventListener("DOMContentLoaded", function () { + CrystalDocs.initializeVersions() +}) + +var UsageModal = function(title, content) { + var $body = document.body; + var self = this; + var $modalBackground = document.createElement("div"); + $modalBackground.classList.add("modal-background"); + var $usageModal = document.createElement("div"); + $usageModal.classList.add("usage-modal"); + $modalBackground.appendChild($usageModal); + var $title = document.createElement("h3"); + $title.classList.add("modal-title"); + $title.innerHTML = title + $usageModal.appendChild($title); + var $closeButton = document.createElement("span"); + $closeButton.classList.add("close-button"); + $closeButton.setAttribute("title", "Close modal"); + $closeButton.innerText = '×'; + $usageModal.appendChild($closeButton); + $usageModal.insertAdjacentHTML("beforeend", content); + + $modalBackground.addEventListener('click', function(event) { + var element = event.target || event.srcElement; + + if(element == $modalBackground) { + self.hide(); + } + }); + $closeButton.addEventListener('click', function(event) { + self.hide(); + }); + + $body.insertAdjacentElement('beforeend', $modalBackground); + + this.show = function(){ + $body.classList.add("js-modal-visible"); + }; + this.hide = function(){ + $body.classList.remove("js-modal-visible"); + }; + this.isVisible = function(){ + return $body.classList.contains("js-modal-visible"); + } +} + + +document.addEventListener('DOMContentLoaded', function() { + var sessionStorage; + try { + sessionStorage = window.sessionStorage; + } catch (e) { } + if(!sessionStorage) { + sessionStorage = { + setItem: function() {}, + getItem: function() {}, + removeItem: function() {} + }; + } + + var repositoryName = document.querySelector('#repository-name').getAttribute('content'); + var typesList = document.querySelector('.types-list'); + var searchInput = document.querySelector('.search-input'); + var parents = document.querySelectorAll('.types-list li.parent'); + + var scrollSidebarToOpenType = function(){ + var openTypes = typesList.querySelectorAll('.current'); + if (openTypes.length > 0) { + var lastOpenType = openTypes[openTypes.length - 1]; + lastOpenType.scrollIntoView(); + } + } + + scrollSidebarToOpenType(); + + var setPersistentSearchQuery = function(value){ + sessionStorage.setItem(repositoryName + '::search-input:value', value); + } + + for(var i = 0; i < parents.length; i++) { + var _parent = parents[i]; + _parent.addEventListener('click', function(e) { + e.stopPropagation(); + + if(e.target.tagName.toLowerCase() == 'li') { + if(e.target.className.match(/open/)) { + sessionStorage.removeItem(e.target.getAttribute('data-id')); + e.target.className = e.target.className.replace(/ +open/g, ''); + } else { + sessionStorage.setItem(e.target.getAttribute('data-id'), '1'); + if(e.target.className.indexOf('open') == -1) { + e.target.className += ' open'; + } + } + } + }); + + if(sessionStorage.getItem(_parent.getAttribute('data-id')) == '1') { + _parent.className += ' open'; + } + } + + var leaveSearchScope = function(){ + CrystalDocs.toggleResultsList(false); + window.focus(); + } + + var navigator = new Navigator(document.querySelector('.types-list'), searchInput, document.querySelector(".search-results"), leaveSearchScope); + + CrystalDocs.loadIndex(); + var searchTimeout; + var lastSearchText = false; + var performSearch = function() { + document.dispatchEvent(new Event("CrystalDocs:searchDebounceStarted")); + + clearTimeout(searchTimeout); + searchTimeout = setTimeout(function() { + var text = searchInput.value; + + if(text == "") { + CrystalDocs.toggleResultsList(false); + }else if(text == lastSearchText){ + document.dispatchEvent(new Event("CrystalDocs:searchDebounceStopped")); + }else{ + CrystalDocs.search(text); + navigator.highlightFirst(); + searchInput.focus(); + } + lastSearchText = text; + setPersistentSearchQuery(text); + }, 200); + }; + + if(location.hash.length > 3 && location.hash.substring(0,3) == "#q="){ + // allows directly linking a search query which is then executed on the client + // this comes handy for establishing a custom browser search engine with https://crystal-lang.org/api/#q=%s as a search URL + // TODO: Add OpenSearch description + var searchQuery = location.hash.substring(3); + history.pushState({searchQuery: searchQuery}, "Search for " + searchQuery, location.href.replace(/#q=.*/, "")); + searchInput.value = searchQuery; + document.addEventListener('CrystalDocs:loaded', performSearch); + } + + if (searchInput.value.length == 0) { + var searchText = sessionStorage.getItem(repositoryName + '::search-input:value'); + if(searchText){ + searchInput.value = searchText; + } + } + searchInput.addEventListener('keyup', performSearch); + searchInput.addEventListener('input', performSearch); + + var usageModal = new UsageModal('Keyboard Shortcuts', '' + + '' + ); + + function handleShortkeys(event) { + var element = event.target || event.srcElement; + + if(element.tagName == "INPUT" || element.tagName == "TEXTAREA" || element.parentElement.tagName == "TEXTAREA"){ + return; + } + + switch(event.key) { + case "?": + usageModal.show(); + break; + + case "Escape": + usageModal.hide(); + break; + + case "s": + case "/": + if(usageModal.isVisible()) { + return; + } + event.stopPropagation(); + navigator.focus(); + performSearch(); + break; + } + } + + document.addEventListener('keyup', handleShortkeys); + + var scrollToEntryFromLocationHash = function() { + var hash = window.location.hash; + if (hash) { + var targetAnchor = decodeURI(hash.substr(1)); + var targetEl = document.getElementById(targetAnchor) + if (targetEl) { + targetEl.offsetParent.scrollTop = targetEl.offsetTop; + } + } + }; + window.addEventListener("hashchange", scrollToEntryFromLocationHash, false); + scrollToEntryFromLocationHash(); +}); diff --git a/docs/search-index.js b/docs/search-index.js new file mode 100644 index 0000000..ef8c4cc --- /dev/null +++ b/docs/search-index.js @@ -0,0 +1 @@ +crystal_doc_search_index_callback({"repository_name":"validator","body":"# validator\n\n[![Build Status](https://travis-ci.com/Nicolab/crystal-validator.svg?branch=master)](https://travis-ci.com/Nicolab/crystal-validator) [![GitHub release](https://img.shields.io/github/release/Nicolab/crystal-validator.svg)](https://github.com/Nicolab/crystal-validator/releases) [![Docs](https://img.shields.io/badge/docs-available-brightgreen.svg)](https://nicolab.github.io/crystal-validator/)\n\n∠(・.-)―〉 →◎ `validator` is a [Crystal](https://crystal-lang.org) data validation module.
\nVery simple and efficient, all validations return `true` or `false`.\n\nAlso [validator/check](#check) (not exposed by default) provides:\n\n* Error message handling intended for the end user.\n* Also (optional) a powerful and productive system of validation rules.\n With self-generated granular methods for cleaning and checking data.\n\n**Validator** respects the [KISS principle](https://en.wikipedia.org/wiki/KISS_principle) and the [Unix Philosophy](https://en.wikipedia.org/wiki/Unix_philosophy). It's a great basis tool for doing your own validation logic on top of it.\n\n## Installation\n\n1. Add the dependency to your `shard.yml`:\n\n```yaml\ndependencies:\n validator:\n github: nicolab/crystal-validator\n version: ~> 1.1.0 # Check the latest version!\n```\n\n2. Run `shards install`\n\n## Usage\n\n* [Validator - API docs](https://nicolab.github.io/crystal-validator/)\n\nThere are 3 main ways to use *validator*:\n\n* As a simple validator to check rules (eg: email, url, min, max, presence, in, ...) which return a boolean.\n* As a more advanced validation system which will check a series of rules and returns all validation errors encountered with custom or standard messages.\n* As a system of validation rules (inspired by the _Laravel framework's Validator_)\n which makes data cleaning and data validation in Crystal very easy!\n With self-generated granular methods for cleaning and checking data of each field.\n\nBy default the **validator** module expose only `Validator` and `Valid` (alias) in the scope:\n\n```crystal\nrequire \"validator\"\n\nValid.email? \"contact@example.org\" # => true\nValid.url? \"https://github.com/Nicolab/crystal-validator\" # => true\nValid.my_validator? \"value to validate\", \"hello\", 42 # => true\n```\n\nAn (optional) expressive validation flavor, `is` available as an alternative.\nNot exposed by default, it must be imported:\n\n```crystal\nrequire \"validator/is\"\n\nis :email?, \"contact@example.org\" # => true\nis :url?, \"https://github.com/Nicolab/crystal-validator\" # => true\nis :my_validator?, \"value to validate\", \"hello\", 42 # => true\n\n\n# raises an error if the email is not valid\nis! :email?, \"contact@@example..org\" # => Validator::Error\n```\n\n`is` is a macro, no overhead during the runtime 🚀\n By the nature of the macros, you can't pass the *validator* name dynamically with a variable like that `is(validator_name, \"my value to validate\", arg)`.\n But of course you can pass arguments with variables `is(:validator_name?, arg1, arg2)`.\n\n* [Validator - API docs](https://nicolab.github.io/crystal-validator/)\n\n### Validation rules\n\n```crystal\nrequire \"validator/check\"\n\nclass User\n # Mixin\n Check.checkable\n\n property email : String\n property age : Int32\n property bio : String?\n\n Check.rules(\n # required\n email: {\n required: true,\n\n # Checker (all validators are supported)\n check: {\n not_empty: {\"Email is required\"},\n email: {\"It is not a valid email\"},\n },\n\n # Cleaner\n clean: {\n # Data type\n type: String,\n\n # Converter (if union or other) to the expected value type.\n # Example if the input value is i32, but i64 is expected\n # Here is a String\n to: :to_s,\n\n # Formatter (any Crystal Proc)\n format: ->self.format_email(String),\n\n # Error message\n # Default is \"Wrong type\" but it can be customized\n message: \"Oops! Wrong type.\",\n },\n },\n\n # required\n age: {\n required: true,\n check: {\n min: {\"Age should be more than 18\", 18},\n between: {\"Age should be between 25 and 35\", 25, 35},\n },\n clean: {type: Int32, to: :to_i32, message: \"Unable to cast to Int32\"},\n },\n\n # nilable\n bio: {\n check: {\n between: {\"The user bio must be between 2 and 400 characters.\", 2, 400},\n },\n clean: {\n type: String,\n to: :to_s,\n # `nilable` means omited if not provided,\n # regardless of Crystal type (nilable or not)\n nilable: true\n },\n },\n )\n\n def initialize(@email, @age); end\n\n # ---------------------------------------------------------------------------\n # Lifecycle methods (hooks)\n # ---------------------------------------------------------------------------\n\n # Triggered on instance: `user.check`\n def before_check(v : Check::Validation, required : Bool, format : Bool)\n # Code...\n end\n\n # Triggered on instance: `user.check`\n def after_check(v : Check::Validation, required : Bool, format : Bool)\n # Code...\n end\n\n # Triggered on a static call: `User.check(h)` (with a `Hash` or `JSON::Any`)\n def self.before_check(v : Check::Validation, h, required : Bool, format : Bool)\n # Code...\n pp h\n end\n\n # Triggered on a static call: `User.check(h)` (with a `Hash` or `JSON::Any`)\n def self.after_check(v : Check::Validation, h, cleaned_h, required : Bool, format : Bool)\n # Code...\n pp cleaned_h\n cleaned_h # <= returns cleaned_h!\n end\n\n # --------------------------------------------------------------------------\n # Custom checkers\n # --------------------------------------------------------------------------\n\n # Triggered on instance: `user.check`\n @[Check::Checker]\n def custom_checker(v : Check::Validation, required : Bool, format : Bool)\n self.custom_checker_called = true\n end\n\n # Triggered on a static call: `User.check(h)` (with a `Hash` or `JSON::Any`)\n @[Check::Checker]\n def self.custom_checker(v : Check::Validation, h, cleaned_h, required : Bool, format : Bool)\n @@custom_checker_called = true\n cleaned_h # <= returns cleaned_h!\n end\n\n # --------------------------------------------------------------------------\n # Formatters\n # --------------------------------------------------------------------------\n\n # Format (convert) email.\n def self.format_email(email)\n puts \"mail stripped\"\n email.strip\n end\n\n # --------------------------------------------------------------------------\n # Normal methods\n # --------------------------------------------------------------------------\n\n def foo()\n # Code...\n end\n\n def self.bar(v)\n # Code...\n end\n\n # ...\n end\n```\n\n__Check__ with this example class (`User`):\n\n```crystal\n# Check a Hash (statically)\nv, user_h = User.check(input_h)\n\npp v # => Validation instance\npp v.valid?\npp v.errors\n\npp user_h # => Casted and cleaned Hash\n\n# Check a Hash (on instance)\nuser = user.new(\"demo@example.org\", 38)\n\nv = user.check # => Validation instance\npp v.valid?\npp v.errors\n\n# Check field\nv, email = User.check_email(value: \"demo@example.org\")\nv, age = User.check_age(value: 42)\n\nv, email = User.check_email(value: \"demo@example.org \", format: true)\nv, email = User.check_email(value: \"demo@example.org \", format: false)\n\n# Using an existing Validation instance\nv = Check.new_validation\nv, email = User.check_email(v, value: \"demo@example.org\")\n```\n\n__Clean__ with this example class (`User`):\n\n```crystal\n# `check` method cleans all values of the Hash (or JSON::Any),\n# before executing the validation rules\nv, user_h = User.check(input_h)\n\npp v # => Validation instance\npp v.valid?\npp v.errors\n\npp user_h # => Casted and cleaned Hash\n\n# Cast and clean field\nok, email = User.clean_email(value: \"demo@example.org\")\nok, age = User.clean_age(value: 42)\n\nok, email = User.clean_email(value: \"demo@example.org \", format: true)\nok, email = User.clean_email(value: \"demo@example.org \", format: false)\n\nputs \"${email} is casted and cleaned\" if ok\n# or\nputs \"Email type error\" unless ok\n```\n\n* `clean_*` methods are useful to caste a union value (like `Hash` or `JSON::Any`).\n* Also `clean_*` methods are optional and handy for formatting values, such as the strip on the email in the example `User` class.\n\nMore details about cleaning, casting, formatting and return values:\n\nBy default `format` is `true`, to disable:\n\n```crystal\nok, email = User.clean_email(value: \"demo@example.org\", format: false)\n# or\nok, email = User.clean_email(\"demo@example.org\", false)\n```\n\nAlways use named argument if there is only one (the `value`):\n\n```crystal\nok, email = User.clean_email(value: \"demo@example.org\")\n```\n\n`ok` is a boolean value that reports whether the cast succeeded. Like the type assertions in _Go_ (lang).\nBut the `ok` value is returned in first (like in _Elixir_ lang) for easy handling of multiple return values (`Tuple`).\n\nExample with multiple values returned:\n\n```crystal\nok, value1, value2 = User.clean_my_tuple({1, 2, 3})\n```\n\nConsidering the example class above (`User`).\nAs a reminder, the email field has been defined with the formatter below:\n\n```crystal\nCheck.rules(\n email: {\n clean: {\n type: String,\n to: :to_s,\n format: ->self.format_email(String), # <= Here!\n message: \"Wrong type\",\n },\n },\n)\n\n# ...\n\n# Format (convert) email.\ndef self.format_email(email)\n puts \"mail stripped\"\n email.strip\nend\n```\n\nSo `clean_email` cast to `String` and strip the value `\" demo@example.org \"`:\n\n```crystal\n# Email value with one space before and one space after\nok, email = User.clean_email(value: \" demo@example.org \")\n\nputs email # => \"demo@example.org\"\n```\n\nIf the email was taken from a union type (`json[\"email\"]?`), the returned `email` variable would be a `String` too.\n\nSee [more examples](https://github.com/Nicolab/crystal-validator/tree/master/examples).\n\n> NOTE: Require more explanations about `required`, `nilable` rules.\n> Also about the converters JSON / Crystal Hash: `h_from_json`, `to_json_h`, `to_crystal_h`.\n> In the meantime see the [API doc](https://nicolab.github.io/crystal-validator/Check/Checkable.html).\n\n### Validation#check\n\nTo perform a series of validations with error handling, the [validator/check](https://nicolab.github.io/crystal-validator/Check.html) module offers this possibility 👍\n\nA [Validation](https://nicolab.github.io/crystal-validator/Check/Validation.html) instance provides the means to write sequential checks, fine-tune each micro-validation with their own rules and custom error message, the possibility to retrieve all error messages, etc.\n\n> `Validation` is also used with `Check.rules` and `Check.checkable`\n that provide a powerful and productive system of validation rules\n which makes data cleaning and data validation in Crystal very easy.\n With self-generated granular methods for cleaning and checking data.\n\nTo use the checker (`check`) includes in the `Validation` class:\n\n```crystal\nrequire \"validator/check\"\n\n# Validates the *user* data received in the HTTP controller or other.\ndef validate_user(user : Hash) : Check::Validation\n v = Check.new_validation\n\n # -- email\n\n # Hash key can be a String or a Symbol\n v.check :email, \"The email is required.\", is :presence?, :email, user\n\n v.check \"email\", \"The email is required.\", is :presence?, \"email\", user\n v.check \"email\", \"#{user[\"email\"]} is an invalid email.\", is :email?, user[\"email\"]\n\n # -- username\n\n v.check \"username\", \"The username is required.\", is :presence?, \"username\", user\n\n v.check(\n \"username\",\n \"The username must contain at least 2 characters.\",\n is :min?, user[\"username\"], 2\n )\n\n v.check(\n \"username\",\n \"The username must contain a maximum of 20 characters.\",\n is :max?, user[\"username\"], 20\n )\nend\n\nv = validate_user user\n\npp v.valid? # => true (or false)\n\n# Inverse of v.valid?\nif v.errors.empty?\n return \"no error\"\nend\n\n# Print all the errors (if any)\npp v.errors\n\n# It's a Hash of Array\nerrors = v.errors\n\nputs errors.size\nputs errors.first_value\n\nerrors.each do |key, messages|\n puts key # => \"username\"\n puts messages # => [\"The username is required.\", \"etc...\"]\nend\n```\n\n3 methods [#check](https://nicolab.github.io/crystal-validator/Check/Validation.html#instance-method-summary):\n\n```crystal\n# check(key : Symbol | String, valid : Bool)\n# Using default error message\nv.check(\n \"username\",\n is(:min?, user[\"username\"], 2)\n)\n\n# check(key : Symbol | String, message : String, valid : Bool)\n# Using custom error message\nv.check(\n \"username\",\n \"The username must contain at least 2 characters.\",\n is(:min?, user[\"username\"], 2)\n)\n\n# check(key : Symbol | String, valid : Bool, message : String)\n# Using custom error message\nv.check(\n \"username\",\n is(:min?, user[\"username\"], 2),\n \"The username must contain at least 2 characters.\"\n)\n```\n\n`Check` is a simple and lightweight wrapper.\nThe `Check::Validation` is agnostic of the checked data,\nof the context (model, controller, CSV file, HTTP data, socket data, JSON, etc).\n\n> Use case example:\n Before saving to the database or process user data for a particular task,\n the custom error messages can be used for the end user response.\n\nBut a `Validation` instance can be used just to store validation errors:\n\n```crystal\nv = Check.new_validation\nv.add_error(\"foo\", \"foo error!\")\npp v.errors # => {\"foo\" => [\"foo error!\"]}\n```\n\n> See also `Check.rules` and `Check.checkable`.\n\nLet your imagination run wild to add your logic around it.\n\n### Custom validator\n\nJust add your own method to register a custom *validator* or to overload an existing *validator*.\n\n```crystal\nmodule Validator\n # My custom validator\n def self.my_validator?(value, arg : String, another_arg : Int32) : Bool\n # write here the logic of your validator...\n return true\n end\nend\n\n# Call it\nputs Valid.my_validator?(\"value to validate\", \"hello\", 42) # => true\n\n# or with the `is` flavor\nputs is :my_validator?, \"value to validate\", \"hello\", 42 # => true\n```\n\nUsing the custom validator with the validation rules:\n\n```crystal\nrequire \"validator/check\"\n\nclass Article\n # Mixin\n Check.checkable\n\n property title : String\n property content : String\n\n Check.rules(\n content: {\n # Now the custom validator is available\n check: {\n my_validator: {\"My validator error message\"},\n between: {\"The article content must be between 10 and 20 000 characters\", 10, 20_000},\n # ...\n },\n },\n )\nend\n\n# Triggered with all data\nv, article = Article.check(input_data)\n\n# Triggered with one value\nv, content = Article.check_content(input_data[\"content\"]?)\n```\n\n## Conventions\n\n* The word \"validator\" is the method to make a \"validation\" (value validation).\n* A *validator* returns `true` if the value (or/and the condition) is valid, `false` if not.\n* The first argument(s) is (are) the value(s) to be validated.\n* Always add the `Bool` return type to a *validator*.\n* Always add the suffix `?` to the method name of a *validator*.\n* If possible, indicates the type of the *validator* arguments.\n* Spec: Battle tested.\n* [KISS](https://en.wikipedia.org/wiki/KISS_principle) and [Unix Philosophy](https://en.wikipedia.org/wiki/Unix_philosophy).\n\n## Development\n\n```sh\ncrystal spec\ncrystal tool format\n```\n\n> TODO: add `ameba`?\n\n## Contributing\n\n1. Fork it ()\n2. Create your feature branch (`git checkout -b my-new-feature`)\n3. Commit your changes (`git commit -am 'Add some feature'`)\n4. Push to the branch (`git push origin my-new-feature`)\n5. Create a new Pull Request\n\n## LICENSE\n\n[MIT](https://github.com/Nicolab/crystal-validator/blob/master/LICENSE) (c) 2020, Nicolas Talle.\n\n## Author\n\n| [![Nicolas Tallefourtane - Nicolab.net](https://www.gravatar.com/avatar/d7dd0f4769f3aa48a3ecb308f0b457fc?s=64)](https://github.com/sponsors/Nicolab) |\n|---|\n| [Nicolas Talle](https://github.com/sponsors/Nicolab) |\n| [![Make a donation via Paypal](https://www.paypalobjects.com/en_US/i/btn/btn_donate_SM.gif)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=PGRH4ZXP36GUC) |\n\n> Thanks to [ilourt](https://github.com/ilourt) for his great work on `checkable` mixins (clean_*, check_*, ...).\n","program":{"html_id":"validator/toplevel","path":"toplevel.html","kind":"module","full_name":"Top Level Namespace","name":"Top Level Namespace","abstract":false,"superclass":null,"ancestors":[],"locations":[],"repository_name":"validator","program":true,"enum":false,"alias":false,"aliased":"","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":null,"doc":null,"summary":null,"class_methods":[],"constructors":[],"instance_methods":[],"macros":[{"id":"is(name,*args)-macro","html_id":"is(name,*args)-macro","name":"is","doc":"An (optional) expressive flavor of `Validator` (or `Valid` alias).\nNot exposed by default, must be imported:\n\n```\nrequire \"validator/is\"\n\nis :email?, \"contact@example.org\" # => true\nis \"email?\", \"contact@example.org\" # => true\nis :url?, \"https://github.com/Nicolab/crystal-validator\" # => true\n```","summary":"

An (optional) expressive flavor of Validator (or Valid alias).

","abstract":false,"args":[{"name":"name","doc":null,"default_value":"","external_name":"name","restriction":""},{"name":"args","doc":null,"default_value":"","external_name":"args","restriction":""}],"args_string":"(name, *args)","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/is.cr#L18","def":{"name":"is","args":[{"name":"name","doc":null,"default_value":"","external_name":"name","restriction":""},{"name":"args","doc":null,"default_value":"","external_name":"args","restriction":""}],"double_splat":null,"splat_index":1,"block_arg":null,"visibility":"Public","body":" \n# Symbol ? String\n\n Valid.\n{{ name.id }}\n \n{{ args.splat }}\n\n\n"}},{"id":"is!(name,*args)-macro","html_id":"is!(name,*args)-macro","name":"is!","doc":"Same as `is` but `raise` a `Validator::Error`\ndisplaying an inspection if the validation is `false`.\nUseful for the unit tests :)","summary":"

Same as is but raise a Validator::Error displaying an inspection if the validation is false.

","abstract":false,"args":[{"name":"name","doc":null,"default_value":"","external_name":"name","restriction":""},{"name":"args","doc":null,"default_value":"","external_name":"args","restriction":""}],"args_string":"(name, *args)","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/is.cr#L26","def":{"name":"is!","args":[{"name":"name","doc":null,"default_value":"","external_name":"name","restriction":""},{"name":"args","doc":null,"default_value":"","external_name":"args","restriction":""}],"double_splat":null,"splat_index":1,"block_arg":null,"visibility":"Public","body":" \n# Symbol ? String\n\n valid = Valid.\n{{ name.id }}\n \n{{ args.splat }}\n\n\n if valid == false\n raise Validator::Error.new \"Is not \\\"#{\n{{ name }}\n}\\\":\\n#{\n{{ args.stringify }}\n}\"\n \nend\n\n true\n\n"}}],"types":[{"html_id":"validator/Check","path":"Check.html","kind":"module","full_name":"Check","name":"Check","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/check.cr","line_number":11,"url":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/check.cr#L11"},{"filename":"src/checkable.cr","line_number":9,"url":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/checkable.cr#L9"}],"repository_name":"validator","program":false,"enum":false,"alias":false,"aliased":"","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":null,"doc":"Standalone check module that provides a practical workflow for validations.","summary":"

Standalone check module that provides a practical workflow for validations.

","class_methods":[{"id":"new_validation(errors:Errors)-class-method","html_id":"new_validation(errors:Errors)-class-method","name":"new_validation","doc":"Initializes a new `Validation` instance to combine\na series of checks (`Validation#check`).\nusing an existing *errors* `Hash` (`Check::Errors`).\n\n```\nv = Check.new_validation existing_errors\n```\n\nSame as:\n\n```\nv = Check::Validation.new existing_errors\n```\n\nExample to combine two hashes of validation errors:\n\n```\npreview_validation = Check.new_validation\nv = Check.new_validation preview_validation.errors\n```","summary":"

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)","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/check.cr#L359","def":{"name":"new_validation","args":[{"name":"errors","doc":null,"default_value":"","external_name":"errors","restriction":"Errors"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"Validation.new(errors)"}},{"id":"new_validation-class-method","html_id":"new_validation-class-method","name":"new_validation","doc":"Initializes a new `Validation` instance to combine\na series of checks (`Validation#check`).\n\n```\nv = Check.new_validation\n```\n\nSame as:\n\n```\nv = Check::Validation.new\n```","summary":"

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

","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/check.cr#L335","def":{"name":"new_validation","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"Validation.new"}}],"constructors":[],"instance_methods":[],"macros":[{"id":"checkable-macro","html_id":"checkable-macro","name":"checkable","doc":"A mixin to make a class checkable.\nThis mixin includes `Checkable` and `CheckableStatic`.\nIt must be used in conjonction with `Check.rules`.\n\n```\nrequire \"validator/check\"\n\nclass Article\n # Mixin\n Check.checkable\n\n property title : String\n property content : String\n\n Check.rules(\n content: {\n check: {\n not_empty: {\"Article content is required\"},\n between: {\"The article content must be between 10 and 20 000 characters\", 10, 20_000},\n # ...\n },\n clean: {\n type: String,\n to: :to_s,\n format: ->(content : String) { content.strip },\n message: \"Wrong type\",\n },\n },\n )\nend\n\n# Triggered on all data\nv, article = Article.check(input_data)\n\n# Triggered on a value\nv, content = Article.check_content(input_data[\"content\"]?)\n```","summary":"

A mixin to make a class checkable.

","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/checkable.cr#L67","def":{"name":"checkable","args":[],"double_splat":null,"splat_index":null,"block_arg":null,"visibility":"Public","body":" include Check::Checkable\n \nextend Check::CheckableStatic\n \n"}},{"id":"rules(**fields)-macro","html_id":"rules(**fields)-macro","name":"rules","doc":"Generates `check`, `check_{{field}}` and `clean_{{field}}` methods for *fields* (class variables).\n\n```\nrequire \"validator/check\"\n\nclass Article\n # Mixin\n Check.checkable\n\n property title : String\n property content : String\n property url : String?\n\n Check.rules(\n content: {\n required: true,\n check: {\n not_empty: {\"Article content is required\"},\n between: {\"The article content must be between 10 and 20 000 characters\", 10, 20_000},\n # ...\n },\n clean: {\n type: String,\n to: :to_s,\n format: ->(content : String) { content.strip },\n message: \"Wrong type\",\n },\n },\n url: {\n check: {\n url: {\"Article URL is invalid\"},\n },\n clean: {\n # `nilable` means omited if not provided,\n # regardless of Crystal type (nilable or not)\n nilable: true,\n # Crystal type\n type: String,\n # Converter to the expected typed value\n to: :to_s,\n },\n },\n # ...\n)\nend\n\n# Triggered on all data\nv, article = Article.check(input_data)\n\n# Triggered on all fields of an instance\narticle = Article.new(title: \"foo\", content: \"bar\")\nv = article.check\n\n# Triggered on a value\nv, content = Article.check_content(input_data[\"content\"]?)\n\n# Cast and clean a value\nok, content = Article.clean_content(input_data[\"content\"]?)\n```\n\nSee also `Check.checkable`.","summary":"

Generates check, check_{{field}} and clean_{{field}} methods for fields (class variables).

","abstract":false,"args":[],"args_string":"(**fields)","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/checkable.cr#L133","def":{"name":"rules","args":[],"double_splat":{"name":"fields","doc":null,"default_value":"","external_name":"fields","restriction":""},"splat_index":null,"block_arg":null,"visibility":"Public","body":" private def self.validation_rules\n \n{{ fields }}\n\n \nend\n\n private def self.validation_required?(field) : Bool\n fields = self.validation_rules\n return false if fields[field].nil?\n fields[field].fetch(\"required\", false).as(Bool)\n \nend\n\n private def self.validation_nilable?(field) : Bool\n fields = self.validation_rules\n return false if fields[field].nil? || fields[field][\"clean\"].nil?\n fields[field][\"clean\"].fetch(\"nilable\", false).as(Bool)\n \nend\n\n \n{% for field, rules in fields %}\n {% clean = rules[\"clean\"] %}\n {% check = rules[\"check\"] %}\n {% type = clean[\"type\"] %}\n {% nilable = clean[\"nilable\"] %}\n\n # Returns *{{ field }}* with the good type and formatted if *format* is `true`.\n # The return type is a tuple with a bool as a first argument indicating\n # that the clean has been processed successfully or not and the 2nd\n # argument is the *value* cleaned.\n #\n # ```\n # ok, email = Checkable.clean_email(user_input[\"email\"]) # => true, user@example.com\n # ```\n def self.clean_{{ field }}(value, format = true) : Tuple(Bool, {{ type }} | Nil)\n # force real Nil type (hack for JSON::Any and equivalent)\n value = nil if value == nil\n\n {% if to = clean[\"to\"] %}\n # Check if the *value* has the method `{{ to }}` and execute it if\n # exists to cast the value in the good type (except if the value is nil and nilable).\n if value.responds_to? {{ to }} {% if nilable %} && !value.nil?{% end %}\n begin\n value = value.{{ to.id }}\n rescue\n return false, nil\n end\n end\n {% end %}\n\n # Format if the value as the correct (Crystal) type.\n # `| Nil` allows to format in the case of a nilable value (example `String?`)\n # where the `type` option of `clean` rules has been defined on the precise\n # Crystal type (example `String`).\n if value.is_a? {{ type }} | Nil\n {% if format = clean[\"format\"] %}\n # If *format* is true then call it to format *value*.\n if format\n begin\n return true, {{ format }}.call(value)\n rescue\n return false, nil\n end\n else\n return true, value\n end\n {% else %}\n return true, value\n {% end %}\n end\n\n {false, nil}\n end\n\n # Create a new `Check::Validation` and checks *{{ field }}*.\n # For more infos check `.check_{{ field }}(v : Check::Validation, value, format : Bool = true)`\n def self.check_{{ field }}(\n *,\n value,\n required : Bool = true,\n format : Bool = true\n ) : Tuple(Check::Validation, {{ type }} | Nil)\n v = Check.new_validation\n self.check_{{ field }}(v, value, required, format)\n end\n\n # Cleans and check *value*.\n # If *format* is `true` it tells `.clean_{{ field }}` to execute the `format` function\n # for this field if it has been defined with `Check.rules`.\n def self.check_{{ field }}(\n v : Check::Validation,\n value,\n required : Bool = true,\n format : Bool = true\n ) : Tuple(Check::Validation, {{ type }} | Nil)\n # Cleans and formats the *value*\n ok, value = self.clean_{{ field }}(value, format)\n\n # If clean has encountered an error, add error message and stop check here.\n if ok == false\n {% msg = clean[\"message\"] || \"Wrong type\" %}\n v.add_error {{ field.stringify }}, {{ msg }} {% if nilable || (check[\"not_null\"].nil? && check[\"not_empty\"].nil?) %}unless value.nil?{% end %}\n return v, value\n end\n\n # Check against each rule provided.\n # Each rule is executed if *value* is not `nil` except for `not_null` and `not_empty`\n # which is executed even if the *value* is `nil`\n {% for name, args in check %}\n v.check(\n {{ field.stringify }},\n {{ args[0] }},\n {% if args.size <= 1 %}\n Valid.{{ name.id }}? value\n {% else %}\n Valid.{{ name.id }}? value, {{ args[1..-1].splat }}\n {% end %}\n ) {% if (nilable || (check[\"not_null\"].nil? && check[\"not_empty\"].nil?)) || ((name != \"not_null\") && (name != \"not_empty\")) %}unless value.nil?{% end %}\n {% end %}\n\n {v, value}\n end\n {% end %}\n\n \n"}}],"types":[{"html_id":"validator/Check/Checkable","path":"Check/Checkable.html","kind":"module","full_name":"Check::Checkable","name":"Checkable","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/checkable.cr","line_number":411,"url":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/checkable.cr#L411"}],"repository_name":"validator","program":false,"enum":false,"alias":false,"aliased":"","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"validator/Check","kind":"module","full_name":"Check","name":"Check"},"doc":"Mixin that adds `#check` method to be used with variables of an instance of the class including it.\nThe idea is to check the instance variables of the class extending it\nagainst rules defined with `Check.rules` plus executing custom checkers defined with `Checker`.","summary":"

Mixin that adds #check method to be used with variables of an instance of the class including it.

","class_methods":[],"constructors":[],"instance_methods":[{"id":"after_check(v:Check::Validation,required:Bool=true,format:Bool=true)-instance-method","html_id":"after_check(v:Check::Validation,required:Bool=true,format:Bool=true)-instance-method","name":"after_check","doc":"Lifecycle method triggered after each call of `#check`.\n\n```\n# Triggered on instance: `user.check`\ndef after_check(v : Check::Validation, required : Bool = true, format : Bool = true)\n # Code...\nend\n```","summary":"

Lifecycle method triggered after each call of #check.

","abstract":false,"args":[{"name":"v","doc":null,"default_value":"","external_name":"v","restriction":"Check::Validation"},{"name":"required","doc":null,"default_value":"true","external_name":"required","restriction":"Bool"},{"name":"format","doc":null,"default_value":"true","external_name":"format","restriction":"Bool"}],"args_string":"(v : Check::Validation, required : Bool = true, format : Bool = true)","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/checkable.cr#L434","def":{"name":"after_check","args":[{"name":"v","doc":null,"default_value":"","external_name":"v","restriction":"Check::Validation"},{"name":"required","doc":null,"default_value":"true","external_name":"required","restriction":"Bool"},{"name":"format","doc":null,"default_value":"true","external_name":"format","restriction":"Bool"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":""}},{"id":"before_check(v:Check::Validation,required:Bool=true,format:Bool=true)-instance-method","html_id":"before_check(v:Check::Validation,required:Bool=true,format:Bool=true)-instance-method","name":"before_check","doc":"Lifecycle method triggered before each call of `#check`.\n\n```\n# Triggered on instance: `user.check`\ndef before_check(v : Check::Validation, required : Bool = true, format : Bool = true)\n # Code...\nend\n```","summary":"

Lifecycle method triggered before each call of #check.

","abstract":false,"args":[{"name":"v","doc":null,"default_value":"","external_name":"v","restriction":"Check::Validation"},{"name":"required","doc":null,"default_value":"true","external_name":"required","restriction":"Bool"},{"name":"format","doc":null,"default_value":"true","external_name":"format","restriction":"Bool"}],"args_string":"(v : Check::Validation, required : Bool = true, format : Bool = true)","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/checkable.cr#L420","def":{"name":"before_check","args":[{"name":"v","doc":null,"default_value":"","external_name":"v","restriction":"Check::Validation"},{"name":"required","doc":null,"default_value":"true","external_name":"required","restriction":"Bool"},{"name":"format","doc":null,"default_value":"true","external_name":"format","restriction":"Bool"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":""}},{"id":"check(required:Bool=true,format:Bool=true):Validation-instance-method","html_id":"check(required:Bool=true,format:Bool=true):Validation-instance-method","name":"check","doc":"Checks the instance fields and clean them.\n\nIt instantiates a `Check::Validation` (if not provided) and calls all methods\nrelated to rules and then methods defined with annotation `Checker`.\n\nLifecycle methods `#before_check` and `#after_check` that are triggered\nrespectively at the beginning and at the end of the process.\n\n*format* is used to tell cleaners generated by `Check.rules`\nto execute format method if it has been defined.","summary":"

Checks the instance fields and clean them.

","abstract":false,"args":[{"name":"required","doc":null,"default_value":"true","external_name":"required","restriction":"Bool"},{"name":"format","doc":null,"default_value":"true","external_name":"format","restriction":"Bool"}],"args_string":"(required : Bool = true, format : Bool = true) : Validation","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/checkable.cr#L480","def":{"name":"check","args":[{"name":"required","doc":null,"default_value":"true","external_name":"required","restriction":"Bool"},{"name":"format","doc":null,"default_value":"true","external_name":"format","restriction":"Bool"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Validation","visibility":"Public","body":"v = Check.new_validation\ncheck(v, required, format)\n"}},{"id":"check(v:Check::Validation,required:Bool=true,format:Bool=true):Validation-instance-method","html_id":"check(v:Check::Validation,required:Bool=true,format:Bool=true):Validation-instance-method","name":"check","doc":"Checks the instance fields and clean them.\n\nIt instantiates a `Check::Validation` (if not provided) and calls all methods\nrelated to rules and then methods defined with annotation `Checker`.\n\nLifecycle methods `#before_check` and `#after_check` that are triggered\nrespectively at the beginning and at the end of the process.\n\n*format* is used to tell cleaners generated by `Check.rules`\nto execute format method if it has been defined.","summary":"

Checks the instance fields and clean them.

","abstract":false,"args":[{"name":"v","doc":null,"default_value":"","external_name":"v","restriction":"Check::Validation"},{"name":"required","doc":null,"default_value":"true","external_name":"required","restriction":"Bool"},{"name":"format","doc":null,"default_value":"true","external_name":"format","restriction":"Bool"}],"args_string":"(v : Check::Validation, required : Bool = true, format : Bool = true) : Validation","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/checkable.cr#L450","def":{"name":"check","args":[{"name":"v","doc":null,"default_value":"","external_name":"v","restriction":"Check::Validation"},{"name":"required","doc":null,"default_value":"true","external_name":"required","restriction":"Bool"},{"name":"format","doc":null,"default_value":"true","external_name":"format","restriction":"Bool"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Validation","visibility":"Public","body":"{% if true %}\n\n # Call lifecycle method before check\n before_check v, required, format\n\n # Check all fields that have a method `#check_{field}`\n {% for ivar in @type.instance_vars.select do |ivar|\n @type.class.has_method?(\"check_#{ivar}\")\nend %}\n v, value = self.class.check_{{ ivar.name }}(v, {{ ivar.name }}, required, format)\n\n # If the field is not nilable and the value is nil,\n # it means that the clean method has failed\n # (to cast or an exception has been raised (and catched) in the formatter)\n # So ignore the nil value if the field is not nilable\n @{{ ivar.name }} = value.as({{ ivar.type }}) {% if !ivar.type.nilable? %} unless value.nil? {% end %}\n {% end %}\n\n # Check methods with `Check::Checker` annotation\n {% for method in @type.methods.select do |method|\n method.annotation(Checker)\nend %}\n {{ method.name }} v, required, format\n {% end %}\n\n # Call lifecycle method `#after_check`\n after_check v, required, format\n\n v\n {% end %}"}}],"macros":[],"types":[]},{"html_id":"validator/Check/CheckableStatic","path":"Check/CheckableStatic.html","kind":"module","full_name":"Check::CheckableStatic","name":"CheckableStatic","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/checkable.cr","line_number":261,"url":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/checkable.cr#L261"}],"repository_name":"validator","program":false,"enum":false,"alias":false,"aliased":"","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"validator/Check","kind":"module","full_name":"Check","name":"Check"},"doc":"Mixin that adds `.check` method to be used with a `Hash`.\nThe idea is to check a `Hash` against rules defined with `Check.rules`\nplus executing custom checkers defined with `Checker` annotation.","summary":"

Mixin that adds .check method to be used with a Hash.

","class_methods":[],"constructors":[],"instance_methods":[{"id":"after_check(v:Check::Validation,h:Hash,cleaned_h:Hash,required:Bool=true,format:Bool=true):Hash-instance-method","html_id":"after_check(v:Check::Validation,h:Hash,cleaned_h:Hash,required:Bool=true,format:Bool=true):Hash-instance-method","name":"after_check","doc":"Lifecycle method triggered after each call of `.check`.\n\nThis method (in static call) must returns the cleaned `Hash`\nwhich is provided in the third argument.\nYou can update this cleaned hash but you have to return it.\n\n```\n# Triggered on a static call: `User.check(h)` (with a `Hash` or `JSON::Any`)\ndef self.after_check(v : Check::Validation, h, cleaned_h, required : Bool = true, format : Bool = true) : Hash\n # Code...\n pp cleaned_h\n cleaned_h # <= returns cleaned_h!\nend\n```","summary":"

Lifecycle method triggered after each call of .check.

","abstract":false,"args":[{"name":"v","doc":null,"default_value":"","external_name":"v","restriction":"Check::Validation"},{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"Hash"},{"name":"cleaned_h","doc":null,"default_value":"","external_name":"cleaned_h","restriction":"Hash"},{"name":"required","doc":null,"default_value":"true","external_name":"required","restriction":"Bool"},{"name":"format","doc":null,"default_value":"true","external_name":"format","restriction":"Bool"}],"args_string":"(v : Check::Validation, h : Hash, cleaned_h : Hash, required : Bool = true, format : Bool = true) : Hash","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/checkable.cr#L341","def":{"name":"after_check","args":[{"name":"v","doc":null,"default_value":"","external_name":"v","restriction":"Check::Validation"},{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"Hash"},{"name":"cleaned_h","doc":null,"default_value":"","external_name":"cleaned_h","restriction":"Hash"},{"name":"required","doc":null,"default_value":"true","external_name":"required","restriction":"Bool"},{"name":"format","doc":null,"default_value":"true","external_name":"format","restriction":"Bool"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Hash","visibility":"Public","body":"cleaned_h"}},{"id":"before_check(v:Check::Validation,h:Hash,required:Bool=true,format:Bool=true)-instance-method","html_id":"before_check(v:Check::Validation,h:Hash,required:Bool=true,format:Bool=true)-instance-method","name":"before_check","doc":"Lifecycle method triggered before each call of `.check`.\n\n```\n# Triggered on a static call: `User.check(h)` (with a `Hash` or `JSON::Any`)\ndef self.before_check(v : Check::Validation, h, required : Bool = true, format : Bool = true)\n # Code...\n pp h\nend\n```","summary":"

Lifecycle method triggered before each call of .check.

","abstract":false,"args":[{"name":"v","doc":null,"default_value":"","external_name":"v","restriction":"Check::Validation"},{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"Hash"},{"name":"required","doc":null,"default_value":"true","external_name":"required","restriction":"Bool"},{"name":"format","doc":null,"default_value":"true","external_name":"format","restriction":"Bool"}],"args_string":"(v : Check::Validation, h : Hash, required : Bool = true, format : Bool = true)","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/checkable.cr#L320","def":{"name":"before_check","args":[{"name":"v","doc":null,"default_value":"","external_name":"v","restriction":"Check::Validation"},{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"Hash"},{"name":"required","doc":null,"default_value":"true","external_name":"required","restriction":"Bool"},{"name":"format","doc":null,"default_value":"true","external_name":"format","restriction":"Bool"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":""}},{"id":"check(v:Check::Validation,h:Hash,required:Bool=true,format:Bool=true)-instance-method","html_id":"check(v:Check::Validation,h:Hash,required:Bool=true,format:Bool=true)-instance-method","name":"check","doc":"Checks and clean the `Hash` for its fields corresponding\nto class variables that have a `.check_{{field}}` method.\n\nIt instantiates a `Check::Validation` (if not provided) and calls all methods\nrelated to `.rules` and then methods defined with annotation `Checker`.\n\nLifecycle methods `.before_check` and `.after_check` that are called\nrespectively at the beginning and at the end of the process.\n\n*format* is used to tell cleaners generated by `Check.rules`\nto execute format method if it has been defined.","summary":"

Checks and clean the Hash for its fields corresponding to class variables that have a .check_{{field}} method.

","abstract":false,"args":[{"name":"v","doc":null,"default_value":"","external_name":"v","restriction":"Check::Validation"},{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"Hash"},{"name":"required","doc":null,"default_value":"true","external_name":"required","restriction":"Bool"},{"name":"format","doc":null,"default_value":"true","external_name":"format","restriction":"Bool"}],"args_string":"(v : Check::Validation, h : Hash, required : Bool = true, format : Bool = true)","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/checkable.cr#L361","def":{"name":"check","args":[{"name":"v","doc":null,"default_value":"","external_name":"v","restriction":"Check::Validation"},{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"Hash"},{"name":"required","doc":null,"default_value":"true","external_name":"required","restriction":"Bool"},{"name":"format","doc":null,"default_value":"true","external_name":"format","restriction":"Bool"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"{% if true %}\n {% types = [] of Type %}\n {% fields = [] of String %}\n\n {% for ivar in @type.instance_vars.select do |ivar|\n @type.class.has_method?(\"check_#{ivar}\")\nend %}\n {% types << ivar.type %}\n {% fields << ivar.name %}\n {% end %}\n\n # Instantiate a `Hash` with keys as `String` and values as a union of\n # all types of fields which have a method `.check_{field}`\n cleaned_h = Hash(String, {{ (types.join(\"|\")).id }}).new\n\n # Call lifecycle method before check\n self.before_check v, h, required, format\n\n # Call check methods for fields that are present in *h*\n # and populate `cleaned_h`\n {% for field, i in fields %}\n {% field_name = field.stringify %}\n # if hash has the field or this field MUST be checked when required is `true`\n if h.has_key?({{ field_name }}) || (required && self.validation_required?({{ field_name }}))\n v, value = self.check_{{ field }}(v, h[{{ field_name }}]?, required, format)\n cleaned_h[{{ field_name }}] = value.as({{ types[i] }})\n end\n {% end %}\n\n # Check methods with `Check::Checker` annotation\n {% for method in @type.class.methods.select do |method|\n method.annotation(Checker)\nend %}\n cleaned_h = {{ method.name }} v, h, cleaned_h, required, format\n {% end %}\n\n # Call lifecycle method `.after_check`\n cleaned_h = self.after_check v, h, cleaned_h, required, format\n\n {v, cleaned_h}\n {% end %}"}},{"id":"check(h:Hash,required:Bool=true,format:Bool=true)-instance-method","html_id":"check(h:Hash,required:Bool=true,format:Bool=true)-instance-method","name":"check","doc":"Checks and clean the `Hash` for its fields corresponding\nto class variables that have a `.check_{{field}}` method.\n\nIt instantiates a `Check::Validation` (if not provided) and calls all methods\nrelated to `.rules` and then methods defined with annotation `Checker`.\n\nLifecycle methods `.before_check` and `.after_check` that are called\nrespectively at the beginning and at the end of the process.\n\n*format* is used to tell cleaners generated by `Check.rules`\nto execute format method if it has been defined.","summary":"

Checks and clean the Hash for its fields corresponding to class variables that have a .check_{{field}} method.

","abstract":false,"args":[{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"Hash"},{"name":"required","doc":null,"default_value":"true","external_name":"required","restriction":"Bool"},{"name":"format","doc":null,"default_value":"true","external_name":"format","restriction":"Bool"}],"args_string":"(h : Hash, required : Bool = true, format : Bool = true)","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/checkable.cr#L402","def":{"name":"check","args":[{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"Hash"},{"name":"required","doc":null,"default_value":"true","external_name":"required","restriction":"Bool"},{"name":"format","doc":null,"default_value":"true","external_name":"format","restriction":"Bool"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"v = Check.new_validation\ncheck(v, h, required, format)\n"}},{"id":"h_from_json(json:String|IO)-instance-method","html_id":"h_from_json(json:String|IO)-instance-method","name":"h_from_json","doc":"Returns a `Hash` from a JSON input.\nThe return type is a tuple with a bool as a first argument indicating\nthat the `JSON.parse` has been processed successfully or not and the 2nd\nargument is the *json* Hash.\n\n```\nok, user_h = User.h_from_json(json) # => true, {\"username\" => \"Bob\", \"email\" => \"user@example.com\"}\n```","summary":"

Returns a Hash from a JSON input.

","abstract":false,"args":[{"name":"json","doc":null,"default_value":"","external_name":"json","restriction":"String | IO"}],"args_string":"(json : String | IO)","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/checkable.cr#L305","def":{"name":"h_from_json","args":[{"name":"json","doc":null,"default_value":"","external_name":"json","restriction":"String | IO"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"begin\n return {true, self.to_crystal_h((JSON.parse(json)).as_h)}\nrescue\n return {false, nil}\nend"}},{"id":"map_json_keys:Hash(String,String)-instance-method","html_id":"map_json_keys:Hash(String,String)-instance-method","name":"map_json_keys","doc":"Macro that returns the mapping of the JSON fields","summary":"

Macro that returns the mapping of the JSON fields

","abstract":false,"args":[],"args_string":" : Hash(String, String)","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/checkable.cr#L263","def":{"name":"map_json_keys","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Hash(String, String)","visibility":"Public","body":"map = {} of String => String\n{% if true %}\n {% for ivar in @type.instance_vars %}\n {% ann = ivar.annotation(::JSON::Field) %}\n {% if ann && ann[:ignore] %}{% else %}\n map[{{ ((ann && ann[:key]) || ivar).id.stringify }}] = {{ ivar.id.stringify }}\n {% end %}\n {% end %}\n {% end %}\nmap\n"}},{"id":"to_crystal_h(h:Hash):Hash-instance-method","html_id":"to_crystal_h(h:Hash):Hash-instance-method","name":"to_crystal_h","doc":"Returns a new `Hash` with all JSON keys converted to Crystal keys.","summary":"

Returns a new Hash with all JSON keys converted to Crystal keys.

","abstract":false,"args":[{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"Hash"}],"args_string":"(h : Hash) : Hash","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/checkable.cr#L278","def":{"name":"to_crystal_h","args":[{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"Hash"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Hash","visibility":"Public","body":"cr_keys = map_json_keys\nh.transform_keys do |cr_k|\n cr_keys[cr_k]? || cr_k\nend\n"}},{"id":"to_json_h(h:Hash):Hash-instance-method","html_id":"to_json_h(h:Hash):Hash-instance-method","name":"to_json_h","doc":"Returns a new `Hash` with all Crystal keys converted to JSON keys.","summary":"

Returns a new Hash with all Crystal keys converted to JSON keys.

","abstract":false,"args":[{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"Hash"}],"args_string":"(h : Hash) : Hash","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/checkable.cr#L288","def":{"name":"to_json_h","args":[{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"Hash"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Hash","visibility":"Public","body":"cr_keys = map_json_keys\nh.transform_keys do |json_k|\n cr_keys.key_for?(json_k || json_k)\nend\n"}}],"macros":[],"types":[]},{"html_id":"validator/Check/Checker","path":"Check/Checker.html","kind":"annotation","full_name":"Check::Checker","name":"Checker","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/checkable.cr","line_number":28,"url":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/checkable.cr#L28"}],"repository_name":"validator","program":false,"enum":false,"alias":false,"aliased":"","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"validator/Check","kind":"module","full_name":"Check","name":"Check"},"doc":"Declare a method as a checker.\n\n```\n# Triggered by the instance.\n@[Check::Checker]\ndef custom_checker(v : Check::Validation, required : Bool, format : Bool)\n puts \"custom checker triggered on instance\"\nend\n\n# Triggered statically.\n@[Check::Checker]\ndef self.custom_checker(v : Check::Validation, h, cleaned_h, required : Bool, format : Bool)\n puts \"custom checker triggered statically\"\n cleaned_h\nend\n```\n\nWhen `.check` and `#check` are called, the custom checkers are triggered respectively.","summary":"

Declare a method as a checker.

","class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[]},{"html_id":"validator/Check/Errors","path":"Check/Errors.html","kind":"alias","full_name":"Check::Errors","name":"Errors","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/check.cr","line_number":19,"url":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/check.cr#L19"}],"repository_name":"validator","program":false,"enum":false,"alias":true,"aliased":"Hash(String | Symbol, Array(String))","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"validator/Check","kind":"module","full_name":"Check","name":"Check"},"doc":"Validation errors.\nIt's a `Hash` used as a container of errors, in order to handle them easily.\n\n```\nv = Check.new_validation\npp v.errors\n```","summary":"

Validation errors.

","class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[]},{"html_id":"validator/Check/Validation","path":"Check/Validation.html","kind":"class","full_name":"Check::Validation","name":"Validation","abstract":false,"superclass":{"html_id":"validator/Reference","kind":"class","full_name":"Reference","name":"Reference"},"ancestors":[{"html_id":"validator/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"validator/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"src/check.cr","line_number":139,"url":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/check.cr#L139"}],"repository_name":"validator","program":false,"enum":false,"alias":false,"aliased":"","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"validator/Check","kind":"module","full_name":"Check","name":"Check"},"doc":"Combines a series of checks into one validation instance,\nwith a customized error message for each case.\n\nA `Validation` instance provides the means to write sequential checks,\nfine-tune each micro-validation with their own rules and custom error message,\nthe possibility to retrieve all error messages, etc.\n\n> `Validation` is also used with `Check.rules` and `Check.checkable`\nthat provide a powerful and productive system of validation rules\nwhich makes data cleaning and data validation in Crystal very easy.\nWith self-generated granular methods for cleaning and checking data.\n\n\nTo use the checker (`check`) includes in the `Validation` class:\n\n```\nrequire \"validator/check\"\n\n# Validates the *user* data received in the HTTP controller or other.\ndef validate_user(user : Hash) : Check::Validation\n v = Check.new_validation\n\n # -- email\n\n # Hash key can be a String or a Symbol\n v.check :email, \"The email is required.\", is :presence?, :email, user\n\n v.check \"email\", \"The email is required.\", is :presence?, \"email\", user\n v.check \"email\", \"#{user[\"email\"]} is an invalid email.\", is :email?, user[\"email\"]\n\n # -- username\n\n v.check \"username\", \"The username is required.\", is :presence?, \"username\", user\n\n v.check(\n \"username\",\n \"The username must contain at least 2 characters.\",\n is :min?, user[\"username\"], 2\n )\n\n v.check(\n \"username\",\n \"The username must contain a maximum of 20 characters.\",\n is :max?, user[\"username\"], 20\n )\nend\n\nv = validate_user user\n\npp v.valid? # => true (or false)\n\n# Inverse of v.valid?\nif v.errors.empty?\n return \"no error\"\nend\n\n# display all the errors (if any)\npp v.errors\n\n# It's a Hash of Array\nerrors = v.errors\n\nputs errors.size\nputs errors.first_value\n\nerrors.each do |key, messages|\n puts key # => \"username\"\n puts messages # => [\"The username is required.\", \"etc...\"]\nend\n```\n\n3 methods [#check](https://nicolab.github.io/crystal-validator/Check/Validation.html#instance-method-summary):\n\n```\n# check(key : Symbol | String, valid : Bool)\n# Using default standard error message\nv.check(\n \"username\",\n is(:min?, user[\"username\"], 2)\n)\n\n# check(key : Symbol | String, message : String, valid : Bool)\n# Using custom error message\nv.check(\n \"username\",\n \"The username must contain at least 2 characters.\",\n is(:min?, user[\"username\"], 2)\n)\n\n# check(key : Symbol | String, valid : Bool, message : String)\n# Using custom error message\nv.check(\n \"username\",\n is(:min?, user[\"username\"], 2),\n \"The username must contain at least 2 characters.\"\n)\n```\n\n`Check` is a simple and lightweight wrapper.\n`Check::Validation` is agnostic of the checked data,\nof the context (model, controller, CSV file, HTTP data, socket data, JSON, etc).\n\n> Use case example:\n Before saving to the database or process user data for a particular task,\n the custom error messages can be used for the end user response.\n\nBut a `Validation` instance can be used just to store validation errors:\n\n```\nv = Check.new_validation\nv.add_error(\"foo\", \"foo error!\")\npp v.errors # => {\"foo\" => [\"foo error!\"]}\n```\n\n> See also `Check.rules` and `Check.checkable`.\n\nLet your imagination run wild to add your logic around it.\n","summary":"

Combines a series of checks into one validation instance, with a customized error message for each case.

","class_methods":[],"constructors":[{"id":"new(errors:Errors)-class-method","html_id":"new(errors:Errors)-class-method","name":"new","doc":"Initializes a validation using an existing *errors* `Hash` (`Check::Errors`).\n\n```\nv = Check::Validation.new\n```\n\nSame as:\n\n```\nv = Check.new_validation\n```","summary":"

Initializes a validation using an existing errors Hash (Check::Errors).

","abstract":false,"args":[{"name":"errors","doc":null,"default_value":"","external_name":"errors","restriction":"Errors"}],"args_string":"(errors : Errors)","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/check.cr#L168","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":"","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/check.cr#L153","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","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/check.cr#L191","def":{"name":"add_error","args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"Symbol | String"},{"name":"message","doc":null,"default_value":"","external_name":"message","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Validation","visibility":"Public","body":"if message.blank?\n message = \"\\\"#{key}\\\" is not valid.\"\nend\nif @errors.has_key?(key)\nelse\n @errors[key] = Array(String).new\nend\n@errors[key] << message\nself\n"}},{"id":"add_error(key:Symbol|String):Validation-instance-method","html_id":"add_error(key:Symbol|String):Validation-instance-method","name":"add_error","doc":"Add a validation error.\n\n> By default a standard message is used.\n\n```\nv = Check.new_validation\nv.add_error(:foo)\npp v.errors # => {:foo => [\"\\\"foo\\\" is not valid.\"]}\n```\n\nSee also: `Errors`","summary":"

Add a validation error.

","abstract":false,"args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"Symbol | String"}],"args_string":"(key : Symbol | String) : Validation","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/check.cr#L211","def":{"name":"add_error","args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"Symbol | String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Validation","visibility":"Public","body":"add_error(key, \"\")\nself\n"}},{"id":"check(key:Symbol|String,message:String,valid:Bool):Validation-instance-method","html_id":"check(key:Symbol|String,message:String,valid:Bool):Validation-instance-method","name":"check","doc":"Checks a validation, often used in sequence.\n\nIf *valid* is `false`, the error *message* is added in the `errors`.\nNothing if *valid* is `true`.\n\n```\nv = Check.new_validation\n\n# -- email\n\nv.check :email, \"The email is required.\", is :presence?, :email, user\nv.check :email, \"#{user[:email]} is an invalid email.\", is :email?, user[:email]?\n\n# -- username\n\nv.check :username, \"The username is required.\", is :presence?, :username, user\n\nv.check(\n :username,\n \"The username must contain at least 2 characters.\",\n is :min?, user[:username]?, 2\n)\n\nv.check(\n :username,\n \"The username must contain a maximum of 20 characters.\",\n is :max?, user[:username]?, 20\n)\n\n# Print all errors\npp v.errors\n```","summary":"

Checks a validation, often used in sequence.

","abstract":false,"args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"Symbol | String"},{"name":"message","doc":null,"default_value":"","external_name":"message","restriction":"String"},{"name":"valid","doc":null,"default_value":"","external_name":"valid","restriction":"Bool"}],"args_string":"(key : Symbol | String, message : String, valid : Bool) : Validation","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/check.cr#L259","def":{"name":"check","args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"Symbol | String"},{"name":"message","doc":null,"default_value":"","external_name":"message","restriction":"String"},{"name":"valid","doc":null,"default_value":"","external_name":"valid","restriction":"Bool"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Validation","visibility":"Public","body":"if valid\nelse\n add_error(key, message)\nend\nself\n"}},{"id":"check(key:Symbol|String,valid:Bool,message:String):Validation-instance-method","html_id":"check(key:Symbol|String,valid:Bool,message:String):Validation-instance-method","name":"check","doc":"Checks a validation, often used in sequence.\n\nIf *valid* is `false`, the error *message* is added in the `errors`.\nNothing if *valid* is `true`.\n\n```\nv = Check.new_validation\n\n# -- email\n\nv.check(:email, is(:presence?, :email, user), \"The email is required.\")\nv.check(:email, is(:email?, user[:email]?), \"#{user[:email]} is an invalid email.\")\n\n# -- username\n\nv.check(:username, is(:presence?, :username, user), \"The username is required.\")\n\nv.check(\n :username,\n is :min?, user[:username]?, 2,\n \"The username must contain at least 2 characters.\"\n)\n\nv.check(\n :username,\n is :max?, user[:username]?, 20,\n \"The username must contain a maximum of 20 characters.\"\n)\n\n# Print all errors\npp v.errors\n```","summary":"

Checks a validation, often used in sequence.

","abstract":false,"args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"Symbol | String"},{"name":"valid","doc":null,"default_value":"","external_name":"valid","restriction":"Bool"},{"name":"message","doc":null,"default_value":"","external_name":"message","restriction":"String"}],"args_string":"(key : Symbol | String, valid : Bool, message : String) : Validation","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/check.cr#L296","def":{"name":"check","args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"Symbol | String"},{"name":"valid","doc":null,"default_value":"","external_name":"valid","restriction":"Bool"},{"name":"message","doc":null,"default_value":"","external_name":"message","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Validation","visibility":"Public","body":"if valid\nelse\n add_error(key, message)\nend\nself\n"}},{"id":"check(key:Symbol|String,valid:Bool):Validation-instance-method","html_id":"check(key:Symbol|String,valid:Bool):Validation-instance-method","name":"check","doc":"Checks a validation, often used in sequence.\n\nIf *valid* is `false`, an error message is added in the `errors`.\nNothing if *valid* is `true`.\n\n> Unlike other `check` methods, with this one a default standard message is used.\n\n```\nv = Check.new_validation\n\nv.check(\"email\", Valid.presence?(\"email\", user))\nv.check(\"email\", Valid.email?(user[\"email\"]?))\n\n# Print all errors\npp v.errors\n```","summary":"

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","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/check.cr#L317","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","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/check.cr#L178","def":{"name":"errors","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Errors","visibility":"Public","body":"@errors"}},{"id":"valid?-instance-method","html_id":"valid?-instance-method","name":"valid?","doc":"Returns `true` if there is no error, `false` if there is one or more errors.\n\n```\npp v.errors if !v.valid?\n# or with another flavor ;-)\npp v.errors unless v.valid?\n```","summary":"

Returns true if there is no error, false if there is one or more errors.

","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/check.cr#L223","def":{"name":"valid?","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@errors.empty?"}}],"macros":[],"types":[]}]},{"html_id":"validator/Valid","path":"Valid.html","kind":"alias","full_name":"Valid","name":"Valid","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/validator.cr","line_number":124,"url":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validator.cr#L124"}],"repository_name":"validator","program":false,"enum":false,"alias":true,"aliased":"Validator","const":false,"constants":[{"id":"VERSION","name":"VERSION","value":"{{ (`shards version \\\"/media/data/lab/dev/work/projects/nicolab/crystal/crystal-validator/src\\\"`).chomp.stringify.downcase }}","doc":null,"summary":null}],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":null,"doc":"Alias of `Validator`","summary":"

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":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validator.cr#L116"},{"filename":"src/validators/alpha_num.cr","line_number":8,"url":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/alpha_num.cr#L8"},{"filename":"src/validators/case_sensitive.cr","line_number":8,"url":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/case_sensitive.cr#L8"},{"filename":"src/validators/comparisons.cr","line_number":8,"url":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/comparisons.cr#L8"},{"filename":"src/validators/format.cr","line_number":8,"url":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/format.cr#L8"},{"filename":"src/validators/geo.cr","line_number":8,"url":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/geo.cr#L8"},{"filename":"src/validators/presence.cr","line_number":8,"url":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/presence.cr#L8"},{"filename":"src/validators/uri.cr","line_number":8,"url":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/uri.cr#L8"}],"repository_name":"validator","program":false,"enum":false,"alias":false,"aliased":"","const":false,"constants":[{"id":"VERSION","name":"VERSION","value":"{{ (`shards version \\\"/media/data/lab/dev/work/projects/nicolab/crystal/crystal-validator/src\\\"`).chomp.stringify.downcase }}","doc":null,"summary":null}],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":null,"doc":"∠(・.-)―〉 →◎ `validator` is a [Crystal](https://crystal-lang.org) data validation module.\nVery simple and efficient, all validations return `true` or `false`.\n\nAlso [validator/check](https://nicolab.github.io/crystal-validator/Check.html)\n(not exposed by default) provides error message handling intended for the end user.\n\nThere are 2 main ways to use *validator*:\n\n- As a simple validator to check rules (eg: email, url, min, max, presence, in, ...) which return a boolean.\n- As a more advanced validation system which will check a series of rules\n and returns all validation errors encountered with custom or standard messages.\n\nBy default the **validator** module expose only `Validator` and `Valid` (alias) in the scope:\n\n```\nrequire \"validator\"\n\nValid.email? \"contact@example.org\" # => true\nValid.url? \"https://github.com/Nicolab/crystal-validator\" # => true\nValid.my_validator? \"value to validate\", \"hello\", 42 # => true\n```\n\nAn (optional) expressive validation flavor, `is` available as an alternative. \\\nNot exposed by default, it must be imported:\n\n```\nrequire \"validator/is\"\n\nis :email?, \"contact@example.org\" # => true\nis :url?, \"https://github.com/Nicolab/crystal-validator\" # => true\nis :my_validator?, \"value to validate\", \"hello\", 42 # => true\n\n# raises an error if the email is not valid\nis! :email?, \"contact@@example..org\" # => Validator::Error\n```\n\n`is` is a macro, no overhead during the runtime 🚀\n By the nature of the macros, you can't pass the *validator* name dynamically\n with a variable like that `is(validator_name, \"my value to validate\", arg)`.\n But of course you can pass arguments with variables `is(:validator_name?, arg1, arg2)`.\n\n\n## Check\n\nMake a series of checks, with a customized error message for each case.\n\n```crystal\nrequire \"validator/check\"\n\ncheck = Check.new\n\ncheck(\"email\", \"The email is required.\", is :absence?, \"email\", user)\n```\n## Custom validator\n\nJust add your own method to register a custom *validator* or to overload an existing *validator*.\n\n```crystal\nmodule Validator\n # My custom validator\n def self.my_validator?(value, arg : String, another_arg : Int32) : Bool\n # write here the logic of your validator...\n return true\n end\nend\n\n# Call it\nputs Valid.my_validator?(\"value to validate\", \"hello\", 42) # => true\n\n# or with the `is` flavor\nputs is :my_validator?, \"value to validate\", \"hello\", 42 # => true\n```\n\n`Check` is a simple and lightweight wrapper, let your imagination run wild to add your logic around it.\n\nUsing the custom validator with the validation rules:\n\n```\nrequire \"validator/check\"\n\nclass Article\n # Mixin\n Check.checkable\n\n property title : String\n property content : String\n\n Check.rules(\n content: {\n # Now the custom validator is available\n check: {\n my_validator: {\"My validator error message\"},\n between: {\"The article content must be between 10 and 20 000 characters\", 10, 20_000},\n # ...\n },\n },\n )\nend\n\n# Triggered with all data\nv, article = Article.check(input_data)\n\n# Triggered with one value\nv, content = Article.check_content(input_data[\"content\"]?)\n```","summary":"

∠(・.-)―〉 →◎ validator is a Crystal data validation module.

","class_methods":[{"id":"absence?(key:String|Symbol,list:NamedTuple):Bool-class-method","html_id":"absence?(key:String|Symbol,list:NamedTuple):Bool-class-method","name":"absence?","doc":"Validates the absence of the value.\n- See also `#not_in?`.\n- See also `#empty?`.","summary":"

Validates the absence of the value.

","abstract":false,"args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"String | Symbol"},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"NamedTuple"}],"args_string":"(key : String | Symbol, list : NamedTuple) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/presence.cr#L47","def":{"name":"absence?","args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"String | Symbol"},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"NamedTuple"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"self.empty?(list[key]?)"}},{"id":"absence?(key:String|Symbol|Number,list:Hash):Bool-class-method","html_id":"absence?(key:String|Symbol|Number,list:Hash):Bool-class-method","name":"absence?","doc":"Validates the absence of the value.\n- See also `#not_in?`.\n- See also `#empty?`.","summary":"

Validates the absence of the value.

","abstract":false,"args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"String | Symbol | Number"},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Hash"}],"args_string":"(key : String | Symbol | Number, list : Hash) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/presence.cr#L42","def":{"name":"absence?","args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"String | Symbol | Number"},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Hash"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"self.empty?(list[key]?)"}},{"id":"accepted?(value:String):Bool-class-method","html_id":"accepted?(value:String):Bool-class-method","name":"accepted?","doc":"Validates that the *value* `String` is the representation of an acceptance.\n> One of: \"yes\", \"y\", \"on\", \"o\", \"ok\", \"1\", \"true\"\n- See also `#refused?`.","summary":"

Validates that the 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","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/presence.cr#L180","def":{"name":"accepted?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"self.in?(value.downcase, [\"yes\", \"y\", \"on\", \"o\", \"ok\", \"1\", \"true\"])"}},{"id":"accepted?(value):Bool-class-method","html_id":"accepted?(value):Bool-class-method","name":"accepted?","doc":"Validates that the *value* is the representation of an acceptance.\n> One of: \"yes\", \"y\", \"on\", \"o\", \"ok\", \"1\", \"true\"\n\n*value* must implements *#to_s* method.\n- See also `#refused?`.","summary":"

Validates that the value is the representation of an acceptance.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"args_string":"(value) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/presence.cr#L189","def":{"name":"accepted?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"self.accepted?(value.to_s)"}},{"id":"ascii_only?(value:String):Bool-class-method","html_id":"ascii_only?(value:String):Bool-class-method","name":"ascii_only?","doc":"Validates that the *value* `String`\nis comprised in its entirety by ASCII characters.","summary":"

Validates that the 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","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/format.cr#L41","def":{"name":"ascii_only?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value.ascii_only?"}},{"id":"ascii_only?(values:Array(String)):Bool-class-method","html_id":"ascii_only?(values:Array(String)):Bool-class-method","name":"ascii_only?","doc":"Validates that all the `String` in the *values* `Array`\nare comprised in their entirety by ASCII characters.","summary":"

Validates that all the String in the 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","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/format.cr#L47","def":{"name":"ascii_only?","args":[{"name":"values","doc":null,"default_value":"","external_name":"values","restriction":"Array(String)"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"size = value.size\nwhile size\n size = size - 1\n if value.ascii_only?(values[i])\n else\n return false\n end\nend\ntrue\n"}},{"id":"base64?(value:String):Bool-class-method","html_id":"base64?(value:String):Bool-class-method","name":"base64?","doc":"Validates that the *value* has the format *base64*.","summary":"

Validates that the value has the format base64.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/format.cr#L87","def":{"name":"base64?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"if (value.match(@@rx_base64)) && ((value.size % 4) === 0)\n return true\nend\nfalse\n"}},{"id":"between?(value,min,max):Bool-class-method","html_id":"between?(value,min,max):Bool-class-method","name":"between?","doc":"Validates that the *value* is between (inclusive) *min* and *max*.","summary":"

Validates that the value is between (inclusive) min and max.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"min","doc":null,"default_value":"","external_name":"min","restriction":""},{"name":"max","doc":null,"default_value":"","external_name":"max","restriction":""}],"args_string":"(value, min, max) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/comparisons.cr#L87","def":{"name":"between?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"min","doc":null,"default_value":"","external_name":"min","restriction":""},{"name":"max","doc":null,"default_value":"","external_name":"max","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value >= min && value <= max"}},{"id":"between?(value:String|Array,min:Int,max:Int):Bool-class-method","html_id":"between?(value:String|Array,min:Int,max:Int):Bool-class-method","name":"between?","doc":"Validates that the size of the *value* (`String` or `Array`) is between\n(inclusive) *min* and *max*.\n- See also `#size?`.","summary":"

Validates that the size of the value (String or Array) is between (inclusive) min and max.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String | Array"},{"name":"min","doc":null,"default_value":"","external_name":"min","restriction":"Int"},{"name":"max","doc":null,"default_value":"","external_name":"max","restriction":"Int"}],"args_string":"(value : String | Array, min : Int, max : Int) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/comparisons.cr#L94","def":{"name":"between?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String | Array"},{"name":"min","doc":null,"default_value":"","external_name":"min","restriction":"Int"},{"name":"max","doc":null,"default_value":"","external_name":"max","restriction":"Int"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"size = value.size\nsize >= min && size <= max\n"}},{"id":"domain?(value:String):Bool-class-method","html_id":"domain?(value:String):Bool-class-method","name":"domain?","doc":null,"summary":null,"abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/uri.cr#L23","def":{"name":"domain?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"size = value.size\nif size > 75 || size < 4\n return false\nend\nif value.includes?(\"..\")\n return false\nend\nif m = value.match(@@rx_domain)\nelse\n return false\nend\next_size = m[\"ext\"].size\nif ext_size < 2 || ext_size > 12\n return false\nend\ntrue\n"}},{"id":"email?(value:String):Bool-class-method","html_id":"email?(value:String):Bool-class-method","name":"email?","doc":"Validates that the *value* is an email.\nThis method is stricter than the standard allows.\nIt is subjectively based on the common addresses\nof organisations (@enterprise.ltd, ...)\nand mail services suck as Gmail, Hotmail, Yahoo !, ...","summary":"

Validates that the value is an email.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/uri.cr#L158","def":{"name":"email?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"size = value.size\nif size > 60 || size < 7\n return false\nend\nif value.includes?(\"..\")\n return false\nend\nif value.includes?(\"--\")\n return false\nend\nif value.includes?(\"___\")\n return false\nend\nif m = value.match(@@rx_email)\nelse\n return false\nend\nself.domain?(\"#{m[\"name\"]}.#{m[\"ext\"]}\")\n"}},{"id":"empty?(value):Bool-class-method","html_id":"empty?(value):Bool-class-method","name":"empty?","doc":"Validates that the *value* is empty.\n- See also `#absence?`.\n- See also `#not_in?`.","summary":"

Validates that the value is empty.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"args_string":"(value) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/presence.cr#L58","def":{"name":"empty?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"case value\nwhen .nil?\n true\nwhen .is_a?(String)\n value.presence.nil?\nwhen .is_a?(Number)\n value == 0\nwhen .responds_to?(:size)\n value.size == 0\nelse\n false\nend"}},{"id":"ends?(value:String,search:String):Bool-class-method","html_id":"ends?(value:String,search:String):Bool-class-method","name":"ends?","doc":"Validates that the `String` *value* ends with *search*.\n- See also `#starts?`.\n- See also `#match?`.\n- See also `#in?`.","summary":"

Validates that the 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","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/presence.cr#L243","def":{"name":"ends?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"search","doc":null,"default_value":"","external_name":"search","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value.ends_with?(search)"}},{"id":"ends?(value:String,search:Char):Bool-class-method","html_id":"ends?(value:String,search:Char):Bool-class-method","name":"ends?","doc":"Validates that the `String` *value* ends with *search*.\n- See also `#starts?`.\n- See also `#match?`.\n- See also `#in?`.","summary":"

Validates that the 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","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/presence.cr#L248","def":{"name":"ends?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"search","doc":null,"default_value":"","external_name":"search","restriction":"Char"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value.ends_with?(search)"}},{"id":"ends?(value:String,search:Regex):Bool-class-method","html_id":"ends?(value:String,search:Regex):Bool-class-method","name":"ends?","doc":"Validates that the `String` *value* ends with *search*.\n- See also `#starts?`.\n- See also `#match?`.\n- See also `#in?`.","summary":"

Validates that the 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","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/presence.cr#L253","def":{"name":"ends?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"search","doc":null,"default_value":"","external_name":"search","restriction":"Regex"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value.ends_with?(search)"}},{"id":"eq?(value,another_value):Bool-class-method","html_id":"eq?(value,another_value):Bool-class-method","name":"eq?","doc":"Validates that the *value* is equal to *another_value*.","summary":"

Validates that the value is equal to another_value.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"another_value","doc":null,"default_value":"","external_name":"another_value","restriction":""}],"args_string":"(value, another_value) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/comparisons.cr#L10","def":{"name":"eq?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"another_value","doc":null,"default_value":"","external_name":"another_value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value == another_value"}},{"id":"gt?(value,another_value):Bool-class-method","html_id":"gt?(value,another_value):Bool-class-method","name":"gt?","doc":"Validates that the *value* is greater than *another_value*.","summary":"

Validates that the value is greater than another_value.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"another_value","doc":null,"default_value":"","external_name":"another_value","restriction":""}],"args_string":"(value, another_value) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/comparisons.cr#L15","def":{"name":"gt?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"another_value","doc":null,"default_value":"","external_name":"another_value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value > another_value"}},{"id":"gt?(value:String|Array,limit:Int):Bool-class-method","html_id":"gt?(value:String|Array,limit:Int):Bool-class-method","name":"gt?","doc":"Validates that the size of the *value* (`String` or `Array`)\nis greater than *limit* number.","summary":"

Validates that the size of the value (String or Array) is greater than limit number.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String | Array"},{"name":"limit","doc":null,"default_value":"","external_name":"limit","restriction":"Int"}],"args_string":"(value : String | Array, limit : Int) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/comparisons.cr#L21","def":{"name":"gt?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String | Array"},{"name":"limit","doc":null,"default_value":"","external_name":"limit","restriction":"Int"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value.size > limit"}},{"id":"gte?(value,another_value):Bool-class-method","html_id":"gte?(value,another_value):Bool-class-method","name":"gte?","doc":"Validates that the *value* is equal to or greater than *another_value*.\n> Similar to `#min`.","summary":"

Validates that the value is equal to or greater than another_value.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"another_value","doc":null,"default_value":"","external_name":"another_value","restriction":""}],"args_string":"(value, another_value) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/comparisons.cr#L27","def":{"name":"gte?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"another_value","doc":null,"default_value":"","external_name":"another_value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value >= another_value"}},{"id":"gte?(value:String|Array,min:Int):Bool-class-method","html_id":"gte?(value:String|Array,min:Int):Bool-class-method","name":"gte?","doc":"Validates that the size of the *value* (`String` or `Array`)\nis greater than *min* number.\n> Similar to `#min`.","summary":"

Validates that the size of the value (String or Array) is greater than min number.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String | Array"},{"name":"min","doc":null,"default_value":"","external_name":"min","restriction":"Int"}],"args_string":"(value : String | Array, min : Int) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/comparisons.cr#L34","def":{"name":"gte?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String | Array"},{"name":"min","doc":null,"default_value":"","external_name":"min","restriction":"Int"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value.size >= min"}},{"id":"hex?(value:String):Bool-class-method","html_id":"hex?(value:String):Bool-class-method","name":"hex?","doc":"Validates that the `String` *value* does denote\na representation of a hexadecimal string.","summary":"

Validates that the 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","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/format.cr#L112","def":{"name":"hex?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!value.match(@@rx_hex).nil?"}},{"id":"hex?(value:Bytes):Bool-class-method","html_id":"hex?(value:Bytes):Bool-class-method","name":"hex?","doc":"Validates that the `Bytes` *value* does denote\na representation of a hexadecimal slice of Bytes.","summary":"

Validates that the 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","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/format.cr#L118","def":{"name":"hex?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"Bytes"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!(String.new(value)).match(@@rx_hex).nil?"}},{"id":"hex_color?(value:String):Bool-class-method","html_id":"hex_color?(value:String):Bool-class-method","name":"hex_color?","doc":"Validates that the `String` *value* does denote\na representation of a hexadecimal color.\n\n```\nValid.hex_color? \"#fff\" => true\nValid.hex_color? \"#ffffff\" => true\n```","summary":"

Validates that the 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","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/format.cr#L129","def":{"name":"hex_color?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!value.match(@@rx_hex_color).nil?"}},{"id":"in?(value,list:Array):Bool-class-method","html_id":"in?(value,list:Array):Bool-class-method","name":"in?","doc":"Validates that the (*list*) contains the *value*.\n- See also `#presence?`.\n- See also `#not_in?`.\n- See also `#not_empty?`.","summary":"

Validates that the (list) contains the value.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Array"}],"args_string":"(value, list : Array) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/presence.cr#L109","def":{"name":"in?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Array"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"list.includes?(value)"}},{"id":"in?(value:String,str:String):Bool-class-method","html_id":"in?(value:String,str:String):Bool-class-method","name":"in?","doc":"Validates that the (*str*) `String` contains the *value*.\n- See also `#presence?`.\n- See also `#not_in?`.\n- See also `#not_empty?`.","summary":"

Validates that the (str) String contains the value.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"str","doc":null,"default_value":"","external_name":"str","restriction":"String"}],"args_string":"(value : String, str : String) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/presence.cr#L101","def":{"name":"in?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"str","doc":null,"default_value":"","external_name":"str","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"str.includes?(value)"}},{"id":"in?(key:Symbol|String,list:Hash):Bool-class-method","html_id":"in?(key:Symbol|String,list:Hash):Bool-class-method","name":"in?","doc":"Validates that the (*list*) contains the *value*.\n- See also `#presence?`.\n- See also `#not_in?`.\n- See also `#not_empty?`.","summary":"

Validates that the (list) contains the value.

","abstract":false,"args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"Symbol | String"},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Hash"}],"args_string":"(key : Symbol | String, list : Hash) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/presence.cr#L129","def":{"name":"in?","args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"Symbol | String"},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Hash"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"list.has_key?(key)"}},{"id":"in?(key:Symbol|String,list:NamedTuple):Bool-class-method","html_id":"in?(key:Symbol|String,list:NamedTuple):Bool-class-method","name":"in?","doc":"Validates that the (*list*) contains the *value*.\n- See also `#presence?`.\n- See also `#not_in?`.\n- See also `#not_empty?`.","summary":"

Validates that the (list) contains the value.

","abstract":false,"args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"Symbol | String"},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"NamedTuple"}],"args_string":"(key : Symbol | String, list : NamedTuple) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/presence.cr#L124","def":{"name":"in?","args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"Symbol | String"},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"NamedTuple"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"list.has_key?(key)"}},{"id":"in?(value,list:Range):Bool-class-method","html_id":"in?(value,list:Range):Bool-class-method","name":"in?","doc":"Validates that the (*list*) contains the *value*.\n- See also `#presence?`.\n- See also `#not_in?`.\n- See also `#not_empty?`.","summary":"

Validates that the (list) contains the value.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Range"}],"args_string":"(value, list : Range) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/presence.cr#L119","def":{"name":"in?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Range"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"list.includes?(value)"}},{"id":"in?(value,list:Tuple):Bool-class-method","html_id":"in?(value,list:Tuple):Bool-class-method","name":"in?","doc":"Validates that the (*list*) contains the *value*.\n- See also `#presence?`.\n- See also `#not_in?`.\n- See also `#not_empty?`.","summary":"

Validates that the (list) contains the value.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Tuple"}],"args_string":"(value, list : Tuple) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/presence.cr#L114","def":{"name":"in?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Tuple"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"list.includes?(value)"}},{"id":"ip?(value:String):Bool-class-method","html_id":"ip?(value:String):Bool-class-method","name":"ip?","doc":"Validates that the *value* is an IP (IPv4 or IPv6).","summary":"

Validates that the value is an IP (IPv4 or IPv6).

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/uri.cr#L77","def":{"name":"ip?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"(self.ipv4?(value)) || (self.ipv6?(value))"}},{"id":"ipv4?(value:String):Bool-class-method","html_id":"ipv4?(value:String):Bool-class-method","name":"ipv4?","doc":"Validates that the *value* is an IPv4.","summary":"

Validates that the value is an IPv4.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/uri.cr#L82","def":{"name":"ipv4?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!value.match(@@rx_ipv4).nil?"}},{"id":"ipv6?(value:String):Bool-class-method","html_id":"ipv6?(value:String):Bool-class-method","name":"ipv6?","doc":"Validates that the *value* is an IPv6.","summary":"

Validates that the value is an IPv6.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/uri.cr#L87","def":{"name":"ipv6?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"addr_and_zone = [value]\nif value.includes?('%')\n addr_and_zone = value.split('%')\n if addr_and_zone.size == 2\n else\n return false\n end\n if addr_and_zone[0].includes?(':')\n else\n return false\n end\n if addr_and_zone[1] == \"\"\n return false\n end\nend\nblocks = addr_and_zone[0].split(':')\nfound_omission_block = false\nfound_ipv4_transition_block = self.ipv4?(blocks[blocks.size - 1])\nexpected_number_of_blocks = found_ipv4_transition_block ? 7 : 8\nif blocks.size > expected_number_of_blocks\n return false\nend\nif value == \"::\"\n return true\nend\nif value[0...2] == \"::\"\n blocks.shift(2)\n found_omission_block = true\nelse\n if value[(value.size - 2)..] == \"::\"\n blocks.pop(2)\n found_omission_block = true\n end\nend\ni = 0\nwhile i < blocks.size\n if ((blocks[i] === \"\") && i > 0) && i < (blocks.size - 1)\n if found_omission_block\n return false\n end\n found_omission_block = true\n else\n if (!(found_ipv4_transition_block && (i == (blocks.size - 1)))) && blocks[i].match(@@rx_ipv6_block).nil?\n return false\n end\n end\n i = i + 1\nend\nif found_omission_block\n return blocks.size >= 1\nend\nblocks.size == expected_number_of_blocks\n"}},{"id":"json?(value:String,strict:Bool=true):Bool-class-method","html_id":"json?(value:String,strict:Bool=true):Bool-class-method","name":"json?","doc":"Validates that the *value* represents a JSON string.\n*strict* to `true` (default) to try to parse the JSON,\nreturns `false` if the parsing fails.\nIf *strict* is `false`, only the first char and the last char are checked.","summary":"

Validates that the value represents a JSON string.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"strict","doc":null,"default_value":"true","external_name":"strict","restriction":"Bool"}],"args_string":"(value : String, strict : Bool = true) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/format.cr#L64","def":{"name":"json?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"strict","doc":null,"default_value":"true","external_name":"strict","restriction":"Bool"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"if strict\n begin\n JSON.parse(value)\n rescue err\n return false\n else\n return true\n end\nend\n((self.starts?(value, \"{\")) && (self.ends?(value, \"}\"))) || ((self.starts?(value, \"[\")) && (self.ends?(value, \"]\")))\n"}},{"id":"jwt?(value:String):Bool-class-method","html_id":"jwt?(value:String):Bool-class-method","name":"jwt?","doc":"Validates that the *value* is a *JSON Web Token*.","summary":"

Validates that the value is a JSON Web Token.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/format.cr#L95","def":{"name":"jwt?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!value.match(@@rx_jwt).nil?"}},{"id":"lat?(value:String|Float):Bool-class-method","html_id":"lat?(value:String|Float):Bool-class-method","name":"lat?","doc":"Validates that the *value* is a valid format representation of a geographical latitude.\n- See also `#lng?`.\n- See also `#lat_lng?`.","summary":"

Validates that the value is a valid format representation of a geographical latitude.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String | Float"}],"args_string":"(value : String | Float) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/geo.cr#L31","def":{"name":"lat?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String | Float"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!value.to_s.match(@@rx_geo_lat).nil?"}},{"id":"lat_lng?(value:String):Bool-class-method","html_id":"lat_lng?(value:String):Bool-class-method","name":"lat_lng?","doc":"Validates that the *value* is a valid format representation of\na geographical position (given in latitude and longitude).\n- See also `#lat?`.\n- See also `#lng?`.","summary":"

Validates that the value is a valid format representation of a geographical position (given in latitude and longitude).

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/geo.cr#L16","def":{"name":"lat_lng?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"if !(value.includes?(\",\"))\n return false\nend\nlat, lng = value.split(\",\")\nif lat && lng\nelse\n return false\nend\nif ((lat.starts_with?('(')) && (!(lng.ends_with?(')'))))\n return false\nend\nif ((lng.ends_with?(')')) && (!(lat.starts_with?('('))))\n return false\nend\nif (lat.match(@@rx_geo_lat)) && (lng.match(@@rx_geo_lng))\n return true\nend\nfalse\n"}},{"id":"lng?(value:String|Float):Bool-class-method","html_id":"lng?(value:String|Float):Bool-class-method","name":"lng?","doc":"Validates that the *value* is a valid format representation of a geographical longitude.\n- See also `#lat?`.\n- See also `#lat_lng?`.","summary":"

Validates that the value is a valid format representation of a geographical longitude.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String | Float"}],"args_string":"(value : String | Float) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/geo.cr#L38","def":{"name":"lng?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String | Float"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!value.to_s.match(@@rx_geo_lng).nil?"}},{"id":"lower?(value:String):Bool-class-method","html_id":"lower?(value:String):Bool-class-method","name":"lower?","doc":"Validates that the *value* is in lower case.","summary":"

Validates that the value is in lower case.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/case_sensitive.cr#L10","def":{"name":"lower?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"(!value.blank?) && (value.downcase === value)"}},{"id":"lt?(value:String|Array,limit:Int):Bool-class-method","html_id":"lt?(value:String|Array,limit:Int):Bool-class-method","name":"lt?","doc":"Validates that the size of the *value* (`String` or `Array`)\nis lesser than *limit* number.","summary":"

Validates that the size of the value (String or Array) is lesser than limit number.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String | Array"},{"name":"limit","doc":null,"default_value":"","external_name":"limit","restriction":"Int"}],"args_string":"(value : String | Array, limit : Int) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/comparisons.cr#L45","def":{"name":"lt?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String | Array"},{"name":"limit","doc":null,"default_value":"","external_name":"limit","restriction":"Int"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value.size < limit"}},{"id":"lt?(value,another_value):Bool-class-method","html_id":"lt?(value,another_value):Bool-class-method","name":"lt?","doc":"Validates that the *value* is lesser than *another_value*.","summary":"

Validates that the value is lesser than another_value.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"another_value","doc":null,"default_value":"","external_name":"another_value","restriction":""}],"args_string":"(value, another_value) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/comparisons.cr#L39","def":{"name":"lt?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"another_value","doc":null,"default_value":"","external_name":"another_value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value < another_value"}},{"id":"lte?(value:String|Array,max:Int):Bool-class-method","html_id":"lte?(value:String|Array,max:Int):Bool-class-method","name":"lte?","doc":"Validates that the size of the *value* (`String` or `Array`)\nis equal or lesser than *max* number.\n> Similar to `#max`.","summary":"

Validates that the size of the value (String or Array) is equal or lesser than max number.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String | Array"},{"name":"max","doc":null,"default_value":"","external_name":"max","restriction":"Int"}],"args_string":"(value : String | Array, max : Int) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/comparisons.cr#L58","def":{"name":"lte?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String | Array"},{"name":"max","doc":null,"default_value":"","external_name":"max","restriction":"Int"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value.size <= max"}},{"id":"lte?(value,another_value):Bool-class-method","html_id":"lte?(value,another_value):Bool-class-method","name":"lte?","doc":"Validates that the *value* is equal to or lesser than *another_value*.\n> Similar to `#max`.","summary":"

Validates that the value is equal to or lesser than another_value.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"another_value","doc":null,"default_value":"","external_name":"another_value","restriction":""}],"args_string":"(value, another_value) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/comparisons.cr#L51","def":{"name":"lte?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"another_value","doc":null,"default_value":"","external_name":"another_value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value <= another_value"}},{"id":"mac_addr?(value:String,no_colons:Bool=false):Bool-class-method","html_id":"mac_addr?(value:String,no_colons:Bool=false):Bool-class-method","name":"mac_addr?","doc":"Validates that the *value* is a MAC address.","summary":"

Validates that the value is a MAC address.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"no_colons","doc":null,"default_value":"false","external_name":"no_colons","restriction":"Bool"}],"args_string":"(value : String, no_colons : Bool = false) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/uri.cr#L176","def":{"name":"mac_addr?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"no_colons","doc":null,"default_value":"false","external_name":"no_colons","restriction":"Bool"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"if no_colons\n return !value.match(@@rx_mac_addr_no_colons).nil?\nend\n(((!value.match(@@rx_mac_addr).nil?) || (!value.match(@@rx_mac_addr_with_hyphen).nil?)) || (!value.match(@@rx_mac_addr_with_spaces).nil?)) || (!value.match(@@rx_mac_addr_with_dots).nil?)\n"}},{"id":"magnet_uri?(value:String):Bool-class-method","html_id":"magnet_uri?(value:String):Bool-class-method","name":"magnet_uri?","doc":"Validates that the *value* is a Magnet URI.","summary":"

Validates that the value is a Magnet URI.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/uri.cr#L186","def":{"name":"magnet_uri?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!value.match(@@rx_magnet_uri).nil?"}},{"id":"match?(value:Number,pattern:Regex):Bool-class-method","html_id":"match?(value:Number,pattern:Regex):Bool-class-method","name":"match?","doc":"Validates that the *value* matches the *pattern*.","summary":"

Validates that the value matches the pattern.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"Number"},{"name":"pattern","doc":null,"default_value":"","external_name":"pattern","restriction":"Regex"}],"args_string":"(value : Number, pattern : Regex) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/presence.cr#L15","def":{"name":"match?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"Number"},{"name":"pattern","doc":null,"default_value":"","external_name":"pattern","restriction":"Regex"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!value.to_s.match(pattern).nil?"}},{"id":"match?(value:String,pattern:Regex):Bool-class-method","html_id":"match?(value:String,pattern:Regex):Bool-class-method","name":"match?","doc":"Validates that the *value* matches the *pattern*.","summary":"

Validates that the value matches the pattern.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"pattern","doc":null,"default_value":"","external_name":"pattern","restriction":"Regex"}],"args_string":"(value : String, pattern : Regex) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/presence.cr#L10","def":{"name":"match?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"pattern","doc":null,"default_value":"","external_name":"pattern","restriction":"Regex"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!value.match(pattern).nil?"}},{"id":"max?(value,max):Bool-class-method","html_id":"max?(value,max):Bool-class-method","name":"max?","doc":"Validates that the *value* is equal to or lesser than *max* (inclusive).\n> Similar to `#lte`.","summary":"

Validates that the value is equal to or lesser than max (inclusive).

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"max","doc":null,"default_value":"","external_name":"max","restriction":""}],"args_string":"(value, max) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/comparisons.cr#L76","def":{"name":"max?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"max","doc":null,"default_value":"","external_name":"max","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value <= max"}},{"id":"max?(value:String|Array,max:Int):Bool-class-method","html_id":"max?(value:String|Array,max:Int):Bool-class-method","name":"max?","doc":":ditto:\n> Based on the size of the `String`.","summary":"

:ditto: > Based on the size of the String.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String | Array"},{"name":"max","doc":null,"default_value":"","external_name":"max","restriction":"Int"}],"args_string":"(value : String | Array, max : Int) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/comparisons.cr#L82","def":{"name":"max?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String | Array"},{"name":"max","doc":null,"default_value":"","external_name":"max","restriction":"Int"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value.size <= max"}},{"id":"md5?(value:String):Bool-class-method","html_id":"md5?(value:String):Bool-class-method","name":"md5?","doc":"Validates that the *value* has the format *md5*.","summary":"

Validates that the value has the format md5.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/format.cr#L82","def":{"name":"md5?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!value.match(@@rx_md5).nil?"}},{"id":"min?(value,min):Bool-class-method","html_id":"min?(value,min):Bool-class-method","name":"min?","doc":"Validates that the *value* is equal to or greater than *min* (inclusive).\n> Similar to `#gte`.","summary":"

Validates that the value is equal to or greater than min (inclusive).

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"min","doc":null,"default_value":"","external_name":"min","restriction":""}],"args_string":"(value, min) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/comparisons.cr#L64","def":{"name":"min?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"min","doc":null,"default_value":"","external_name":"min","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value >= min"}},{"id":"min?(value:String|Array,min:Int):Bool-class-method","html_id":"min?(value:String|Array,min:Int):Bool-class-method","name":"min?","doc":":ditto:\n> Based on the size of the `String`.","summary":"

:ditto: > Based on the size of the String.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String | Array"},{"name":"min","doc":null,"default_value":"","external_name":"min","restriction":"Int"}],"args_string":"(value : String | Array, min : Int) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/comparisons.cr#L70","def":{"name":"min?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String | Array"},{"name":"min","doc":null,"default_value":"","external_name":"min","restriction":"Int"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value.size >= min"}},{"id":"mongo_id?(value:Bytes):Bool-class-method","html_id":"mongo_id?(value:Bytes):Bool-class-method","name":"mongo_id?","doc":"Validates that the `Bytes` *value* does denote\na representation of a *MongoID* slice of Bytes.","summary":"

Validates that the 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","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/format.cr#L143","def":{"name":"mongo_id?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"Bytes"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"(self.hex?(value)) && (value.size == 24)"}},{"id":"mongo_id?(value:String):Bool-class-method","html_id":"mongo_id?(value:String):Bool-class-method","name":"mongo_id?","doc":"Validates that the `String` *value* does denote\na representation of a *MongoID* string.","summary":"

Validates that the 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","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/format.cr#L137","def":{"name":"mongo_id?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"(self.hex?(value)) && (value.size == 24)"}},{"id":"not_empty?(value):Bool-class-method","html_id":"not_empty?(value):Bool-class-method","name":"not_empty?","doc":"Validates that the *value* is not empty.\n- See also `#presence?`.\n- See also `#in?`.","summary":"

Validates that the value is not empty.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"args_string":"(value) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/presence.cr#L71","def":{"name":"not_empty?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"(self.empty?(value)) == false"}},{"id":"not_in?(value:String,str:String):Bool-class-method","html_id":"not_in?(value:String,str:String):Bool-class-method","name":"not_in?","doc":"Validates that the (*str*) `String` does not contain the *value*.\n- See also `#absence?`.\n- See also `#in?`.\n- See also `#empty?`.","summary":"

Validates that the (str) String does not contain the value.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"str","doc":null,"default_value":"","external_name":"str","restriction":"String"}],"args_string":"(value : String, str : String) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/presence.cr#L141","def":{"name":"not_in?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"str","doc":null,"default_value":"","external_name":"str","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!(str.includes?(value))"}},{"id":"not_in?(value,list:Array):Bool-class-method","html_id":"not_in?(value,list:Array):Bool-class-method","name":"not_in?","doc":"Validates that the (*list*) does not contain the *value*.\n- See also `#absence?`.\n- See also `#in?`.\n- See also `#empty?`.","summary":"

Validates that the (list) does not contain the value.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Array"}],"args_string":"(value, list : Array) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/presence.cr#L149","def":{"name":"not_in?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Array"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!(list.includes?(value))"}},{"id":"not_in?(value,list:Tuple):Bool-class-method","html_id":"not_in?(value,list:Tuple):Bool-class-method","name":"not_in?","doc":"Validates that the (*list*) does not contain the *value*.\n- See also `#absence?`.\n- See also `#in?`.\n- See also `#empty?`.","summary":"

Validates that the (list) does not contain the value.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Tuple"}],"args_string":"(value, list : Tuple) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/presence.cr#L154","def":{"name":"not_in?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Tuple"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!(list.includes?(value))"}},{"id":"not_in?(value,list:Range):Bool-class-method","html_id":"not_in?(value,list:Range):Bool-class-method","name":"not_in?","doc":"Validates that the (*list*) does not contain the *value*.\n- See also `#absence?`.\n- See also `#in?`.\n- See also `#empty?`.","summary":"

Validates that the (list) does not contain the value.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Range"}],"args_string":"(value, list : Range) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/presence.cr#L159","def":{"name":"not_in?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Range"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!(list.includes?(value))"}},{"id":"not_in?(key:Symbol|String,list:NamedTuple):Bool-class-method","html_id":"not_in?(key:Symbol|String,list:NamedTuple):Bool-class-method","name":"not_in?","doc":"Validates that the (*list*) does not contain the *value*.\n- See also `#absence?`.\n- See also `#in?`.\n- See also `#empty?`.","summary":"

Validates that the (list) does not contain the value.

","abstract":false,"args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"Symbol | String"},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"NamedTuple"}],"args_string":"(key : Symbol | String, list : NamedTuple) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/presence.cr#L164","def":{"name":"not_in?","args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"Symbol | String"},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"NamedTuple"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!(list.has_key?(key))"}},{"id":"not_in?(key:Symbol|String,list:Hash):Bool-class-method","html_id":"not_in?(key:Symbol|String,list:Hash):Bool-class-method","name":"not_in?","doc":"Validates that the (*list*) does not contain the *value*.\n- See also `#absence?`.\n- See also `#in?`.\n- See also `#empty?`.","summary":"

Validates that the (list) does not contain the value.

","abstract":false,"args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"Symbol | String"},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Hash"}],"args_string":"(key : Symbol | String, list : Hash) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/presence.cr#L169","def":{"name":"not_in?","args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"Symbol | String"},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Hash"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!(list.has_key?(key))"}},{"id":"not_null?(value):Bool-class-method","html_id":"not_null?(value):Bool-class-method","name":"not_null?","doc":"Validates that the *value* is not null (`nil`).\n- See also `#null?`.\n- See also `#not_empty?`.","summary":"

Validates that the value is not null (nil).

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"args_string":"(value) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/presence.cr#L89","def":{"name":"not_null?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!value.nil?"}},{"id":"null?(value):Bool-class-method","html_id":"null?(value):Bool-class-method","name":"null?","doc":"Validates that the *value* is null (`nil`).\n- See also `#empty?`.\n- See also `#not_null?`.","summary":"

Validates that the value is null (nil).

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"args_string":"(value) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/presence.cr#L82","def":{"name":"null?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value.nil?"}},{"id":"number?(value:String):Bool-class-method","html_id":"number?(value:String):Bool-class-method","name":"number?","doc":"Validates that the *value* is a numeric `String` representation.","summary":"

Validates that the value is a numeric String representation.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/alpha_num.cr#L12","def":{"name":"number?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"(!value.blank?) && (!value.match(@@rx_number).nil?)"}},{"id":"port?(value:String="0",min:String="1",max:String="65535"):Bool-class-method","html_id":"port?(value:String="0",min:String="1",max:String="65535"):Bool-class-method","name":"port?","doc":"Validates that the *value* is in a valid port range,\nbetween (inclusive) 1 / *min* and 65535 / *max*.","summary":"

Validates that the value is in a valid port range, between (inclusive) 1 / min and 65535 / max.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"\"0\"","external_name":"value","restriction":"String"},{"name":"min","doc":null,"default_value":"\"1\"","external_name":"min","restriction":"String"},{"name":"max","doc":null,"default_value":"\"65535\"","external_name":"max","restriction":"String"}],"args_string":"(value : String = "0", min : String = "1", max : String = "65535") : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/uri.cr#L44","def":{"name":"port?","args":[{"name":"value","doc":null,"default_value":"\"0\"","external_name":"value","restriction":"String"},{"name":"min","doc":null,"default_value":"\"1\"","external_name":"min","restriction":"String"},{"name":"max","doc":null,"default_value":"\"65535\"","external_name":"max","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"if (self.number?(min)) && (self.number?(max))\nelse\n return false\nend\nself.port?(value.to_i, min.to_i, max.to_i)\n"}},{"id":"port?(value=0,min=1,max=65535):Bool-class-method","html_id":"port?(value=0,min=1,max=65535):Bool-class-method","name":"port?","doc":"Validates that the *value* is in a valid port range,\nbetween (inclusive) 1 / *min* and 65535 / *max*.","summary":"

Validates that the value is in a valid port range, between (inclusive) 1 / min and 65535 / max.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"0","external_name":"value","restriction":""},{"name":"min","doc":null,"default_value":"1","external_name":"min","restriction":""},{"name":"max","doc":null,"default_value":"65535","external_name":"max","restriction":""}],"args_string":"(value = 0, min = 1, max = 65535) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/uri.cr#L38","def":{"name":"port?","args":[{"name":"value","doc":null,"default_value":"0","external_name":"value","restriction":""},{"name":"min","doc":null,"default_value":"1","external_name":"min","restriction":""},{"name":"max","doc":null,"default_value":"65535","external_name":"max","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"if self.between?(value, 1, 65535)\nelse\n return false\nend\nself.between?(value, min, max)\n"}},{"id":"presence?(key:String|Symbol,list:NamedTuple):Bool-class-method","html_id":"presence?(key:String|Symbol,list:NamedTuple):Bool-class-method","name":"presence?","doc":"Validates the presence of the value.\n- See also `#in?`.\n- See also `#not_empty?`.","summary":"

Validates the presence of the value.

","abstract":false,"args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"String | Symbol"},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"NamedTuple"}],"args_string":"(key : String | Symbol, list : NamedTuple) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/presence.cr#L31","def":{"name":"presence?","args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"String | Symbol"},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"NamedTuple"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"self.not_empty?(list[key]?)"}},{"id":"presence?(key:String|Symbol|Number,list:Hash):Bool-class-method","html_id":"presence?(key:String|Symbol|Number,list:Hash):Bool-class-method","name":"presence?","doc":"Validates the presence of the value.\n- See also `#in?`.\n- See also `#not_empty?`.","summary":"

Validates the presence of the value.

","abstract":false,"args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"String | Symbol | Number"},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Hash"}],"args_string":"(key : String | Symbol | Number, list : Hash) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/presence.cr#L26","def":{"name":"presence?","args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"String | Symbol | Number"},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Hash"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"self.not_empty?(list[key]?)"}},{"id":"refused?(value):Bool-class-method","html_id":"refused?(value):Bool-class-method","name":"refused?","doc":"Returns `true` if the *value* is the representation of a refusal.\n> One of: \"no\", \"n\", \"off\", \"0\", \"false\"\n\n*value* must implements *#to_s* method.\n- See also `#accepted?`.","summary":"

Returns true if the value is the representation of a refusal.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"args_string":"(value) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/presence.cr#L209","def":{"name":"refused?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"self.refused?(value.to_s)"}},{"id":"refused?(value:String):Bool-class-method","html_id":"refused?(value:String):Bool-class-method","name":"refused?","doc":"Validates that the *value* `String` is the representation of a refusal.\n> One of: \"no\", \"n\", \"off\", \"0\", \"false\"\n- See also `#accepted?`.","summary":"

Validates that the 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","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/presence.cr#L200","def":{"name":"refused?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"self.in?(value.downcase, [\"no\", \"n\", \"off\", \"0\", \"false\"])"}},{"id":"size?(value,size:Array(String))-class-method","html_id":"size?(value,size:Array(String))-class-method","name":"size?","doc":"Validates that the *value* is in the *size* array.\n- See also `#between?`.","summary":"

Validates that the value is in the size array.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"size","doc":null,"default_value":"","external_name":"size","restriction":"Array(String)"}],"args_string":"(value, size : Array(String))","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/comparisons.cr#L122","def":{"name":"size?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"size","doc":null,"default_value":"","external_name":"size","restriction":"Array(String)"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"size.includes?(value.size.to_s)"}},{"id":"size?(value,size:Array(Int))-class-method","html_id":"size?(value,size:Array(Int))-class-method","name":"size?","doc":"Validates that the *value* is in the *size* array.\n- See also `#between?`.","summary":"

Validates that the value is in the size array.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"size","doc":null,"default_value":"","external_name":"size","restriction":"Array(Int)"}],"args_string":"(value, size : Array(Int))","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/comparisons.cr#L117","def":{"name":"size?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"size","doc":null,"default_value":"","external_name":"size","restriction":"Array(Int)"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"size.includes?(value.size)"}},{"id":"size?(value,size:Range)-class-method","html_id":"size?(value,size:Range)-class-method","name":"size?","doc":"Validates that the *value* is in the *size* range.\n- See also `#between?`.","summary":"

Validates that the value is in the size range.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"size","doc":null,"default_value":"","external_name":"size","restriction":"Range"}],"args_string":"(value, size : Range)","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/comparisons.cr#L111","def":{"name":"size?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"size","doc":null,"default_value":"","external_name":"size","restriction":"Range"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"size.includes?(value.size)"}},{"id":"size?(value,size:String)-class-method","html_id":"size?(value,size:String)-class-method","name":"size?","doc":"Validates that the *value* is equal to the *size*.","summary":"

Validates that the value is equal to the size.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"size","doc":null,"default_value":"","external_name":"size","restriction":"String"}],"args_string":"(value, size : String)","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/comparisons.cr#L105","def":{"name":"size?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"size","doc":null,"default_value":"","external_name":"size","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"value.size.to_s == size"}},{"id":"size?(value,size:Int)-class-method","html_id":"size?(value,size:Int)-class-method","name":"size?","doc":"Validates that the *value* is equal to the *size*.","summary":"

Validates that the value is equal to the size.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"size","doc":null,"default_value":"","external_name":"size","restriction":"Int"}],"args_string":"(value, size : Int)","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/comparisons.cr#L100","def":{"name":"size?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"size","doc":null,"default_value":"","external_name":"size","restriction":"Int"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"value.size == size"}},{"id":"slug?(value:String,min=1,max=100):Bool-class-method","html_id":"slug?(value:String,min=1,max=100):Bool-class-method","name":"slug?","doc":"Validates that the *value* is a slug.","summary":"

Validates that the value is a slug.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"min","doc":null,"default_value":"1","external_name":"min","restriction":""},{"name":"max","doc":null,"default_value":"100","external_name":"max","restriction":""}],"args_string":"(value : String, min = 1, max = 100) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/uri.cr#L171","def":{"name":"slug?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"min","doc":null,"default_value":"1","external_name":"min","restriction":""},{"name":"max","doc":null,"default_value":"100","external_name":"max","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!value.match(/^([a-zA-Z0-9_-]{#{min},#{max}})$/).nil?"}},{"id":"starts?(value:String,search:Char):Bool-class-method","html_id":"starts?(value:String,search:Char):Bool-class-method","name":"starts?","doc":"Validates that the `String` *value* starts with *search*.\n- See also `#ends?`.\n- See also `#match?`.\n- See also `#in?`.","summary":"

Validates that the 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","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/presence.cr#L226","def":{"name":"starts?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"search","doc":null,"default_value":"","external_name":"search","restriction":"Char"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value.starts_with?(search)"}},{"id":"starts?(value:String,search:Regex):Bool-class-method","html_id":"starts?(value:String,search:Regex):Bool-class-method","name":"starts?","doc":"Validates that the `String` *value* starts with *search*.\n- See also `#ends?`.\n- See also `#match?`.\n- See also `#in?`.","summary":"

Validates that the 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","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/presence.cr#L231","def":{"name":"starts?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"search","doc":null,"default_value":"","external_name":"search","restriction":"Regex"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value.starts_with?(search)"}},{"id":"starts?(value:String,search:String):Bool-class-method","html_id":"starts?(value:String,search:String):Bool-class-method","name":"starts?","doc":"Validates that the `String` *value* starts with *search*.\n- See also `#ends?`.\n- See also `#match?`.\n- See also `#in?`.","summary":"

Validates that the 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","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/presence.cr#L221","def":{"name":"starts?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"search","doc":null,"default_value":"","external_name":"search","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value.starts_with?(search)"}},{"id":"time?(value:String):Bool-class-method","html_id":"time?(value:String):Bool-class-method","name":"time?","doc":"Validates that the *value* is a time `String` representation.","summary":"

Validates that the value is a time String representation.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/format.cr#L31","def":{"name":"time?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"(!value.blank?) && (!value.match(@@rx_time).nil?)"}},{"id":"upper?(value:String):Bool-class-method","html_id":"upper?(value:String):Bool-class-method","name":"upper?","doc":"Validates that the *value* is in upper case.","summary":"

Validates that the value is in upper case.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/case_sensitive.cr#L15","def":{"name":"upper?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"(!value.blank?) && (value.upcase === value)"}},{"id":"url?(value:String):Bool-class-method","html_id":"url?(value:String):Bool-class-method","name":"url?","doc":"Validates that the *value* is a URL.","summary":"

Validates that the value is a URL.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/uri.cr#L52","def":{"name":"url?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"size = value.size\nif ((size >= 2083 || size < 11) || (value.match(/[\\s<>]/))) || (value.starts_with?(\"mailto:\"))\n return false\nend\nif m = value.match(@@rx_url)\nelse\n return false\nend\nif self.domain?(\"#{m[\"name\"]}.#{m[\"ext\"]}\")\nelse\n return false\nend\nsp = (value.gsub(/^http(?:s)?:\\/\\//, \"\")).split(\":\")\nif sp.size > 1\n if m_port = sp[1].match(/^[0-9]+/)\n else\n return true\n end\n return self.port?(m_port[0])\nend\ntrue\n"}},{"id":"uuid?(value:String,version=0):Bool-class-method","html_id":"uuid?(value:String,version=0):Bool-class-method","name":"uuid?","doc":"Validates that the *value* is a *UUID*\nVersions: 0 (all), 3, 4 and 5. *version* by default is 0 (all).","summary":"

Validates that the value is a UUID Versions: 0 (all), 3, 4 and 5.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"version","doc":null,"default_value":"0","external_name":"version","restriction":""}],"args_string":"(value : String, version = 0) : Bool","source_link":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validators/format.cr#L103","def":{"name":"uuid?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"version","doc":null,"default_value":"0","external_name":"version","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"if @@rx_uuid.has_key?(version)\nelse\n return false\nend\n!value.match(@@rx_uuid[version]).nil?\n"}}],"constructors":[],"instance_methods":[],"macros":[],"types":[{"html_id":"validator/Validator/Error","path":"Validator/Error.html","kind":"class","full_name":"Validator::Error","name":"Error","abstract":false,"superclass":{"html_id":"validator/Exception","kind":"class","full_name":"Exception","name":"Exception"},"ancestors":[{"html_id":"validator/Exception","kind":"class","full_name":"Exception","name":"Exception"},{"html_id":"validator/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"validator/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"src/validator.cr","line_number":120,"url":"https://github.com/Nicolab/crystal-validator/blob/fe0d31532016b14d61671178767dc58de67ba1b2/src/validator.cr#L120"}],"repository_name":"validator","program":false,"enum":false,"alias":false,"aliased":"","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"validator/Validator","kind":"module","full_name":"Validator","name":"Validator"},"doc":"Used by `is!` when a validation is not `true`.","summary":"

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/toplevel.html b/docs/toplevel.html new file mode 100644 index 0000000..e5cb652 --- /dev/null +++ b/docs/toplevel.html @@ -0,0 +1,268 @@ + + + + + + + + + + + + + + + + + Top Level Namespace - validator master + + + + + + + +
+

+ + Top Level Namespace + +

+ + + + + + + + + + + + + + + + + + +

+ + + + Defined in: +

+ + + + + + + + + + + + +

+ + + + Macro Summary +

+ + + + +
+ +
+ + + + + + + + +

+ + + + Macro Detail +

+ +
+
+ + macro is(name, *args) + + # +
+ +
+ +

An (optional) expressive flavor of Validator (or Valid alias). +Not exposed by default, must be imported:

+ +
require "validator/is"
+
+is :email?, "contact@example.org"                        # => true
+is "email?", "contact@example.org"                       # => true
+is :url?, "https://github.com/Nicolab/crystal-validator" # => true
+
+ +
+
+ + [View source] + +
+
+ +
+
+ + macro is!(name, *args) + + # +
+ +
+ +

Same as is but raise a Validator::Error +displaying an inspection if the validation is false. +Useful for the unit tests :)

+
+ +
+
+ + [View source] + +
+
+ + + +
+ + +