active_model_validations_reflection 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +5 -3
- data/lib/active_model/validations/reflection.rb +8 -0
- data/lib/active_model_validations_reflection/version.rb +1 -1
- 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: a2157bd5ce0dd6c8eaec27072fa186ac7bd93409ba32df041a86f5fe583cf208
|
4
|
+
data.tar.gz: e6d3f51343264ec744d0395dc090a416a13f1a5fc039caaa9e8aba1384f91816
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8e0b853c7190f4bcda9791ba89ad92ab3fd8c8c7806c46dc2bf9e346750543af003f09e5751a40ea4b4c0e894e03947d5b47a03dcd57791981f00296e8e6a710
|
7
|
+
data.tar.gz: 7318a479b2b89410b6499ec1388a84b515b5d32deb31e83c9147bce2cfb2873dc303e8978fc0fd39955503b9dba62ef290552dc070eb59ab75d14493b09c8e22
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -7,7 +7,7 @@
|
|
7
7
|
|
8
8
|
## Installation
|
9
9
|
|
10
|
-
`
|
10
|
+
`ActiveModel::Validations::Reflection` is distributed as a gem and available on [rubygems.org](https://rubygems.org/gems/active_model_validations_reflection) so you can add it to your `Gemfile` or install it manually with:
|
11
11
|
|
12
12
|
```ruby
|
13
13
|
gem install active_model_validations_reflection
|
@@ -61,9 +61,9 @@ Article.validators_on_of_kinds(:date, :timeliness)
|
|
61
61
|
# => []
|
62
62
|
```
|
63
63
|
|
64
|
-
### `#relevant_validators_on(attribute, *kinds)`
|
64
|
+
### `#relevant_validators(*kinds)` & `#relevant_validators_on(attribute, *kinds)`
|
65
65
|
|
66
|
-
Returns validator that will be applied
|
66
|
+
Returns validator that will be applied considering the instance current state: flat validators and conditional validators whose condition is met.
|
67
67
|
|
68
68
|
```ruby
|
69
69
|
class Article < ApplicationRecord
|
@@ -77,6 +77,8 @@ class Article < ApplicationRecord
|
|
77
77
|
end
|
78
78
|
|
79
79
|
article = Article.new
|
80
|
+
article.relevant_validators
|
81
|
+
# => [#<ActiveModel::Validations::PresenceValidator […]>]
|
80
82
|
article.relevant_validators_on(:date)
|
81
83
|
# => [#<ActiveModel::Validations::PresenceValidator […]>]
|
82
84
|
|
@@ -59,6 +59,14 @@ module ActiveModel
|
|
59
59
|
end
|
60
60
|
end
|
61
61
|
|
62
|
+
def relevant_validators(*kinds)
|
63
|
+
self.class.validators_of_kinds(*kinds).select do |validator|
|
64
|
+
next true if Helpers.flat_validator?(validator)
|
65
|
+
|
66
|
+
Helpers.relevant_validator?(validator, self)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
62
70
|
def relevant_validators_on(attribute, *kinds)
|
63
71
|
self.class.validators_on_of_kinds(attribute, *kinds).select do |validator|
|
64
72
|
next true if Helpers.flat_validator?(validator)
|