Skip to content

Commit

Permalink
Add example usages to AVD::Constraints docs (#483)
Browse files Browse the repository at this point in the history
  • Loading branch information
tamdaz authored Dec 14, 2024
1 parent c7fa026 commit 3bcaa0b
Show file tree
Hide file tree
Showing 30 changed files with 331 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/components/validator/src/constraints/blank.cr
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# Validates that a value is blank; meaning equal to an empty string or `nil`.
#
# ```
# class Profile
# include AVD::Validatable
#
# def initialize(@username : String); end
#
# @[Assert::NotBlank]
# property username : String
# end
# ```
#
# # Configuration
#
# ## Optional Arguments
Expand Down
11 changes: 11 additions & 0 deletions src/components/validator/src/constraints/choice.cr
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
# Validates that a value is one of a given set of valid choices;
# can also be used to validate that each item in a collection is one of those valid values.
#
# ```
# class User
# include AVD::Validatable
#
# def initialize(@role : String); end
#
# @[Assert::Choice(["member", "moderator", "admin"])]
# property role : String
# end
# ```
#
# # Configuration
#
# ## Required Arguments
Expand Down
11 changes: 11 additions & 0 deletions src/components/validator/src/constraints/email.cr
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@
# NOTE: As with most other constraints, `nil` and empty strings are considered valid values, in order to allow the value to be optional.
# If the value is required, consider combining this constraint with `AVD::Constraints::NotBlank`.
#
# ```
# class User
# include AVD::Validatable
#
# def initialize(@email : String); end
#
# @[Assert::Email]
# property email : String
# end
# ```
#
# # Configuration
#
# ## Optional Arguments
Expand Down
11 changes: 11 additions & 0 deletions src/components/validator/src/constraints/equal_to.cr
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# Validates that a value is equal to another.
#
# ```
# class Project
# include AVD::Validatable
#
# def initialize(@name : String); end
#
# @[Assert::EqualTo("Athena")]
# property name : String
# end
# ```
#
# # Configuration
#
# ## Required Arguments
Expand Down
11 changes: 11 additions & 0 deletions src/components/validator/src/constraints/file.cr
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,17 @@ require "mime"
# NOTE: As with most other constraints, `nil` and empty strings are considered valid values, in order to allow the value to be optional.
# If the value is required, consider combining this constraint with `AVD::Constraints::NotBlank`.
#
# ```
# class Profile
# include AVD::Validatable
#
# def initialize(@resume : ::File); end
#
# @[Assert::File]
# property resume : ::File
# end
# ```
#
# # Configuration
#
# ## Optional Arguments
Expand Down
11 changes: 11 additions & 0 deletions src/components/validator/src/constraints/greater_than.cr
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# Validates that a value is greater than another.
#
# ```
# class Person
# include AVD::Validatable
#
# def initialize(@age : Int64); end
#
# @[Assert::GreaterThan(18)]
# property age : Int64
# end
# ```
#
# # Configuration
#
# ## Required Arguments
Expand Down
11 changes: 11 additions & 0 deletions src/components/validator/src/constraints/greater_than_or_equal.cr
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# Validates that a value is greater than or equal to another.
#
# ```
# class Person
# include AVD::Validatable
#
# def initialize(@age : Int64); end
#
# @[Assert::GreaterThanOrEqual(18)]
# property age : Int64
# end
# ```
#
# # Configuration
#
# ## Required Arguments
Expand Down
11 changes: 11 additions & 0 deletions src/components/validator/src/constraints/image.cr
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,17 @@ require "athena-image_size"
#
# See `AVD::Constraints::File` for common documentation.
#
# ```
# class Profile
# include AVD::Validatable
#
# def initialize(@avatar : ::File); end
#
# @[Assert::Image]
# property avatar : ::File
# end
# ```
#
# # Configuration
#
# ## Optional Arguments
Expand Down
11 changes: 11 additions & 0 deletions src/components/validator/src/constraints/ip.cr
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,17 @@ require "socket"
# NOTE: As with most other constraints, `nil` and empty strings are considered valid values, in order to allow the value to be optional.
# If the value is required, consider combining this constraint with `AVD::Constraints::NotBlank`.
#
# ```
# class Machine
# include AVD::Validatable
#
# def initialize(@ip_address : String); end
#
# @[Assert::IP]
# property ip_address : String
# end
# ```
#
# # Configuration
#
# ## Optional Arguments
Expand Down
11 changes: 11 additions & 0 deletions src/components/validator/src/constraints/is_false.cr
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# Validates that a value is `false`.
#
# ```
# class Post
# include AVD::Validatable
#
# def initialize(@is_published : Bool); end
#
# @[Assert::IsFalse]
# property is_published : Bool
# end
# ```
#
# # Configuration
#
# ## Optional Arguments
Expand Down
11 changes: 11 additions & 0 deletions src/components/validator/src/constraints/is_nil.cr
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# Validates that a value is `nil`.
#
# ```
# class Post
# include AVD::Validatable
#
# def initialize(@updated_at : Time?); end
#
# @[Assert::IsNil]
# property updated_at : Time?
# end
# ```
#
# # Configuration
#
# ## Optional Arguments
Expand Down
11 changes: 11 additions & 0 deletions src/components/validator/src/constraints/is_true.cr
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# Validates that a value is `true`.
#
# ```
# class Post
# include AVD::Validatable
#
# def initialize(@is_published : Bool); end
#
# @[Assert::IsTrue]
# property is_published : Bool
# end
# ```
#
# # Configuration
#
# ## Optional Arguments
Expand Down
11 changes: 11 additions & 0 deletions src/components/validator/src/constraints/isbn.cr
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@
# NOTE: As with most other constraints, `nil` and empty strings are considered valid values, in order to allow the value to be optional.
# If the value is required, consider combining this constraint with `AVD::Constraints::NotBlank`.
#
# ```
# class Book
# include AVD::Validatable
#
# def initialize(@isbn : String); end
#
# @[Assert::ISBN]
# property isbn : String
# end
# ```
#
# # Configuration
#
# ## Optional Arguments
Expand Down
10 changes: 10 additions & 0 deletions src/components/validator/src/constraints/isin.cr
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@
# NOTE: As with most other constraints, `nil` and empty strings are considered valid values, in order to allow the value to be optional.
# If the value is required, consider combining this constraint with `AVD::Constraints::NotBlank`.
#
# ```
# class UnitAccount
# include AVD::Validatable
#
# def initialize(@isin : String); end
#
# @[Assert::ISIN]
# property isin : String
# end
# ```
# # Configuration
#
# ## Optional Arguments
Expand Down
11 changes: 11 additions & 0 deletions src/components/validator/src/constraints/issn.cr
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@
# NOTE: As with most other constraints, `nil` and empty strings are considered valid values, in order to allow the value to be optional.
# If the value is required, consider combining this constraint with `AVD::Constraints::NotBlank`.
#
# ```
# class Journal
# include AVD::Validatable
#
# def initialize(@isin : String); end
#
# @[Assert::ISSN]
# property issn : String
# end
# ```
#
# # Configuration
#
# ## Optional Arguments
Expand Down
11 changes: 11 additions & 0 deletions src/components/validator/src/constraints/less_than.cr
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# Validates that a value is less than another.
#
# ```
# class Employee
# include AVD::Validatable
#
# def initialize(@age : Number); end
#
# @[Assert::LessThan(60)]
# property age : Number
# end
# ```
#
# # Configuration
#
# ## Required Arguments
Expand Down
11 changes: 11 additions & 0 deletions src/components/validator/src/constraints/less_than_or_equal.cr
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# Validates that a value is less than or equal to another.
#
# ```
# class Employee
# include AVD::Validatable
#
# def initialize(@age : Number); end
#
# @[Assert::LessThanOrEqual(60)]
# property age : Number
# end
# ```
#
# # Configuration
#
# ## Required Arguments
Expand Down
11 changes: 11 additions & 0 deletions src/components/validator/src/constraints/luhn.cr
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@
# NOTE: As with most other constraints, `nil` and empty strings are considered valid values, in order to allow the value to be optional.
# If the value is required, consider combining this constraint with `AVD::Constraints::NotBlank`.
#
# ```
# class Transaction
# include AVD::Validatable
#
# def initialize(@card_number : String); end
#
# @[Assert::Luhn]
# property card_number : String
# end
# ```
#
# # Configuration
#
# ## Optional Arguments
Expand Down
11 changes: 11 additions & 0 deletions src/components/validator/src/constraints/negative.cr
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
# Validates that a value is a negative number.
# Use `AVD::Constraints::NegativeOrZero` if you wish to also allow `0`.
#
# ```
# class Mall
# include AVD::Validatable
#
# def initialize(@lowest_floor : Number); end
#
# @[Assert::Negative]
# property lowest_floor : Number
# end
# ```
#
# # Configuration
#
# ## Optional Arguments
Expand Down
11 changes: 11 additions & 0 deletions src/components/validator/src/constraints/negative_or_zero.cr
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
# Validates that a value is a negative number, or `0`.
# Use `AVD::Constraints::Negative` if you don't want to allow `0`.
#
# ```
# class Mall
# include AVD::Validatable
#
# def initialize(@lowest_floor : Number); end
#
# @[Assert::NegativeOrZero]
# property lowest_floor : Number
# end
# ```
#
# # Configuration
#
# ## Optional Arguments
Expand Down
11 changes: 11 additions & 0 deletions src/components/validator/src/constraints/not_blank.cr
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# Validates that a value is not blank; meaning not equal to a blank string, an empty `Iterable`, `false`, or optionally `nil`.
#
# ```
# class User
# include AVD::Validatable
#
# def initialize(@name : String); end
#
# @[Assert::NotBlank]
# property name : String
# end
# ```
#
# # Configuration
#
# ## Optional Arguments
Expand Down
11 changes: 11 additions & 0 deletions src/components/validator/src/constraints/not_equal_to.cr
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# Validates that a value is not equal to another.
#
# ```
# class User
# include AVD::Validatable
#
# def initialize(@name : String); end
#
# @[Assert::NotEqualTo("John Doe")]
# property name : String
# end
# ```
#
# # Configuration
#
# ## Required Arguments
Expand Down
Loading

0 comments on commit 3bcaa0b

Please sign in to comment.