avro-builder 0.12.0 → 0.13.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/README.md +23 -0
- data/lib/avro/builder/definition_cache.rb +19 -11
- data/lib/avro/builder/dsl.rb +6 -0
- data/lib/avro/builder/version.rb +1 -1
- 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: 8672dba84b4ee61d299c99f3fe0ced401b3817b4
|
4
|
+
data.tar.gz: dcdcf44d8c0f11c3b2d9b828738047a037df0caa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e3f8f47f84aa98101454de16745b084e07f3342f0c97f69597cf378ef0906b1deeafe730a96562e478daac34b0f78f1ad47565eded84c2bc3dafaa72c6223408
|
7
|
+
data.tar.gz: 3116b64339e0afb980ced2790f2e71e626983fc976a1b519edf5656e4dabb09b2175dc9545bdba7942df2223920d78813cb10cb5688bc7f7880f6c5a51498adc
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -316,6 +316,29 @@ record :with_date_array
|
|
316
316
|
end
|
317
317
|
```
|
318
318
|
|
319
|
+
### Type Macros
|
320
|
+
|
321
|
+
`avro-builder` allows type macros to be defined that expand to types that
|
322
|
+
cannot normally be named in Avro schemas. These macro names are not retained
|
323
|
+
in generated schemas but allow definitions to be reused across DSL files:
|
324
|
+
|
325
|
+
```ruby
|
326
|
+
type_macro :timestamp, long(logical_type: 'timestamp-millis')
|
327
|
+
|
328
|
+
record :user do
|
329
|
+
required :created_at, :timestamp
|
330
|
+
required :updated_at, :timestamp
|
331
|
+
end
|
332
|
+
```
|
333
|
+
|
334
|
+
Type macros inherit the namespace from the context where they are defined or
|
335
|
+
an explicit namespace option may be specified:
|
336
|
+
|
337
|
+
```ruby
|
338
|
+
type_macro :timestamp, long(logical_type: 'timestamp-millis'),
|
339
|
+
namespace: 'com.my_company'
|
340
|
+
```
|
341
|
+
|
319
342
|
### Auto-loading and Imports
|
320
343
|
|
321
344
|
Specify paths to search for definitions:
|
@@ -32,26 +32,34 @@ module Avro
|
|
32
32
|
object || lookup_named_type(key, nil)
|
33
33
|
end
|
34
34
|
|
35
|
+
# Add a type object directly with the specified name.
|
36
|
+
# The type_object may not have a name or namespace.
|
37
|
+
def add_type_by_name(type_object, name, namespace = nil)
|
38
|
+
fullname = Avro::Name.make_fullname(name.to_s, namespace && namespace.to_s)
|
39
|
+
name = fullname.split('.').last
|
40
|
+
|
41
|
+
store_by_name(type_object, name)
|
42
|
+
store_by_fullname(type_object, fullname) if name != fullname
|
43
|
+
end
|
44
|
+
|
35
45
|
private
|
36
46
|
|
37
47
|
# Schemas are stored by name, provided that the name is unique.
|
38
48
|
# If the unqualified name is ambiguous then it is removed from the cache.
|
39
49
|
# A set of unqualified names is kept to avoid reloading files for
|
40
50
|
# ambiguous references.
|
41
|
-
def store_by_name(object)
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
schema_objects.store(key, object)
|
51
|
+
def store_by_name(object, name = object.name.to_s)
|
52
|
+
if schema_objects.key?(name)
|
53
|
+
schema_objects.delete(name)
|
54
|
+
elsif !schema_names.include?(name)
|
55
|
+
schema_objects.store(name, object)
|
47
56
|
end
|
48
|
-
schema_names.add(
|
57
|
+
schema_names.add(name)
|
49
58
|
end
|
50
59
|
|
51
|
-
def store_by_fullname(object)
|
52
|
-
|
53
|
-
|
54
|
-
schema_objects.store(key, object)
|
60
|
+
def store_by_fullname(object, fullname = object.fullname)
|
61
|
+
raise DuplicateDefinitionError.new(fullname, object, schema_objects[fullname]) if schema_objects.key?(fullname)
|
62
|
+
schema_objects.store(fullname, object)
|
55
63
|
end
|
56
64
|
|
57
65
|
attr_reader :schema_objects, :schema_names, :builder
|
data/lib/avro/builder/dsl.rb
CHANGED
@@ -89,6 +89,12 @@ module Avro
|
|
89
89
|
@last_object = super
|
90
90
|
end
|
91
91
|
|
92
|
+
def type_macro(name, type_object, options = {})
|
93
|
+
raise "#{type_object.inspect} must be a type object" unless type_object.is_a?(Types::Type)
|
94
|
+
raise "namespace cannot be included in name: #{name}" if name.to_s.index('.')
|
95
|
+
cache.add_type_by_name(type_object, name, options[:namespace] || namespace)
|
96
|
+
end
|
97
|
+
|
92
98
|
private
|
93
99
|
|
94
100
|
def cache
|
data/lib/avro/builder/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: avro-builder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.13.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Salsify Engineering
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-09-
|
11
|
+
date: 2016-09-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: avro
|