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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZGE5YmEzMTk0NmRmMjc3ZDlkNmMzNzY3NmExOTg1MzgzODY4Yzc0MQ==
4
+ NzZiODRmZTI2MTU0MDg4ODQwYTgxNzI1YTcyOTZhYWYxMjdjZTNjZg==
5
5
  data.tar.gz: !binary |-
6
- ZDg1MmVhMzFhMWRmMTE3Y2ZmMTE3YmQyOWJiOGVlMDJmODkxNmE5Yg==
6
+ NTI1OTQxYjZlOGQxZDk5YTA0NjA3OGI4MmQwNzYxYzgyNDExN2Q4YQ==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- OGU0YTkyMDdkMDUwYzFhNDBiNTU5MGUyNjBkYmE1MjQ3ZTdkODIzYTI5MDFm
10
- NGQ3MGY1NzRkOGUwYzUyZWU1MWEyMzI1ZmIxMjViYzkwOGI3M2I3NWRkNDBk
11
- MzU1ODQyNjRkNDYwNjFiMjRhN2I5NmJlODRiOTJkODc3NTk2ZDQ=
9
+ MTE0MGU2NmNhODVlMDIyMjk0N2ViNjgwOTAxNTZjNDBhZTA5ZDQ4ZmRhMWRh
10
+ ZGUwMTgyZmNmZjJkNzA2NjY0NDI2NDAxODEzMTIwYWQ2ZDcwZmQ3MTM2Njc3
11
+ MTNiZDM3ODg3OWI4YzI4NDQ2Mjc2YTRhYjdiOGE0MjE3NjMyMjE=
12
12
  data.tar.gz: !binary |-
13
- YTQ0MWVlYzdiNTgwMjViOGZjODE1YjFmN2QzZjY0YTdiMTE4M2RlOTA3ZWNj
14
- MGU4MzM4ODQxYmQ5ZTcyMTM1NjRmYjYwMzEzYzM4MjkzMDUxNzVmY2NlNjUw
15
- NTBkNTQ2ZTY3MGUyMmIwZjUyYjllMzQ4MTg4NTg4MWUxYTA1YTM=
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 validates_presence_of(*args)
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
- raise_validation_error(opts, errors, Fanforce::Error::CorruptRequest)
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
- raise_validation_error(opts, errors, Fanforce::Error::CorruptRequest)
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
- raise_validation_error(opts, errors, Fanforce::Error::RequestFailed)
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
@@ -1,5 +1,5 @@
1
1
  class Fanforce
2
2
  module Validations
3
- VERSION = '0.1.4'
3
+ VERSION = '0.1.5'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fanforce-internal-validations
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Caleb Clark