classy_hash 0.1.2 → 0.1.3
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.
- checksums.yaml +5 -13
- data/lib/classy_hash.rb +10 -4
- metadata +10 -10
checksums.yaml
CHANGED
@@ -1,15 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
5
|
-
data.tar.gz: !binary |-
|
6
|
-
NGE0MDdjNWJhNWRmZDM4OTRiZWVhYzRhNDVjNzdjMmFlZDM0NmQyYg==
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c312e543d1f629c815c7b1c15358a169b3420ea6
|
4
|
+
data.tar.gz: 2bdd15d37771bea764e2f2582dcdc37d16ee2dfe
|
7
5
|
SHA512:
|
8
|
-
metadata.gz:
|
9
|
-
|
10
|
-
YTMwYzY2N2Y4Mzc1ZDQ1MmI3OGY5NDkzM2U0Y2NmZjc1MjRlMTEyYzE3M2Q5
|
11
|
-
MTJhZjkxMjdkMzM0MmZmYjU4NzQyNDg0YWJkNThlODNjYThjZGQ=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
MGIxOTkyMTZmMDExYzYwZGI5ZGYwNmY0YTg4YmE2ZjI0OThlZTYxNTYyYzQx
|
14
|
-
OGE2NDcxYTk4ZDVjYjc0ZDg4YTFiYmZiMGY4OTU4NmNhMTRmNGNhNDc1N2Q5
|
15
|
-
MGYyNGJlOTBmMDk5MDhmMDhlNzk5MTVlMjA0MTY1OGViMWM3ZTg=
|
6
|
+
metadata.gz: be3b7e32372be07cf3efaa7163002d2a85af1059a0ed6523bbfe619e7770e4eb80fb0f2c2b2254a069cde84643f25ccf56cea389f7325ce2bd1f9411c62bfde8
|
7
|
+
data.tar.gz: bb3287e9a7838a57b42ff90b3fe0fc535f9765c3c25df20b8369ff11529971b7a2602a87f640f9176daf27f7f9c47cc5eee71b879ad3444b08681d77ab99bc52
|
data/lib/classy_hash.rb
CHANGED
@@ -25,13 +25,19 @@ module ClassyHash
|
|
25
25
|
end
|
26
26
|
|
27
27
|
# As with #validate, but members not specified in the +schema+ are forbidden.
|
28
|
-
# Only the top-level schema is strictly validated.
|
29
|
-
|
28
|
+
# Only the top-level schema is strictly validated. If +verbose+ is true, the
|
29
|
+
# names of unexpected keys will be included in the error message.
|
30
|
+
def self.validate_strict(hash, schema, verbose=false, parent_path=nil)
|
30
31
|
raise 'Must validate a Hash' unless hash.is_a?(Hash) # TODO: Allow validating other types by passing to #check_one?
|
31
32
|
raise 'Schema must be a Hash' unless schema.is_a?(Hash) # TODO: Allow individual element validations?
|
32
33
|
|
33
|
-
|
34
|
-
|
34
|
+
extra_keys = hash.keys - schema.keys
|
35
|
+
unless extra_keys.empty?
|
36
|
+
if verbose
|
37
|
+
raise "Hash contains members (#{extra_keys.map(&:inspect).join(', ')}) not specified in schema"
|
38
|
+
else
|
39
|
+
raise 'Hash contains members not specified in schema'
|
40
|
+
end
|
35
41
|
end
|
36
42
|
|
37
43
|
# TODO: Strict validation for nested schemas as well
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: classy_hash
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Deseret Book
|
@@ -9,11 +9,12 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-
|
12
|
+
date: 2014-10-16 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
|
-
description:
|
15
|
-
|
16
|
-
|
14
|
+
description: |2
|
15
|
+
Classy Hash is a schema validator for Ruby Hashes. You provide a simple
|
16
|
+
schema Hash, and Classy Hash will make sure your data matches, providing
|
17
|
+
helpful error messages if it doesn't.
|
17
18
|
email: mike@mikebourgeous.com
|
18
19
|
executables: []
|
19
20
|
extensions: []
|
@@ -31,19 +32,18 @@ require_paths:
|
|
31
32
|
- lib
|
32
33
|
required_ruby_version: !ruby/object:Gem::Requirement
|
33
34
|
requirements:
|
34
|
-
- -
|
35
|
+
- - ">="
|
35
36
|
- !ruby/object:Gem::Version
|
36
37
|
version: 1.9.3
|
37
38
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
38
39
|
requirements:
|
39
|
-
- -
|
40
|
+
- - ">="
|
40
41
|
- !ruby/object:Gem::Version
|
41
42
|
version: '0'
|
42
43
|
requirements: []
|
43
44
|
rubyforge_project:
|
44
|
-
rubygems_version: 2.2.
|
45
|
+
rubygems_version: 2.2.2
|
45
46
|
signing_key:
|
46
47
|
specification_version: 4
|
47
|
-
summary:
|
48
|
+
summary: 'Classy Hash: Keep your Hashes classy; a Hash schema validator'
|
48
49
|
test_files: []
|
49
|
-
has_rdoc:
|