database_validations 0.9.2 → 0.9.3
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 37040902b8f9dd94cbfcc1785129eff2ac2f75eb085f567299852a03f4a83cfa
|
4
|
+
data.tar.gz: c6a2a3331225b8344c23244692296a982ed25405be15650c32bc0815e227c20a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 27f9f74a6f081f343bbe94da77956cd0c06419dcf321d2576a6238f0b2bddb5dd967861deaffe88ab47929e4b3837825fc9c17bf95b4fba83f5fbfd4b07d04e0
|
7
|
+
data.tar.gz: 86f379332348da451c1f2d02e3e4096e528f9e00c25f10fdb8881512d97c10ffdf9ab5cffdc3f4e9ce6ea475e0d3d0a0d75b728fed700f7606ccf07cacfe9bdf
|
@@ -24,13 +24,19 @@ module DatabaseValidations
|
|
24
24
|
keys.each do |key|
|
25
25
|
attribute_validator = instance._db_validators[key]
|
26
26
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
end
|
27
|
+
next unless attribute_validator
|
28
|
+
|
29
|
+
return process_validator(instance, attribute_validator)
|
31
30
|
end
|
32
31
|
|
33
32
|
false
|
34
33
|
end
|
34
|
+
|
35
|
+
def process_validator(instance, attribute_validator)
|
36
|
+
return false unless attribute_validator.validator.perform_db_validation?
|
37
|
+
|
38
|
+
attribute_validator.validator.apply_error(instance, attribute_validator.attribute)
|
39
|
+
true
|
40
|
+
end
|
35
41
|
end
|
36
42
|
end
|
@@ -1,5 +1,7 @@
|
|
1
1
|
module DatabaseValidations
|
2
2
|
class DbUniquenessValidator < ActiveRecord::Validations::UniquenessValidator
|
3
|
+
DEFAULT_MODE = :optimized
|
4
|
+
|
3
5
|
attr_reader :index_name, :where, :klass
|
4
6
|
|
5
7
|
# Used to make 3rd party libraries work correctly
|
@@ -19,8 +21,7 @@ module DatabaseValidations
|
|
19
21
|
options[:conditions] = -> { where(condition) }
|
20
22
|
end
|
21
23
|
|
22
|
-
|
23
|
-
@where = options.delete(:where) if options.key?(:where)
|
24
|
+
handle_custom_options(options)
|
24
25
|
|
25
26
|
super
|
26
27
|
|
@@ -28,8 +29,12 @@ module DatabaseValidations
|
|
28
29
|
Checkers::DbUniquenessValidator.validate!(self)
|
29
30
|
end
|
30
31
|
|
32
|
+
def perform_db_validation?
|
33
|
+
@mode != :standard
|
34
|
+
end
|
35
|
+
|
31
36
|
def validate(record)
|
32
|
-
super if record._database_validations_fallback
|
37
|
+
super if perform_query? || record._database_validations_fallback
|
33
38
|
end
|
34
39
|
|
35
40
|
def apply_error(instance, attribute)
|
@@ -38,6 +43,18 @@ module DatabaseValidations
|
|
38
43
|
|
39
44
|
instance.errors.add(attribute, :taken, error_options)
|
40
45
|
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
def handle_custom_options(options)
|
50
|
+
@index_name = options.delete(:index_name) if options.key?(:index_name)
|
51
|
+
@where = options.delete(:where) if options.key?(:where)
|
52
|
+
@mode = (options.delete(:mode).presence || DEFAULT_MODE).to_sym
|
53
|
+
end
|
54
|
+
|
55
|
+
def perform_query?
|
56
|
+
@mode != :optimized
|
57
|
+
end
|
41
58
|
end
|
42
59
|
|
43
60
|
module ClassMethods
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: database_validations
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Evgeniy Demin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-09-
|
11
|
+
date: 2020-09-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -223,7 +223,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
223
223
|
- !ruby/object:Gem::Version
|
224
224
|
version: '0'
|
225
225
|
requirements: []
|
226
|
-
rubygems_version: 3.
|
226
|
+
rubygems_version: 3.0.8
|
227
227
|
signing_key:
|
228
228
|
specification_version: 4
|
229
229
|
summary: Provide compatibility between database constraints and ActiveRecord validations
|