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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- OWIzNWUwOTdkMzM5YjFlZDYwNmRiOGY4NjBjZDRhNjVkYzMzYzU0Nw==
4
+ NDc0ZDM4N2ZjOTk0MjFhYTYwMjQ4OWVhNzEyNjJhNzllODgyZTQ3Yw==
5
5
  data.tar.gz: !binary |-
6
- OTExYjI1MzZkZTcwY2VmZjIyZjY0MzhmZTZmOTc2MjZmY2Q4MTAzOQ==
6
+ NDJhYzcyNmQ5MDdlMTZjYjZiYTM0ZjU3OTVkZmFmMGI0MDI4NTdmZA==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- NjQzOWViOTA0N2NjOTNlYmFlMTQ5MjFiM2ZjZmY2MjUyNWIwYjU5OWY0MDll
10
- OGY5NWY0ZmZmNmJkZjBkZTZkMTRiMTg4Nzg3Yzg0NDk1NmQ1YjA1OGVjY2Q3
11
- ZmFkOTA4ZmNjODMxZTZiNmRkYzVjNDI2ODBmMTUxYmNiNWVkZTU=
9
+ NDMyYmMwZWM3NjA0NzlkYWE0YTg0NjQxNDA2MDZlMjQ5MmQ5ZDc4Y2M4MmFk
10
+ YWRmOTA2ZTM4MDkzMzVmMGFmMmFmNjI1Njg5ZmVkMDFmN2ZiNDAzOTM5Mjhj
11
+ MDY1ZTc1MmZhZDUxOThmMGY1MTgzM2MzYWEyM2RiMDI4MTBlOGI=
12
12
  data.tar.gz: !binary |-
13
- OGFjMWUyYmQ2NTZmNjYxODUwZDUyMDQ4N2YxYWJlNmNiMzg3OGUxZGFiNTky
14
- NDM3MWRjNWMxNjQ5ZTdiYmQ3MjlhMWZmNjc2NGNjYmY1ZTc0NmRlZTU0YTg1
15
- NDgwNTgyYzFkYjIxNmFkNmQxN2UzYTIwYWZiMTJiNmJlYzY1MTY=
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),
@@ -1,5 +1,5 @@
1
1
  class Fanforce
2
2
  module Validations
3
- VERSION = '0.2'
3
+ VERSION = '0.3'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fanforce-validations
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.2'
4
+ version: '0.3'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Caleb Clark