avro-builder 0.7.0 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +4 -2
- data/CHANGELOG.md +3 -0
- data/README.md +31 -1
- data/lib/avro/builder.rb +1 -0
- data/lib/avro/builder/errors.rb +6 -0
- data/lib/avro/builder/schema_store.rb +24 -0
- data/lib/avro/builder/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 102f64b688e2d8f26a65c2235860d4c161f41645
|
4
|
+
data.tar.gz: 48f49e771a762072dab576f79ccdfd2f951b3dfa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c93f99d97e6e63d0bae808f7608cf4f627fb5efe928ef7ba6da4ef00fda6119e29b94802bda1d21c0a86bd1fc184f102aa4ebdf79688d55df10b3b4534b7680d
|
7
|
+
data.tar.gz: 78dd456fa89680f448ac176e58e3ae3bfadf3954fcb2ea044406db22bdaf65a5d74924d3354c7bbe3e0dd46e00d8afb5f06d7cac215cf30fe47c9042466db846
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -12,12 +12,17 @@ This DSL was created because:
|
|
12
12
|
* Schemas can be extracted as JSON from an IDL Protocol but support
|
13
13
|
for imports is still limited.
|
14
14
|
|
15
|
+
Additional background on why we developed `avro-builder` is provided
|
16
|
+
[here](http://blog.salsify.com/engineering/adventures-in-avro).
|
17
|
+
|
15
18
|
## Features
|
16
19
|
* The syntax is designed for ease-of-use.
|
17
20
|
* Definitions can be imported by name. This includes auto-loading from a configured
|
18
21
|
set of paths. This allows definitions to split across files and even reused
|
19
22
|
between projects.
|
20
23
|
* Record definitions can inherit from other record definitions.
|
24
|
+
* [Schema Store](#schema-store) to load files written in the DSL and return
|
25
|
+
`Avro::Schema` objects.
|
21
26
|
|
22
27
|
## Limitations
|
23
28
|
|
@@ -45,7 +50,7 @@ Or install it yourself as:
|
|
45
50
|
|
46
51
|
## Usage
|
47
52
|
|
48
|
-
To use `Avro::Builder
|
53
|
+
To use `Avro::Builder`, define a schema:
|
49
54
|
|
50
55
|
```ruby
|
51
56
|
namespace 'com.example'
|
@@ -246,6 +251,31 @@ record using `extends <record_name>`. This adds all of the fields from
|
|
246
251
|
the referenced record to the current record. The current record may override
|
247
252
|
fields in the record that it extends.
|
248
253
|
|
254
|
+
## Schema Store
|
255
|
+
|
256
|
+
The `Avro::Builder::SchemaStore` can be used to load DSL files and return cached
|
257
|
+
`Avro::Schema` objects. This schema store can be used as the schema store for
|
258
|
+
[avromatic](https://github.com/salsify/avromatic)
|
259
|
+
to generate models directly from schemas defined using the DSL.
|
260
|
+
|
261
|
+
The schema store must be initialized with the path where DSL files are located:
|
262
|
+
|
263
|
+
```ruby
|
264
|
+
schema_store = Avro::Builder::SchemaStore.new(path: '/path/to/dsl/files')
|
265
|
+
schema_store.find('schema_name', 'my_namespace')
|
266
|
+
#=> Avro::Schema (for file at '/path/to/dsl/files/my_namespace/schema_name.rb')
|
267
|
+
```
|
268
|
+
|
269
|
+
To configure `Avromatic` to use this schema store and its Messaging API:
|
270
|
+
|
271
|
+
```ruby
|
272
|
+
Avromatic.configure do |config|
|
273
|
+
config.schema_store = Avro::Builder::SchemaStore.new(path: 'avro/dsl')
|
274
|
+
config.registry_url = 'https://builder:avro@avro-schema-registry.salsify.com'
|
275
|
+
config.build_messaging!
|
276
|
+
end
|
277
|
+
```
|
278
|
+
|
249
279
|
## Development
|
250
280
|
|
251
281
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
data/lib/avro/builder.rb
CHANGED
data/lib/avro/builder/errors.rb
CHANGED
@@ -0,0 +1,24 @@
|
|
1
|
+
module Avro
|
2
|
+
module Builder
|
3
|
+
# This class implements a schema store that loads Avro::Builder
|
4
|
+
# DSL files and returns Avro::Schema objects.
|
5
|
+
# It implements the same API as AvroTurf::SchemaStore.
|
6
|
+
class SchemaStore
|
7
|
+
def initialize(path: nil)
|
8
|
+
Avro::Builder.add_load_path(path) if path
|
9
|
+
@schemas = {}
|
10
|
+
end
|
11
|
+
|
12
|
+
def find(name, namespace = nil)
|
13
|
+
fullname = Avro::Name.make_fullname(name, namespace)
|
14
|
+
|
15
|
+
@schemas[fullname] ||= Avro::Builder::DSL.new { eval_file(fullname) }
|
16
|
+
.as_schema.tap do |schema|
|
17
|
+
if schema.respond_to?(:fullname) && schema.fullname != fullname
|
18
|
+
raise SchemaError.new(schema.fullname, fullname)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
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.8.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-06-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: avro
|
@@ -157,6 +157,7 @@ files:
|
|
157
157
|
- lib/avro/builder/namespaceable.rb
|
158
158
|
- lib/avro/builder/record.rb
|
159
159
|
- lib/avro/builder/schema_serializer_reference_state.rb
|
160
|
+
- lib/avro/builder/schema_store.rb
|
160
161
|
- lib/avro/builder/type_factory.rb
|
161
162
|
- lib/avro/builder/types.rb
|
162
163
|
- lib/avro/builder/types/array_type.rb
|