-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathathena-validator.cr
More file actions
101 lines (83 loc) · 2.77 KB
/
Copy pathathena-validator.cr
File metadata and controls
101 lines (83 loc) · 2.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
require "json"
require "./constraint"
require "./constraint_validator"
require "./constraint_validator_factory"
require "./constraint_validator_factory_interface"
require "./constraint_validator_interface"
require "./execution_context"
require "./execution_context_interface"
require "./property_path"
require "./validatable"
require "./constraints/abstract_comparison"
require "./constraints/abstract_comparison_validator"
require "./constraints/*"
require "./exception/*"
require "./metadata/*"
require "./validator/*"
require "./violation/*"
# Convenience alias to make referencing `Athena::Validator` types easier.
alias AVD = Athena::Validator
# Used to apply constraints to instance variables and types via annotations.
#
# ```
# @[Assert::NotBlank]
# property name : String
# ```
# NOTE: Constraints, including custom ones, are automatically added to this namespace.
alias Assert = AVD::Annotations
module Athena; end
# Provides a robust object/value validation framework.
module Athena::Validator
VERSION = "0.5.0"
# :nodoc:
#
# Default namespace for constraint annotations.
#
# NOTE: Constraints, including custom ones, are automatically added to this namespace.
module Annotations; end
# Contains all of the built in `AVD::Constraint`s.
# See each individual constraint for more information.
# The `Assert` alias is used to apply these constraints via annotations.
module Constraints; end
# Both acts as a namespace for exceptions related to the `Athena::Validator` component, as well as a way to check for exceptions from the component.
module Exception; end
# Contains types used to store metadata associated with a given `AVD::Validatable` instance.
#
# Most likely you won't have to work any of these directly.
# However if you are adding constraints manually to properties using the `self.load_metadata` method,
# you should be familiar with `AVD::Metadata::ClassMetadata`.
module Metadata; end
# Contains types related to the validator itself.
module Validator; end
# Contains types related to constraint violations.
module Violation; end
# :nodoc:
abstract struct Container
abstract def type_name : String
def inspect(io : IO) : Nil
io << "#<AVD::Container(" << self.type_name << ")>"
end
end
# :nodoc:
record ValueContainer(T) < Container, value : T do
def value_type : T.class
T
end
def type_name : String
{{ T.stringify }}
end
def ==(other : AVD::Container) : Bool
@value == other.value
end
end
# Returns a new `AVD::Validator::ValidatorInterface`.
#
# ```
# validator = AVD.validator
#
# validator.validate "foo", AVD::Constraints::NotBlank.new
# ```
def self.validator : AVD::Validator::ValidatorInterface
AVD::Validator::RecursiveValidator.new
end
end