jsondef 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/config_reader.rb +14 -1
- data/lib/rules.rb +36 -2
- data/lib/verify.rb +12 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 27bfc9c6479bc3349fe6297b555e6fac0aa33092
|
4
|
+
data.tar.gz: 38d3754d0e798d338dd8ceb7243b0b56d7371438
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 00eecc2fbdf266d3b618c6746ab2457df4a8dd50ea5a0abc8dd5bb586fa300764adc18d9a7a5bccee2374b7dc323ec534af8a64584057140694492563dfeda58
|
7
|
+
data.tar.gz: 122c33e13f141c29b0e966fd66d87f1297c7cfefe70567cfa85a655a605d64da6e68658184248d41feebbb4de95c6408c0a0aef9a4b4a819bbdda8ea6ecba86a
|
data/lib/config_reader.rb
CHANGED
@@ -28,8 +28,12 @@ class ConfigReader
|
|
28
28
|
parse_string(conf)
|
29
29
|
when 'number'
|
30
30
|
parse_number(conf)
|
31
|
+
when 'boolean'
|
32
|
+
parse_boolean(conf)
|
33
|
+
when 'nullval'
|
34
|
+
parse_null(conf)
|
31
35
|
else
|
32
|
-
raise "Unknown rule type:
|
36
|
+
raise "Unknown rule type: #{conf['type']}"
|
33
37
|
end
|
34
38
|
end
|
35
39
|
|
@@ -63,4 +67,13 @@ class ConfigReader
|
|
63
67
|
rule
|
64
68
|
end
|
65
69
|
|
70
|
+
def parse_boolean(conf)
|
71
|
+
rule = JsonRuleBoolean.new
|
72
|
+
rule
|
73
|
+
end
|
74
|
+
|
75
|
+
def parse_null(conf)
|
76
|
+
JsonRuleNull.new
|
77
|
+
end
|
78
|
+
|
66
79
|
end
|
data/lib/rules.rb
CHANGED
@@ -35,6 +35,7 @@ class JsonRuleObjectKey
|
|
35
35
|
@value = JsonDef::ANY_TYPE
|
36
36
|
end
|
37
37
|
|
38
|
+
# @todo rename it to optional! - might be more ruby-ist
|
38
39
|
def set_optional
|
39
40
|
@required = false
|
40
41
|
self
|
@@ -48,10 +49,43 @@ class JsonRuleObjectKey
|
|
48
49
|
end
|
49
50
|
|
50
51
|
class JsonRuleArray < JsonRuleBase
|
52
|
+
|
53
|
+
def initialize
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
|
58
|
+
class JsonRuleSingleValue < JsonRuleBase
|
59
|
+
|
60
|
+
def initialize
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
|
65
|
+
class JsonRuleNumber < JsonRuleSingleValue
|
66
|
+
|
67
|
+
def initialize
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
71
|
+
|
72
|
+
class JsonRuleString < JsonRuleSingleValue
|
73
|
+
|
74
|
+
def initialize
|
75
|
+
end
|
76
|
+
|
51
77
|
end
|
52
78
|
|
53
|
-
class
|
79
|
+
class JsonRuleNull < JsonRuleSingleValue
|
80
|
+
|
81
|
+
def initialize
|
82
|
+
end
|
83
|
+
|
54
84
|
end
|
55
85
|
|
56
|
-
class
|
86
|
+
class JsonRuleBoolean < JsonRuleSingleValue
|
87
|
+
|
88
|
+
def initialize
|
89
|
+
end
|
90
|
+
|
57
91
|
end
|
data/lib/verify.rb
CHANGED
@@ -14,6 +14,10 @@ module JsonDef
|
|
14
14
|
JsonDef.verify_string(obj, rule)
|
15
15
|
when 'JsonRuleNumber'
|
16
16
|
JsonDef.verify_number(obj, rule)
|
17
|
+
when 'JsonRuleBoolean'
|
18
|
+
JsonDef.verify_bool(obj, rule)
|
19
|
+
when 'JsonRuleNull'
|
20
|
+
JsonDef.verify_null(obj, rule)
|
17
21
|
else
|
18
22
|
raise "Unknown rule at [verify] level: #{rule.class}"
|
19
23
|
end
|
@@ -29,6 +33,14 @@ module JsonDef
|
|
29
33
|
true
|
30
34
|
end
|
31
35
|
|
36
|
+
def JsonDef.verify_bool(obj, rule)
|
37
|
+
obj == true || obj == false
|
38
|
+
end
|
39
|
+
|
40
|
+
def JsonDef.verify_null(obj, rule)
|
41
|
+
obj == nil
|
42
|
+
end
|
43
|
+
|
32
44
|
def JsonDef.verify_object(obj, rule)
|
33
45
|
return false unless obj.kind_of?(Hash)
|
34
46
|
|