validy 1.0.9 → 1.0.99
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/validy.rb +12 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d89bc7ec77c5a43d71df94fa67ed470ec6865eb251779ece8e4cf8d34dd85247
|
4
|
+
data.tar.gz: 3e8e93f9566766992b46c30db7e9b1013eb55d758b3a8524775545ed7c0bdad2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9eb955a7874c1df5da04f1f5ab99a8f5d5c84bbbc58f12532f8f69ba728559af93adcd48f4a85bb1117c569586683b9f608bacfba5654a1449b7a0db6850a9ea
|
7
|
+
data.tar.gz: f3c7310ee04b5d41dbf35188afb4ba73a8ac779013636f485caa89afd803e580e846839387bf04e663944de20a561afc4d1b6dd3db5c7a357007fc2a43318f92
|
data/lib/validy.rb
CHANGED
@@ -30,6 +30,8 @@ module Validy
|
|
30
30
|
end
|
31
31
|
|
32
32
|
module ClassMethods
|
33
|
+
# @param [String] method - indicates custom, must be implemented method for which will be triggered for defining
|
34
|
+
# validation state
|
33
35
|
def validy_on(method:)
|
34
36
|
method_with_bang_name = (method[-1] == '!' ? method.to_s : "#{method}!")
|
35
37
|
method_without_bang_name = method_with_bang_name.gsub('!', '')
|
@@ -79,6 +81,9 @@ module Validy
|
|
79
81
|
end
|
80
82
|
|
81
83
|
# "condition" evaluates either passed block or instance method represented in the instance
|
84
|
+
# @param [String|block] method or callable object which will be triggered for validation
|
85
|
+
# @param [String|Hash] error definition
|
86
|
+
# @param [Proc] block
|
82
87
|
def condition(method, error = nil, &block)
|
83
88
|
return self unless valid?
|
84
89
|
|
@@ -88,6 +93,9 @@ module Validy
|
|
88
93
|
end
|
89
94
|
|
90
95
|
# "required" checks presence of the variable
|
96
|
+
# @param [String] attribute a target one
|
97
|
+
# @param [String|Hash] error custom defined error message
|
98
|
+
# @param [Proc] block
|
91
99
|
def required(attribute, error = nil, &block)
|
92
100
|
return self unless valid?
|
93
101
|
|
@@ -97,6 +105,7 @@ module Validy
|
|
97
105
|
end
|
98
106
|
|
99
107
|
# "optional" starts void validation for the given attribute
|
108
|
+
# @param [String] attribute a target one
|
100
109
|
def optional(attribute)
|
101
110
|
return self unless valid?
|
102
111
|
|
@@ -105,6 +114,9 @@ module Validy
|
|
105
114
|
end
|
106
115
|
|
107
116
|
# "type" validates type of the instance variable
|
117
|
+
# @param [Object] clazz for checking type of the target attribute
|
118
|
+
# @param [nil] error custom defined error message
|
119
|
+
# @param [Proc] block
|
108
120
|
def type(clazz, error = nil, &block)
|
109
121
|
return self unless valid?
|
110
122
|
|