validate_specific_value 0.2.1 → 0.3.0
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 +17 -3
- data/lib/validate_specific_value/model.rb +4 -6
- data/lib/validate_specific_value/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eba2b32a298365358878cd5e38acc5dca357f3f5165de150fe2a49ce0a1c3eb8
|
4
|
+
data.tar.gz: f776085436cc19d14ab160f7dee169dc0f0b4671d8c11fdf0d563b76e9ced752
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 991303fda26deab88ac2483ff9186f15955dbb1006fb1094685d6487b99170c0981d9f127e1933b9b3c121a2a80d2a19ff5e71fc395c5332d2ae2c13036a7988
|
7
|
+
data.tar.gz: 7ba5f676dbb4fecd7510e1b40c44a3a1da6536cd9625d00f1ab5d2c7598b028ebe00752a56c62248e6a0d32d08c42547d0808e7dc1138d7ae781e6f4d7b79ee3
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -26,9 +26,7 @@ class User < ApplicationRecord
|
|
26
26
|
end
|
27
27
|
```
|
28
28
|
|
29
|
-
|
30
|
-
|
31
|
-
#### Accessor Methods
|
29
|
+
## Accessor Methods
|
32
30
|
|
33
31
|
Instance context:
|
34
32
|
|
@@ -49,6 +47,22 @@ User.valid_name?('duplicate_name')
|
|
49
47
|
# => false
|
50
48
|
```
|
51
49
|
|
50
|
+
## Implementation
|
51
|
+
|
52
|
+
The implementation is quite simple.
|
53
|
+
|
54
|
+
```ruby
|
55
|
+
class User < ApplicationRecord
|
56
|
+
def valid_name?
|
57
|
+
errors.clear
|
58
|
+
self.class.validators_on(:name).each do |validator|
|
59
|
+
validator.validate_each(self, :name, self[:name])
|
60
|
+
end
|
61
|
+
errors.empty?
|
62
|
+
end
|
63
|
+
end
|
64
|
+
```
|
65
|
+
|
52
66
|
## Contributing
|
53
67
|
|
54
68
|
Everyone is encouraged to help improve this project. Here are a few ways you can help:
|
@@ -5,12 +5,11 @@ module ValidateSpecificValue
|
|
5
5
|
extend ActiveSupport::Concern
|
6
6
|
|
7
7
|
class_methods do
|
8
|
-
# def valid_[attribute]? ... end
|
9
|
-
# def self.valid_[attribute]?(value) ... end
|
10
8
|
def validates_specific(column)
|
11
9
|
column = column.to_sym
|
12
10
|
method_name = "valid_#{column}?"
|
13
11
|
|
12
|
+
# def valid_[attribute]? ... end
|
14
13
|
unless method_defined?(method_name)
|
15
14
|
define_method method_name do
|
16
15
|
errors.clear
|
@@ -21,11 +20,10 @@ module ValidateSpecificValue
|
|
21
20
|
end
|
22
21
|
end
|
23
22
|
|
23
|
+
# def self.valid_[attribute]?(value) ... end
|
24
24
|
define_singleton_method method_name do |value, errors = {}|
|
25
|
-
instance = self.new
|
26
|
-
|
27
|
-
validator.validate_each(instance, column, value)
|
28
|
-
end
|
25
|
+
instance = self.new(column => value)
|
26
|
+
instance.send(method_name)
|
29
27
|
errors[column] = instance.errors[column]
|
30
28
|
errors[column].empty?
|
31
29
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: validate_specific_value
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ts-3156
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-12-
|
11
|
+
date: 2018-12-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|