fanforce-validations 0.2 → 0.3
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 +18 -1
- 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
|
+
NDc0ZDM4N2ZjOTk0MjFhYTYwMjQ4OWVhNzEyNjJhNzllODgyZTQ3Yw==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NDJhYzcyNmQ5MDdlMTZjYjZiYTM0ZjU3OTVkZmFmMGI0MDI4NTdmZA==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
NDMyYmMwZWM3NjA0NzlkYWE0YTg0NjQxNDA2MDZlMjQ5MmQ5ZDc4Y2M4MmFk
|
10
|
+
YWRmOTA2ZTM4MDkzMzVmMGFmMmFmNjI1Njg5ZmVkMDFmN2ZiNDAzOTM5Mjhj
|
11
|
+
MDY1ZTc1MmZhZDUxOThmMGY1MTgzM2MzYWEyM2RiMDI4MTBlOGI=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ZTBmY2ZjYjVlOTcyZWFmZTFlM2QyNTQxMWMyNjVkMzQyOGE2MmQ1OTdlM2Qz
|
14
|
+
NDM1ZTYyYTNlMjk1ZDg0OGQ3ODkwZDU2MGE0ZDVjMGE1Nzk4ZmVjZjZhNDQx
|
15
|
+
NjRmODcxM2U2MTI3MWE2YmQ4ZTM3ZTg4YTgyM2YxMjBjYTIwOGU=
|
@@ -36,7 +36,7 @@ module Fanforce::Validations
|
|
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
|
+
alias :validates_presence_of :validates_presence_of_all
|
40
40
|
|
41
41
|
def validates_presence_of_any(*args)
|
42
42
|
opts = extract_options!(args)
|
@@ -72,6 +72,23 @@ module Fanforce::Validations
|
|
72
72
|
raise_validation_errors(opts, errors, Fanforce::Error::RequestFailed)
|
73
73
|
end
|
74
74
|
|
75
|
+
def validates_external_id_format(*args)
|
76
|
+
opts = extract_options!(args).merge(:field => :_external_id)
|
77
|
+
params = extract_validation_params(opts)
|
78
|
+
_external_id = args
|
79
|
+
|
80
|
+
if is_present?(_external_id) and !_external_id.is_a?(String)
|
81
|
+
opts[:message] = "id must be a string but was a #{_external_id.class.name}"
|
82
|
+
elsif _external_id.include('/')
|
83
|
+
opts[:message] = 'id cannot contain forward slashes (/)'
|
84
|
+
else
|
85
|
+
return true
|
86
|
+
end
|
87
|
+
|
88
|
+
error = format_validation_error(opts, :_external_id, :invalid_data)
|
89
|
+
raise_validation_errors(opts, [error], Fanforce::Error::RequestFailed)
|
90
|
+
end
|
91
|
+
|
75
92
|
def format_validation_error(opts, fields, default_error_code=nil)
|
76
93
|
error = {
|
77
94
|
resource: is_present?(opts[:resource]) ? opts[:resource] : (self.class==Class ? self.name.demodulize.tableize.singularize : self.class.name.demodulize.tableize.singularize),
|