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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 46d05b8439f93fa6b9ddd50761c1e914ba344a94
4
- data.tar.gz: bc9aaab652ecd1e496f0adafc634e4777d08b23e
3
+ metadata.gz: 27bfc9c6479bc3349fe6297b555e6fac0aa33092
4
+ data.tar.gz: 38d3754d0e798d338dd8ceb7243b0b56d7371438
5
5
  SHA512:
6
- metadata.gz: ed8a2302c9c9f5c636a5539d087e3aa8c3d30a56b864cfa3fc7be6142c01b4a48a8d9c15d7b6cb1c19c0807aa26fe81b121f61838ae0f99c03d4476c3c380171
7
- data.tar.gz: 7d209081b8ef4143d36d604a6acfbcc6ab949443ed3a2312e7cf29ffca55803a64282945433aeddca4d1407e77c4455c100f159bc8e138f46af9a1797872ee00
6
+ metadata.gz: 00eecc2fbdf266d3b618c6746ab2457df4a8dd50ea5a0abc8dd5bb586fa300764adc18d9a7a5bccee2374b7dc323ec534af8a64584057140694492563dfeda58
7
+ data.tar.gz: 122c33e13f141c29b0e966fd66d87f1297c7cfefe70567cfa85a655a605d64da6e68658184248d41feebbb4de95c6408c0a0aef9a4b4a819bbdda8ea6ecba86a
@@ -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: " + conf['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
@@ -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 JsonRuleNumber < JsonRuleBase
79
+ class JsonRuleNull < JsonRuleSingleValue
80
+
81
+ def initialize
82
+ end
83
+
54
84
  end
55
85
 
56
- class JsonRuleString < JsonRuleBase
86
+ class JsonRuleBoolean < JsonRuleSingleValue
87
+
88
+ def initialize
89
+ end
90
+
57
91
  end
@@ -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
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jsondef
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Arato