fanforce-internal-validations 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/lib/fanforce/validations/validations.rb +9 -11
- data/lib/fanforce/validations/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NzZiODRmZTI2MTU0MDg4ODQwYTgxNzI1YTcyOTZhYWYxMjdjZTNjZg==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NTI1OTQxYjZlOGQxZDk5YTA0NjA3OGI4MmQwNzYxYzgyNDExN2Q4YQ==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MTE0MGU2NmNhODVlMDIyMjk0N2ViNjgwOTAxNTZjNDBhZTA5ZDQ4ZmRhMWRh
|
10
|
+
ZGUwMTgyZmNmZjJkNzA2NjY0NDI2NDAxODEzMTIwYWQ2ZDcwZmQ3MTM2Njc3
|
11
|
+
MTNiZDM3ODg3OWI4YzI4NDQ2Mjc2YTRhYjdiOGE0MjE3NjMyMjE=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ZjI3OWEzMTc1ZmRhZmVjOGYxZmUzM2VmMTljZGU5M2I4NmY1MDcyYTgzMDE0
|
14
|
+
ZjBhMDQ5MzBiMDcwNGEyNTE3NDM4MWZlNGU3OWViMmU1Y2VjNjE4NGM5OGVi
|
15
|
+
ZDc4ODgyMTQxM2NlZWM4ZTYzNGFhZThhMGVhMTQwNGIyMDk0MDg=
|
@@ -20,7 +20,7 @@ module Fanforce::Validations
|
|
20
20
|
name.to_sym
|
21
21
|
end
|
22
22
|
|
23
|
-
def
|
23
|
+
def validates_presence_of_all(*args)
|
24
24
|
opts = extract_options!(args)
|
25
25
|
params = extract_validation_params(opts)
|
26
26
|
fields_to_validate = args.is_a?(Array) ? args : [args]
|
@@ -34,8 +34,9 @@ module Fanforce::Validations
|
|
34
34
|
return true if invalid_fields.size == 0
|
35
35
|
|
36
36
|
errors = invalid_fields.inject([]) {|result, f| result << format_validation_error(opts, f, :missing_field) }
|
37
|
-
|
37
|
+
raise_validation_errors(opts, errors, Fanforce::Error::BadRequest)
|
38
38
|
end
|
39
|
+
alias validates_presence_of validates_presence_of_all
|
39
40
|
|
40
41
|
def validates_presence_of_any(*args)
|
41
42
|
opts = extract_options!(args)
|
@@ -51,12 +52,9 @@ module Fanforce::Validations
|
|
51
52
|
return true if invalid_fields.size < fields_to_validate.size
|
52
53
|
|
53
54
|
errors = [format_validation_error(opts, invalid_fields, :invalid_data)]
|
54
|
-
|
55
|
+
raise_validation_errors(opts, errors, Fanforce::Error::BadRequest)
|
55
56
|
end
|
56
57
|
|
57
|
-
def validates_presence_of_all(*args)
|
58
|
-
validates_presence_of(args)
|
59
|
-
end
|
60
58
|
|
61
59
|
def validates_true(*args)
|
62
60
|
opts = extract_options!(args)
|
@@ -72,11 +70,7 @@ module Fanforce::Validations
|
|
72
70
|
return true if invalid_fields.size == 0
|
73
71
|
|
74
72
|
errors = invalid_fields.inject([]) {|result, f| result << format_validation_error(opts, f, :invalid_data) }
|
75
|
-
|
76
|
-
end
|
77
|
-
|
78
|
-
def raise_validation_error(opts, errors, default_error_class)
|
79
|
-
raise (opts[:error_class] || default_error_class).new(errors)
|
73
|
+
raise_validation_errors(opts, errors, Fanforce::Error::RequestFailed)
|
80
74
|
end
|
81
75
|
|
82
76
|
def format_validation_error(opts, fields, default_error_code=nil)
|
@@ -88,6 +82,10 @@ module Fanforce::Validations
|
|
88
82
|
fields.is_a?(Array) ? error.update(fields: fields) : error.update(field: fields)
|
89
83
|
end
|
90
84
|
|
85
|
+
def raise_validation_errors(opts, errors, default_error_class)
|
86
|
+
raise (opts[:error_class] || default_error_class).new(*errors)
|
87
|
+
end
|
88
|
+
|
91
89
|
def extract_options!(args)
|
92
90
|
if args.last.is_a?(::Hash)
|
93
91
|
opts = args.pop.symbolize_keys
|