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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 55be55b48ed971e75719a7c77d72002a384ae371
4
- data.tar.gz: 164cddb8d0eb7ab54df709751bc0bd3d0b9a4164
3
+ metadata.gz: 102f64b688e2d8f26a65c2235860d4c161f41645
4
+ data.tar.gz: 48f49e771a762072dab576f79ccdfd2f951b3dfa
5
5
  SHA512:
6
- metadata.gz: af77d1df17425d13af42225a8c1ca04e99464e1a907c588699159cf0b0b6248e1fa1af1443f1de64ec186680ec03a895547157e1923cef62132d49e69552e16f
7
- data.tar.gz: 31bd7491a67a0cd075fbf193aa896cadb27ca0ce9c68851bf1e2aa4b302678ae14c34cc81ae1b327523f4c7d450df8f2eeba1f42cff0b6d491826c21c4785e1c
6
+ metadata.gz: c93f99d97e6e63d0bae808f7608cf4f627fb5efe928ef7ba6da4ef00fda6119e29b94802bda1d21c0a86bd1fc184f102aa4ebdf79688d55df10b3b4534b7680d
7
+ data.tar.gz: 78dd456fa89680f448ac176e58e3ae3bfadf3954fcb2ea044406db22bdaf65a5d74924d3354c7bbe3e0dd46e00d8afb5f06d7cac215cf30fe47c9042466db846
@@ -1,5 +1,7 @@
1
1
  language: ruby
2
2
  rvm:
3
3
  - 2.2.4
4
- - 2.3.0
5
- before_install: gem install bundler -v 1.11.2
4
+ - 2.3.1
5
+ script:
6
+ - bundle exec rubocop
7
+ - bundle exec rspec
@@ -1,5 +1,8 @@
1
1
  # avro-builder changelog
2
2
 
3
+ ## v0.8.0
4
+ - Add `Avro::Builder::SchemaStore` to load DSL files and return schema objects.
5
+
3
6
  ## v0.7.0
4
7
  - Only allow `type_name` and `type_namespace` options for naming named types
5
8
  defined inline.
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` define a schema:
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.
@@ -1,5 +1,6 @@
1
1
  require 'avro/builder/version'
2
2
  require 'avro/builder/dsl'
3
+ require 'avro/builder/schema_store'
3
4
 
4
5
  module Avro
5
6
  module Builder
@@ -38,6 +38,12 @@ module Avro
38
38
  end
39
39
  end
40
40
 
41
+ class SchemaError < StandardError
42
+ def initialize(actual, expected)
43
+ super("expected schema '#{actual}' to define type '#{expected}'")
44
+ end
45
+ end
46
+
41
47
  AttributeError = Class.new(StandardError)
42
48
  end
43
49
  end
@@ -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
@@ -1,5 +1,5 @@
1
1
  module Avro
2
2
  module Builder
3
- VERSION = '0.7.0'.freeze
3
+ VERSION = '0.8.0'.freeze
4
4
  end
5
5
  end
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.7.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-05-27 00:00:00.000000000 Z
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