avro_utils 0.2.0 → 0.3.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: af0e71b643b4c4299c0f2da4540c2877047fc5e2
4
- data.tar.gz: 78f6e118f3795b92d8e6079d176308d34aa2e8e5
3
+ metadata.gz: 0080dc3e4ff8b2c5e3b1b23d244c2ffd51c6c7ce
4
+ data.tar.gz: 0eb26f5368882942dd37e81535ac63540955b227
5
5
  SHA512:
6
- metadata.gz: 36536604fa62db13e89d6df4ffd08876556718431fb22334b4ac1f9eeebec21b79dffb0d06b88ecae4b6f3a6619fc9d05cdc4da44b26f2959a1709c38c14309d
7
- data.tar.gz: b94fb042627c71eb4dbee94ea8297775de0f082e9c328253f694f4f1efa85214a879fe63548c254610ad545b1f282e881c82496f0e85e61ec75cbf25aed85440
6
+ metadata.gz: 5354701d75e488ee89d476d7d4f7e196898bd34228af0e64a4d600e24f0cc2d4df9efd4187f01edaff48383033fd36892684a2dfa5cb514421c5c3b2a62866dd
7
+ data.tar.gz: 6983cbb57153c0c19c582f4bbca97ffa9424a629e65ef5944bbe542c53bf6eaaa61cac2fc5e826637cbb3f4170a0b27bb07901f7e87faa7a2a34315e73768eac
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'avro_utils'
3
- s.version = '0.2.0'
3
+ s.version = '0.3.0'
4
4
  s.summary = "A gem to convert different data format to avro"
5
5
  s.description = "A gem to convert different data format to avro"
6
6
  s.authors = ['Linh Chau']
@@ -64,6 +64,39 @@ class AvroUtils
64
64
  end
65
65
  end
66
66
 
67
+ def is_valid_schema?(schema)
68
+ process_data do
69
+ working_schema = ( [Hash, Array].include?(schema.class) )? schema.to_json : schema.dup
70
+ all_names_valid?(working_schema)
71
+ Avro::Schema.parse(working_schema)
72
+ true
73
+ end
74
+ end
75
+
76
+ def all_names_valid?(string_schema)
77
+ result = { }
78
+ names = string_schema.scan(/"name":"[\w][^"]+/).map { |x| x.split(':"')[1] }
79
+ invalid_pt = /[^A-Za-z0-9_]/
80
+ names.each do |name|
81
+ invalid_chars = name.scan(invalid_pt)
82
+ if invalid_chars.any?
83
+ result.store(name, invalid_chars)
84
+ end
85
+ end
86
+
87
+ if result.any?
88
+ error = "The following names have invalid characters:\n"
89
+ result.each do |key, value|
90
+ error += "#{key}: #{value}\n"
91
+ end
92
+
93
+ raise InvalidDataException.new(error)
94
+ end
95
+
96
+ true
97
+ end
98
+
99
+
67
100
  # Avro assumes that all the hashes use strings for keys. It does not accept Indifferent Hash.
68
101
  # So the conversion bellow ensures that the hash data uses strings for keys.
69
102
  def hash_with_string_keys(json_data)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: avro_utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Linh Chau
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-09-24 00:00:00.000000000 Z
11
+ date: 2015-10-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json