thrift-validator 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: d1e1282790eab6d2034f8f05da9d4512102c59be
4
- data.tar.gz: 50535756f602fcf6c60b4f2ef47222fc28e75e6d
3
+ metadata.gz: 3f917d062bb6cba06853a570d6e390e66ddc210d
4
+ data.tar.gz: 5e41fa2667cea5cc6e360fa3a593de38cf19faf1
5
5
  SHA512:
6
- metadata.gz: f59768669a591b41eeb0c1802252ba2256f53800c18242cf21196496c9dc13b08535a52098ed7b9302a2499f97971dddd93e9a2146bf5380e6aa78c73a28c124
7
- data.tar.gz: 96421ce8b108eb57fee36cfa5e1e18b0dd318c2081573110c796320438b0c3612054fd7a38d2066caa4236cb1c7deb66e9588731d5fedc45507c7724d68a91dc
6
+ metadata.gz: bbbf1149166c7616571275d48b3f78be4470c69662426f63cb046eea30e3134722430fdc2f3fe2069fb711103cc4a7c264b966fb373ee6f90b90a614b4c87cd9
7
+ data.tar.gz: 3d1c69299e2b8a9432b37a6e6d2e807f4227353c77d501abaafa9cc133cc2546b0b7cfe9026b99f24a48cc663af2fb28d961a5d433c105de81e91f9fb357d834
data/Makefile CHANGED
@@ -7,3 +7,7 @@ $(THRIFT): test.thrift
7
7
  .PHONY: test
8
8
  test: $(THRIFT)
9
9
  bundle exec rake test
10
+
11
+ .PHONY:
12
+ release:
13
+ bundle exec rake release
@@ -1,5 +1,5 @@
1
1
  module Thrift
2
2
  class Validator
3
- VERSION = "0.1.0"
3
+ VERSION = "0.1.1"
4
4
  end
5
5
  end
@@ -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
- Array(source.send(name)).each do |item|
16
- validate item
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
- key_field = field.fetch(:key)
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
- value_field = field.fetch(:value)
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
@@ -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
@@ -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.0
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-14 00:00:00.000000000 Z
11
+ date: 2015-01-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thrift