thrift-validator 0.1.0 → 0.1.1
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 +4 -4
- data/Makefile +4 -0
- data/lib/thrift/validator/version.rb +1 -1
- data/lib/thrift/validator.rb +10 -6
- data/test/acceptance_test.rb +12 -0
- data/test.thrift +8 -0
- data/vendor/gen-rb/test_types.rb +34 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3f917d062bb6cba06853a570d6e390e66ddc210d
|
4
|
+
data.tar.gz: 5e41fa2667cea5cc6e360fa3a593de38cf19faf1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bbbf1149166c7616571275d48b3f78be4470c69662426f63cb046eea30e3134722430fdc2f3fe2069fb711103cc4a7c264b966fb373ee6f90b90a614b4c87cd9
|
7
|
+
data.tar.gz: 3d1c69299e2b8a9432b37a6e6d2e807f4227353c77d501abaafa9cc133cc2546b0b7cfe9026b99f24a48cc663af2fb28d961a5d433c105de81e91f9fb357d834
|
data/Makefile
CHANGED
data/lib/thrift/validator.rb
CHANGED
@@ -12,19 +12,19 @@ module Thrift
|
|
12
12
|
when Types::STRUCT
|
13
13
|
validate source.send(name)
|
14
14
|
when Types::LIST, Types::SET
|
15
|
-
|
16
|
-
|
15
|
+
if recurse? field.fetch(:element)
|
16
|
+
Array(source.send(name)).each do |item|
|
17
|
+
validate item
|
18
|
+
end
|
17
19
|
end
|
18
20
|
when Types::MAP
|
19
|
-
|
20
|
-
if key_field[:class] && key_field[:class] < ::Thrift::Struct
|
21
|
+
if recurse? field.fetch(:key)
|
21
22
|
Hash(source.send(name)).each_key do |key_value|
|
22
23
|
validate key_value
|
23
24
|
end
|
24
25
|
end
|
25
26
|
|
26
|
-
|
27
|
-
if value_field[:class] && value_field[:class] < ::Thrift::Struct
|
27
|
+
if recurse? field.fetch(:value)
|
28
28
|
Hash(source.send(name)).each_value do |value_value|
|
29
29
|
validate value_value
|
30
30
|
end
|
@@ -32,5 +32,9 @@ module Thrift
|
|
32
32
|
end
|
33
33
|
end
|
34
34
|
end
|
35
|
+
|
36
|
+
def recurse?(field)
|
37
|
+
field[:class] && field[:class] < ::Thrift::Struct
|
38
|
+
end
|
35
39
|
end
|
36
40
|
end
|
data/test/acceptance_test.rb
CHANGED
@@ -46,6 +46,12 @@ class AcceptanceTest < MiniTest::Unit::TestCase
|
|
46
46
|
assert_valid struct
|
47
47
|
end
|
48
48
|
|
49
|
+
def test_passes_with_primitives_list
|
50
|
+
struct = StringListExample.new
|
51
|
+
struct.required_list = [ 'foo' ]
|
52
|
+
assert_valid struct
|
53
|
+
end
|
54
|
+
|
49
55
|
def test_fails_if_a_nested_set_item_is_invalid
|
50
56
|
struct = SetExample.new
|
51
57
|
struct.required_set = Set.new([ SimpleStruct.new ])
|
@@ -66,6 +72,12 @@ class AcceptanceTest < MiniTest::Unit::TestCase
|
|
66
72
|
assert_valid struct
|
67
73
|
end
|
68
74
|
|
75
|
+
def test_passes_with_primitives_set
|
76
|
+
struct = StringSetExample.new
|
77
|
+
struct.required_set = Set.new([ 'foo' ])
|
78
|
+
assert_valid struct
|
79
|
+
end
|
80
|
+
|
69
81
|
def test_fails_if_nested_map_key_is_invalid
|
70
82
|
struct = MapKeyExample.new
|
71
83
|
struct.required_map = { SimpleStruct.new => 'foo' }
|
data/test.thrift
CHANGED
@@ -13,6 +13,14 @@ struct ListExample {
|
|
13
13
|
2: optional list<SimpleStruct> optional_list
|
14
14
|
}
|
15
15
|
|
16
|
+
struct StringListExample {
|
17
|
+
1: required list<string> required_list
|
18
|
+
}
|
19
|
+
|
20
|
+
struct StringSetExample {
|
21
|
+
1: required set<string> required_set
|
22
|
+
}
|
23
|
+
|
16
24
|
struct SetExample {
|
17
25
|
1: required set<SimpleStruct> required_set
|
18
26
|
2: optional set<SimpleStruct> optional_set
|
data/vendor/gen-rb/test_types.rb
CHANGED
@@ -63,6 +63,40 @@ class ListExample
|
|
63
63
|
::Thrift::Struct.generate_accessors self
|
64
64
|
end
|
65
65
|
|
66
|
+
class StringListExample
|
67
|
+
include ::Thrift::Struct, ::Thrift::Struct_Union
|
68
|
+
REQUIRED_LIST = 1
|
69
|
+
|
70
|
+
FIELDS = {
|
71
|
+
REQUIRED_LIST => {:type => ::Thrift::Types::LIST, :name => 'required_list', :element => {:type => ::Thrift::Types::STRING}}
|
72
|
+
}
|
73
|
+
|
74
|
+
def struct_fields; FIELDS; end
|
75
|
+
|
76
|
+
def validate
|
77
|
+
raise ::Thrift::ProtocolException.new(::Thrift::ProtocolException::UNKNOWN, 'Required field required_list is unset!') unless @required_list
|
78
|
+
end
|
79
|
+
|
80
|
+
::Thrift::Struct.generate_accessors self
|
81
|
+
end
|
82
|
+
|
83
|
+
class StringSetExample
|
84
|
+
include ::Thrift::Struct, ::Thrift::Struct_Union
|
85
|
+
REQUIRED_SET = 1
|
86
|
+
|
87
|
+
FIELDS = {
|
88
|
+
REQUIRED_SET => {:type => ::Thrift::Types::SET, :name => 'required_set', :element => {:type => ::Thrift::Types::STRING}}
|
89
|
+
}
|
90
|
+
|
91
|
+
def struct_fields; FIELDS; end
|
92
|
+
|
93
|
+
def validate
|
94
|
+
raise ::Thrift::ProtocolException.new(::Thrift::ProtocolException::UNKNOWN, 'Required field required_set is unset!') unless @required_set
|
95
|
+
end
|
96
|
+
|
97
|
+
::Thrift::Struct.generate_accessors self
|
98
|
+
end
|
99
|
+
|
66
100
|
class SetExample
|
67
101
|
include ::Thrift::Struct, ::Thrift::Struct_Union
|
68
102
|
REQUIRED_SET = 1
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: thrift-validator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ahawkins
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-01-
|
11
|
+
date: 2015-01-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thrift
|