failfast_validation 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +5 -1
- data/lib/active_model/failfast_validation.rb +21 -2
- data/lib/failfast_validation.rb +0 -1
- data/lib/failfast_validation/railtie.rb +3 -0
- data/lib/failfast_validation/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2ed85f8452fb52c4df48bcdf17c9ed7e09f88300
|
4
|
+
data.tar.gz: 4f7782e2d03ff3b863f6b4b64224cf5d427ea509
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2abe74e37086d3a5613fe598f06967bffcfca8d643ab95069603c5e76c27e43c8e8bcfac1398594a0f51c05cfdf9b301d2e6d42047d2b1790280301bef2222bf
|
7
|
+
data.tar.gz: f197bca77343a82fb4eda2b13e06f6fe6bb6cd1dad1b34a822c271616e99045b727b0be6f8f0af73c6e593c919992b707b6c95b1ac4d54b29f5b0a3f8dd2bb9c
|
data/README.md
CHANGED
@@ -1,11 +1,15 @@
|
|
1
1
|
# FailfastValidation
|
2
|
-
Failfast mode for ActiveModel::
|
2
|
+
Failfast mode for ActiveModel::EachValidator
|
3
3
|
|
4
4
|
## Usage
|
5
5
|
```rb
|
6
6
|
class YourModel
|
7
7
|
include ActiveModel::Model
|
8
8
|
include ActiveModel::FailfastValidation
|
9
|
+
|
10
|
+
failfast_validation :attr_name
|
11
|
+
|
12
|
+
# validates :attr_name, ....
|
9
13
|
end
|
10
14
|
```
|
11
15
|
|
@@ -4,15 +4,34 @@ module ActiveModel
|
|
4
4
|
|
5
5
|
module EachValidatorExtention
|
6
6
|
def validate_each(record, attribute, value)
|
7
|
-
if record.errors[attribute].empty?
|
7
|
+
if !(respond_to?(:_failfast_validation_attributes) && _failfast_validation_attributes.member?(attribute) && !record.errors[attribute].empty?)
|
8
8
|
super(record, attribute, value)
|
9
9
|
end
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
13
|
included do
|
14
|
+
def self._failfast_validation_attributes
|
15
|
+
@_failfast_validation_attributes ||= []
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.failfast_validation(*attrs)
|
19
|
+
@_failfast_validation_attributes = attrs
|
20
|
+
end
|
21
|
+
|
14
22
|
def valid?(*args)
|
15
|
-
self.class.validators.each
|
23
|
+
self.class.validators.each do |validator|
|
24
|
+
validator.define_singleton_method :_failfast_validation_attributes= do |attrs|
|
25
|
+
@_failfast_validation_attributes = attrs
|
26
|
+
end
|
27
|
+
|
28
|
+
validator.define_singleton_method :_failfast_validation_attributes do
|
29
|
+
@_failfast_validation_attributes
|
30
|
+
end
|
31
|
+
|
32
|
+
validator._failfast_validation_attributes = self.class._failfast_validation_attributes
|
33
|
+
validator.extend(EachValidatorExtention)
|
34
|
+
end
|
16
35
|
|
17
36
|
super(*args)
|
18
37
|
end
|
data/lib/failfast_validation.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: failfast_validation
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shota Iguchi
|
@@ -102,5 +102,5 @@ rubyforge_project:
|
|
102
102
|
rubygems_version: 2.6.14
|
103
103
|
signing_key:
|
104
104
|
specification_version: 4
|
105
|
-
summary: Failfast mode for ActiveModel::
|
105
|
+
summary: Failfast mode for ActiveModel::EachValidator
|
106
106
|
test_files: []
|