avro-builder 0.11.0 → 0.12.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 +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +20 -0
- data/lib/avro/builder/dsl.rb +7 -1
- data/lib/avro/builder/field.rb +11 -14
- data/lib/avro/builder/type_factory.rb +15 -0
- data/lib/avro/builder/types/array_type.rb +1 -1
- data/lib/avro/builder/types/complex_type.rb +4 -0
- data/lib/avro/builder/types/map_type.rb +1 -1
- data/lib/avro/builder/types/record_type.rb +4 -4
- data/lib/avro/builder/types/type.rb +5 -0
- data/lib/avro/builder/types/type_referencer.rb +7 -7
- data/lib/avro/builder/types/union_type.rb +1 -1
- 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: 21b042e8f1af75aa7438eca4e949b32a50d691a1
|
4
|
+
data.tar.gz: eedcd4cb2b91b9336ad1688bb3c6bdbb3dec079e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f12ec9cd64725bae339a186f7db26f1c6b16a1c59cdc13d935bde7d62e9195bc2c976e7840e307432a3551ff59ea48d8566c990a882026c4f1970f8419bd250f
|
7
|
+
data.tar.gz: 48a859dbb4d78c94db00220ecedb119e564cac42f16031b258accbc4619844ff6d92c87d8d0f2f28232d67b310a750835074b62afece2fd940af59467991f849
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
# avro-builder changelog
|
2
2
|
|
3
|
+
## v0.12.0
|
4
|
+
- Allow methods for complex and primitive types to be used at the top-level and
|
5
|
+
anywhere that a type name is accepted.
|
6
|
+
|
3
7
|
## v0.11.0
|
4
8
|
- Add support for generating schemas that contain logical types. The official
|
5
9
|
Ruby `avro` gem does not yet support logical types. The `avro-salsify-fork` gem
|
data/README.md
CHANGED
@@ -185,6 +185,16 @@ record :complex_types do
|
|
185
185
|
end
|
186
186
|
```
|
187
187
|
|
188
|
+
Methods may also be used for complex types instead of separately specifying the
|
189
|
+
type name and options:
|
190
|
+
|
191
|
+
```ruby
|
192
|
+
record :complex_types do
|
193
|
+
required :array_of_unions, array(union(:int, :string))
|
194
|
+
required :array_or_map, union(array(:int), map(:int))
|
195
|
+
end
|
196
|
+
```
|
197
|
+
|
188
198
|
For more on unions see [below](#unions).
|
189
199
|
|
190
200
|
### Nested Records
|
@@ -254,6 +264,16 @@ end
|
|
254
264
|
For an optional union, `null` is automatically added as the first type for
|
255
265
|
the union and the field defaults to `null`.
|
256
266
|
|
267
|
+
Unions may also be defined using the `union` method instead of specifying the
|
268
|
+
`:union` type and member types separately:
|
269
|
+
|
270
|
+
```ruby
|
271
|
+
record :my_record_with_unions do
|
272
|
+
required :req_union, union(:string, :int)
|
273
|
+
optional :opt_union, union(:float, :long)
|
274
|
+
end
|
275
|
+
```
|
276
|
+
|
257
277
|
### Logical Types
|
258
278
|
|
259
279
|
The DSL supports setting a logical type on any type except a union. The logical
|
data/lib/avro/builder/dsl.rb
CHANGED
@@ -22,7 +22,7 @@ module Avro
|
|
22
22
|
include Avro::Builder::DslOptions
|
23
23
|
include Avro::Builder::DslAttributes
|
24
24
|
include Avro::Builder::FileHandler
|
25
|
-
include Avro::Builder::
|
25
|
+
include Avro::Builder::AnonymousTypes
|
26
26
|
|
27
27
|
dsl_attribute :namespace
|
28
28
|
|
@@ -83,6 +83,12 @@ module Avro
|
|
83
83
|
Avro::Schema.parse(to_json(validate: false))
|
84
84
|
end
|
85
85
|
|
86
|
+
# Override the type method from AnonymousTypes to store a reference to the
|
87
|
+
# last type defined.
|
88
|
+
def type(*)
|
89
|
+
@last_object = super
|
90
|
+
end
|
91
|
+
|
86
92
|
private
|
87
93
|
|
88
94
|
def cache
|
data/lib/avro/builder/field.rb
CHANGED
@@ -17,7 +17,7 @@ module Avro
|
|
17
17
|
# These attributes may be set as options or via a block in the DSL
|
18
18
|
dsl_attributes :doc, :default, :order
|
19
19
|
|
20
|
-
def initialize(name:,
|
20
|
+
def initialize(name:, avro_type_or_name:, record:, cache:, internal: {}, options: {}, &block)
|
21
21
|
@cache = cache
|
22
22
|
@record = record
|
23
23
|
@name = name.to_s
|
@@ -31,19 +31,16 @@ module Avro
|
|
31
31
|
send(key, type_options.delete(key)) if dsl_attribute?(key)
|
32
32
|
end
|
33
33
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
else
|
45
|
-
cache.lookup_named_type(avro_type_name, namespace)
|
46
|
-
end
|
34
|
+
# Find existing Type or build a new instance of a builtin Type using
|
35
|
+
# the supplied block
|
36
|
+
@field_type = type_lookup(avro_type_or_name, namespace) do |avro_type_name|
|
37
|
+
create_and_configure_builtin_type(avro_type_name,
|
38
|
+
field: self,
|
39
|
+
cache: cache,
|
40
|
+
internal: internal,
|
41
|
+
validate_type: false,
|
42
|
+
options: type_options)
|
43
|
+
end
|
47
44
|
|
48
45
|
# DSL calls must be evaluated after the type has been constructed
|
49
46
|
instance_eval(&block) if block_given?
|
@@ -10,6 +10,21 @@ module Avro
|
|
10
10
|
|
11
11
|
private
|
12
12
|
|
13
|
+
# Determine if avro_type_or_name is an existing Type, the name of a builtin
|
14
|
+
# type or a previously defined named type.
|
15
|
+
# If avro_type_or_name is the name of a builtin type, then that type name
|
16
|
+
# is yielded to build the type using a block provided by the caller using,
|
17
|
+
# for example, create_builtin_type or create_and_configure_builtin_type.
|
18
|
+
def type_lookup(avro_type_or_name, namespace = nil)
|
19
|
+
if avro_type_or_name.is_a?(Avro::Builder::Types::Type)
|
20
|
+
avro_type_or_name
|
21
|
+
elsif builtin_type?(avro_type_or_name)
|
22
|
+
yield(avro_type_or_name)
|
23
|
+
else
|
24
|
+
cache.lookup_named_type(avro_type_or_name, namespace)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
13
28
|
# Return a new Type instance
|
14
29
|
def create_builtin_type(avro_type_name, field:, cache:)
|
15
30
|
name = avro_type_name.to_s.downcase
|
@@ -26,9 +26,9 @@ module Avro
|
|
26
26
|
end
|
27
27
|
|
28
28
|
# Add a required field to the record
|
29
|
-
def required(name,
|
29
|
+
def required(name, avro_type_or_name, options = {}, &block)
|
30
30
|
new_field = Avro::Builder::Field.new(name: name,
|
31
|
-
|
31
|
+
avro_type_or_name: avro_type_or_name,
|
32
32
|
record: self,
|
33
33
|
cache: cache,
|
34
34
|
internal: { type_namespace: namespace },
|
@@ -39,9 +39,9 @@ module Avro
|
|
39
39
|
|
40
40
|
# Add an optional field to the record. In Avro this is represented
|
41
41
|
# as a union of null and the type specified here.
|
42
|
-
def optional(name,
|
42
|
+
def optional(name, avro_type_or_name, options = {}, &block)
|
43
43
|
new_field = Avro::Builder::Field.new(name: name,
|
44
|
-
|
44
|
+
avro_type_or_name: avro_type_or_name,
|
45
45
|
record: self,
|
46
46
|
cache: cache,
|
47
47
|
internal: { type_namespace: namespace,
|
@@ -8,13 +8,13 @@ module Avro
|
|
8
8
|
module TypeReferencer
|
9
9
|
include Avro::Builder::TypeFactory
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
cache
|
11
|
+
private
|
12
|
+
|
13
|
+
def create_builtin_or_lookup_type(avro_type_or_name)
|
14
|
+
# Find existing Type or build a new instance of a builtin Type using
|
15
|
+
# the supplied block
|
16
|
+
type_lookup(avro_type_or_name) do |avro_type_name|
|
17
|
+
create_builtin_type(avro_type_name, field: field, cache: cache)
|
18
18
|
end
|
19
19
|
end
|
20
20
|
end
|
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.12.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-
|
11
|
+
date: 2016-09-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: avro
|