vert 0.2.1 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/vert.rb +16 -14
- metadata +28 -22
- checksums.yaml +0 -7
data/lib/vert.rb
CHANGED
|
@@ -15,7 +15,7 @@ module Vert
|
|
|
15
15
|
EMPTY_ERROR = "The hash is empty."
|
|
16
16
|
EMPTY_ERROR_KEY = :empty
|
|
17
17
|
|
|
18
|
-
ABSENT_KEY_ERROR = "The data does not contain
|
|
18
|
+
ABSENT_KEY_ERROR = "The data does not contain one or more required keys."
|
|
19
19
|
ABSENT_KEY_ERROR_KEY = :absent_key
|
|
20
20
|
|
|
21
21
|
ARRAY_TYPE_ERROR = "The following key/s do not have Array type values."
|
|
@@ -30,7 +30,7 @@ module Vert
|
|
|
30
30
|
HASH_EMPTY_ERROR = "The following hash key/s are empty."
|
|
31
31
|
HASH_EMPTY_ERROR_KEY = :hash_empty
|
|
32
32
|
|
|
33
|
-
#error messages for
|
|
33
|
+
#error messages for JSON validation
|
|
34
34
|
NOT_A_STRING_ERROR = "Not a JSON string."
|
|
35
35
|
NOT_A_STRING_ERROR_KEY = :not_a_string
|
|
36
36
|
|
|
@@ -40,21 +40,21 @@ module Vert
|
|
|
40
40
|
EMPTY_JSON_OBJECT_ERROR = "The JSON object is empty."
|
|
41
41
|
EMPTY_JSON_OBJECT_ERROR_KEY = :empty_json_object
|
|
42
42
|
|
|
43
|
-
MALFORMED_JSON_ERROR = "The JSON string is malformed
|
|
43
|
+
MALFORMED_JSON_ERROR = "The JSON string is malformed"
|
|
44
44
|
MALFORMED_JSON_ERROR_KEY = :malformed_json
|
|
45
45
|
|
|
46
46
|
#error messages for avro verification
|
|
47
|
-
INVALID_AVRO_SCHEMA_ERROR = "The avro schema is invalid
|
|
47
|
+
INVALID_AVRO_SCHEMA_ERROR = "The avro schema is invalid"
|
|
48
48
|
INVALID_AVRO_SCHEMA_ERROR_KEY = :invalid_avro_schema
|
|
49
49
|
|
|
50
|
-
INVALID_AVRO_DATUM_ERROR = "The JSON provided is not an instance of the schema
|
|
50
|
+
INVALID_AVRO_DATUM_ERROR = "The JSON provided is not an instance of the schema."
|
|
51
51
|
INVALID_AVRO_DATUM_ERROR_KEY = :invalid_avro_datum
|
|
52
52
|
|
|
53
53
|
#Enums
|
|
54
54
|
TYPE_ENUM = {array_keys: Array, hash_keys: Hash}
|
|
55
55
|
OPTIONS_HASH_ENUM = [:keys, :custom_errors]
|
|
56
56
|
OPTIONS_JSON_HASH_ENUM = [:schema, :custom_errors]
|
|
57
|
-
KEYS_ENUM = [:
|
|
57
|
+
KEYS_ENUM = [:required_keys, :array_keys, :hash_keys]
|
|
58
58
|
ERROR_KEY_ENUM = {
|
|
59
59
|
NOT_A_HASH_ERROR_KEY => NOT_A_HASH_ERROR,
|
|
60
60
|
EMPTY_ERROR_KEY => EMPTY_ERROR,
|
|
@@ -74,6 +74,8 @@ module Vert
|
|
|
74
74
|
#input validation
|
|
75
75
|
OPTIONS_HASH_EMPTY = "The options hash must contain keys"
|
|
76
76
|
OPTIONS_NOT_A_HASH = "The options parameter must be a hash"
|
|
77
|
+
OPTIONS_HASH_FORMAT = "{:keys => {}, :custom_errors => {}}"
|
|
78
|
+
OPTIONS_JSON_HASH_FORMAT = "{:schema => \"avro shcema\", :custom_errors => {}}"
|
|
77
79
|
OPTIONS_HASH_MISSING_VALID_KEYS = "The options hash contains no valid keys. The valid symbol keys are - "
|
|
78
80
|
KEYS_HASH_MISSING_VALID_KEYS = "The options hash contains no valid keys for the :keys hash. The valid symbol keys are - "
|
|
79
81
|
CUSTOM_ERRORS_HASH_MISSING_VALID_KEYS = "The options hash contains no valid keys for the :custom_errors hash. The valid symbol keys are - "
|
|
@@ -82,7 +84,7 @@ module Vert
|
|
|
82
84
|
|
|
83
85
|
def validate(hash, options = nil)
|
|
84
86
|
unless options.nil?
|
|
85
|
-
check_options_format(options)
|
|
87
|
+
check_options_format(options, OPTIONS_HASH_FORMAT)
|
|
86
88
|
check_options(options)
|
|
87
89
|
end
|
|
88
90
|
test_validations(hash, options)
|
|
@@ -106,7 +108,7 @@ module Vert
|
|
|
106
108
|
|
|
107
109
|
def validate_json(json, options = nil)
|
|
108
110
|
unless options.nil?
|
|
109
|
-
check_options_format(options)
|
|
111
|
+
check_options_format(options, OPTIONS_JSON_HASH_FORMAT)
|
|
110
112
|
check_json_options(options)
|
|
111
113
|
end
|
|
112
114
|
test_validations_json(json, options)
|
|
@@ -138,8 +140,8 @@ module Vert
|
|
|
138
140
|
end
|
|
139
141
|
end
|
|
140
142
|
|
|
141
|
-
def check_options_format(options)
|
|
142
|
-
raise InputError, OPTIONS_NOT_A_HASH unless options.is_a?(Hash)
|
|
143
|
+
def check_options_format(options, options_format)
|
|
144
|
+
raise InputError, "#{OPTIONS_NOT_A_HASH}. The options hash has the following format:- #{options_format}" unless options.is_a?(Hash)
|
|
143
145
|
raise InputError, OPTIONS_HASH_EMPTY if options.empty?
|
|
144
146
|
if options.keys.include?(:custom_errors)
|
|
145
147
|
raise_when_all_keys_missing(options[:custom_errors], CUSTOM_ERRORS_HASH_MISSING_VALID_KEYS, ERROR_KEY_ENUM.keys)
|
|
@@ -148,8 +150,8 @@ module Vert
|
|
|
148
150
|
|
|
149
151
|
def test_validations(hash, options)
|
|
150
152
|
test_for_default_hash_errors(hash, options)
|
|
151
|
-
if options_key_types_present?(options, :
|
|
152
|
-
raise_when_keys_absent(hash, options, :
|
|
153
|
+
if options_key_types_present?(options, :required_keys)
|
|
154
|
+
raise_when_keys_absent(hash, options, :required_keys)
|
|
153
155
|
elsif options_key_types_present?(options, :array_keys)
|
|
154
156
|
test_for_array_key_errors(hash, options)
|
|
155
157
|
elsif options_key_types_present?(options, :hash_keys)
|
|
@@ -256,7 +258,7 @@ module Vert
|
|
|
256
258
|
end
|
|
257
259
|
|
|
258
260
|
def build_missing_key_error(options, missing_keys_array)
|
|
259
|
-
"#{build_error_message(options, ABSENT_KEY_ERROR_KEY)}
|
|
261
|
+
"#{build_error_message(options, ABSENT_KEY_ERROR_KEY)}\nMissing key/s: #{missing_keys_array*", "}"
|
|
260
262
|
end
|
|
261
263
|
|
|
262
264
|
def build_error_message(options, error_key)
|
|
@@ -347,7 +349,7 @@ module Vert
|
|
|
347
349
|
raise_custom_error(hash, options, EMPTY_JSON_OBJECT_ERROR_KEY){|hash| hash.empty?}
|
|
348
350
|
rescue Oj::ParseError => exception
|
|
349
351
|
detail = "#{exception.message.gsub( /\[.+\]/, "").rstrip}."
|
|
350
|
-
raise ValidationError, "#{build_error_message(options, MALFORMED_JSON_ERROR_KEY)}
|
|
352
|
+
raise ValidationError, "#{build_error_message(options, MALFORMED_JSON_ERROR_KEY)}, #{detail}"
|
|
351
353
|
else
|
|
352
354
|
hash
|
|
353
355
|
end
|
metadata
CHANGED
|
@@ -1,72 +1,78 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: vert
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
|
|
4
|
+
prerelease:
|
|
5
|
+
version: 0.3.0
|
|
5
6
|
platform: ruby
|
|
6
7
|
authors:
|
|
7
8
|
- Eskimo Bear
|
|
8
9
|
autorequire:
|
|
9
10
|
bindir: bin
|
|
10
11
|
cert_chain: []
|
|
11
|
-
date:
|
|
12
|
+
date: 2015-01-09 00:00:00.000000000 Z
|
|
12
13
|
dependencies:
|
|
13
14
|
- !ruby/object:Gem::Dependency
|
|
15
|
+
type: :runtime
|
|
16
|
+
prerelease: false
|
|
14
17
|
name: avro
|
|
15
18
|
requirement: !ruby/object:Gem::Requirement
|
|
19
|
+
none: false
|
|
16
20
|
requirements:
|
|
17
|
-
- -
|
|
21
|
+
- - ~>
|
|
18
22
|
- !ruby/object:Gem::Version
|
|
19
|
-
version: 1.7.
|
|
20
|
-
type: :runtime
|
|
21
|
-
prerelease: false
|
|
23
|
+
version: 1.7.7
|
|
22
24
|
version_requirements: !ruby/object:Gem::Requirement
|
|
25
|
+
none: false
|
|
23
26
|
requirements:
|
|
24
|
-
- -
|
|
27
|
+
- - ~>
|
|
25
28
|
- !ruby/object:Gem::Version
|
|
26
|
-
version: 1.7.
|
|
29
|
+
version: 1.7.7
|
|
27
30
|
- !ruby/object:Gem::Dependency
|
|
31
|
+
type: :runtime
|
|
32
|
+
prerelease: false
|
|
28
33
|
name: oj
|
|
29
34
|
requirement: !ruby/object:Gem::Requirement
|
|
35
|
+
none: false
|
|
30
36
|
requirements:
|
|
31
|
-
- -
|
|
37
|
+
- - ! '>='
|
|
32
38
|
- !ruby/object:Gem::Version
|
|
33
|
-
version:
|
|
34
|
-
type: :runtime
|
|
35
|
-
prerelease: false
|
|
39
|
+
version: '0'
|
|
36
40
|
version_requirements: !ruby/object:Gem::Requirement
|
|
41
|
+
none: false
|
|
37
42
|
requirements:
|
|
38
|
-
- -
|
|
43
|
+
- - ! '>='
|
|
39
44
|
- !ruby/object:Gem::Version
|
|
40
|
-
version:
|
|
41
|
-
description:
|
|
45
|
+
version: '0'
|
|
46
|
+
description: Validate hashes and JSON data and output custom errors
|
|
42
47
|
email: dev@eskimobear.com
|
|
43
48
|
executables: []
|
|
44
49
|
extensions: []
|
|
45
50
|
extra_rdoc_files: []
|
|
46
51
|
files:
|
|
47
52
|
- lib/vert.rb
|
|
48
|
-
homepage: https://github.com/EskimoBear/
|
|
53
|
+
homepage: https://github.com/EskimoBear/vert/
|
|
49
54
|
licenses:
|
|
50
55
|
- MIT
|
|
51
|
-
metadata: {}
|
|
52
56
|
post_install_message:
|
|
53
57
|
rdoc_options: []
|
|
54
58
|
require_paths:
|
|
55
59
|
- lib
|
|
56
60
|
required_ruby_version: !ruby/object:Gem::Requirement
|
|
61
|
+
none: false
|
|
57
62
|
requirements:
|
|
58
|
-
- -
|
|
63
|
+
- - ! '>='
|
|
59
64
|
- !ruby/object:Gem::Version
|
|
60
65
|
version: '0'
|
|
61
66
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
67
|
+
none: false
|
|
62
68
|
requirements:
|
|
63
|
-
- -
|
|
69
|
+
- - ! '>='
|
|
64
70
|
- !ruby/object:Gem::Version
|
|
65
71
|
version: '0'
|
|
66
72
|
requirements: []
|
|
67
73
|
rubyforge_project:
|
|
68
|
-
rubygems_version:
|
|
74
|
+
rubygems_version: 1.8.23.2
|
|
69
75
|
signing_key:
|
|
70
|
-
specification_version:
|
|
71
|
-
summary: Keep your data clean
|
|
76
|
+
specification_version: 3
|
|
77
|
+
summary: Keep your data clean without the boilerplate
|
|
72
78
|
test_files: []
|
checksums.yaml
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
SHA1:
|
|
3
|
-
metadata.gz: cc6d3bfb12ff30eaad91ca1aaa5d1cb3b22e9f57
|
|
4
|
-
data.tar.gz: 6ab62d9c55248d41c3fa360714b585e54d87924a
|
|
5
|
-
SHA512:
|
|
6
|
-
metadata.gz: 516fe980cc3e286f8f08fed032e79dd2f0b2a98c9770bee92e416e3f93cd82295aa2b9ac98a4e72d918950b5da8282b5ff3e6c4a91558605b10e51a77b0524a4
|
|
7
|
-
data.tar.gz: 97164fdcc94904f226b4a3a2a33bc1756a62cb7992bbfb352ebe5a2560e29b4eef3ed09415b2fabb1956f6f8410321b75045df12f3082263dff58e4a78b266dc
|