avro-builder 0.8.0 → 0.9.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: 102f64b688e2d8f26a65c2235860d4c161f41645
4
- data.tar.gz: 48f49e771a762072dab576f79ccdfd2f951b3dfa
3
+ metadata.gz: 6ce24d8f81a853345491ca01f3f152bea7c322e6
4
+ data.tar.gz: 699ae7ae471b75260c8975e9762648c4dfaeed03
5
5
  SHA512:
6
- metadata.gz: c93f99d97e6e63d0bae808f7608cf4f627fb5efe928ef7ba6da4ef00fda6119e29b94802bda1d21c0a86bd1fc184f102aa4ebdf79688d55df10b3b4534b7680d
7
- data.tar.gz: 78dd456fa89680f448ac176e58e3ae3bfadf3954fcb2ea044406db22bdaf65a5d74924d3354c7bbe3e0dd46e00d8afb5f06d7cac215cf30fe47c9042466db846
6
+ metadata.gz: 0a45f164f8639364362fb34546c29ee79a6e352058c14e766958aee088a7e5ffd5bb56cdf9cc5e9986ba277407a45115e2a12bb8508a04aa36442080a7bee7d2
7
+ data.tar.gz: 373081fd2648cadfb035bde881e14c71cd69c30d1feb350cf6ff0a831851167cbb24279316520740609bb77cc9d59a1616796309aff2618bf27f5dc51d6ac166
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # avro-builder changelog
2
2
 
3
+ ## v0.9.0
4
+ - Add rake task to generate Avro JSON schema files for all DSL files under a
5
+ configurable root directory.
6
+ - Add Railtie to configure `#{Rails.root}/avro/dsl` as a load path, and define
7
+ `avro:generate` rake task.
8
+
3
9
  ## v0.8.0
4
10
  - Add `Avro::Builder::SchemaStore` to load DSL files and return schema objects.
5
11
 
data/README.md CHANGED
@@ -1,6 +1,7 @@
1
1
  # Avro::Builder
2
2
 
3
3
  [![Build Status](https://travis-ci.org/salsify/avro-builder.svg?branch=master)][travis]
4
+ [![Gem Version](https://badge.fury.io/rb/avro-builder.svg)](https://badge.fury.io/rb/avro-builder)
4
5
 
5
6
  [travis]: http://travis-ci.org/salsify/avro-builder
6
7
 
@@ -48,6 +49,14 @@ Or install it yourself as:
48
49
 
49
50
  $ gem install avro-builder
50
51
 
52
+ ## Railtie
53
+
54
+ When included in a Rails project, `#{Rails.root}/avro/dsl` is configured as a
55
+ load path for the DSL.
56
+
57
+ A [rake task](#avro-generate-rake-task) is also defined for generating Avro JSON
58
+ schemas from the DSL.
59
+
51
60
  ## Usage
52
61
 
53
62
  To use `Avro::Builder`, define a schema:
@@ -276,6 +285,26 @@ Avromatic.configure do |config|
276
285
  end
277
286
  ```
278
287
 
288
+ ### Avro Generate Rake Task
289
+
290
+ There is a rake task that can be used to generate Avro schemas from all DSL
291
+ files.
292
+
293
+ A rake task is automatically defined via a Railtie for Rails projects that uses
294
+ `#{Rails.root}/avro/dsl` as the root for Avro DSL files.
295
+
296
+ Custom rake tasks can also be defined:
297
+
298
+ ```ruby
299
+ require 'avro/builder/rake/avro_generate_task'
300
+ Avro::Builder::Rake::AvroGenerateTask.new(name: :custom_gen,
301
+ dependencies: [:load_app]) do |task|
302
+ task.root = '/path/to/dsl/files'
303
+ task.load_paths << '/additional/dsl/files'
304
+ end
305
+ )
306
+ ```
307
+
279
308
  ## Development
280
309
 
281
310
  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.
@@ -0,0 +1,14 @@
1
+ module Avro
2
+ module Builder
3
+ class Railtie < Rails::Railtie
4
+
5
+ initializer 'salsify_avro.avro_builder_load_path' do
6
+ Avro::Builder.add_load_path("#{Rails.root}/avro/dsl")
7
+ end
8
+
9
+ rake_tasks do
10
+ load File.expand_path('../rake/rails_avro_generate_task.rake', __FILE__)
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,47 @@
1
+ require 'rake/tasklib'
2
+ require 'avro/builder'
3
+
4
+ module Avro
5
+ module Builder
6
+ module Rake
7
+ class AvroGenerateTask < ::Rake::TaskLib
8
+
9
+ attr_accessor :name, :task_namespace, :task_desc, :root,
10
+ :load_paths, :dependencies
11
+
12
+ def initialize(name: :generate, dependencies: [])
13
+ @name = name
14
+ @task_namespace = :avro
15
+ @task_desc = 'Generate Avro schema files from Avro::Builder DSL'
16
+ @load_paths = []
17
+ @root = "#{Rails.root}/avro/dsl" if defined?(Rails)
18
+ @dependencies = dependencies
19
+
20
+ yield self if block_given?
21
+
22
+ define
23
+ end
24
+
25
+ private
26
+
27
+ # Define the rake task
28
+ def define
29
+ namespace task_namespace do
30
+ desc task_desc
31
+ task(name.to_sym => dependencies) do
32
+ raise '"root" must be specified for Avro DSL files' unless root
33
+ Avro::Builder.add_load_path(*[root, load_paths].flatten)
34
+ Dir["#{root}/**/*.rb"].each do |dsl_file|
35
+ puts "Generating Avro schema from #{dsl_file}"
36
+ output_file = dsl_file.sub('/dsl/', '/schema/').sub(/\.rb$/, '.avsc')
37
+ schema = Avro::Builder.build(File.read(dsl_file))
38
+ FileUtils.mkdir_p(File.dirname(output_file))
39
+ File.write(output_file, schema.end_with?("\n") ? schema : schema << "\n")
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,2 @@
1
+ require 'avro/builder/rake/avro_generate_task'
2
+ Avro::Builder::Rake::AvroGenerateTask.new(dependencies: %i(environment))
@@ -1,5 +1,5 @@
1
1
  module Avro
2
2
  module Builder
3
- VERSION = '0.8.0'.freeze
3
+ VERSION = '0.9.0'.freeze
4
4
  end
5
5
  end
data/lib/avro/builder.rb CHANGED
@@ -21,3 +21,5 @@ module Avro
21
21
  end
22
22
  end
23
23
  end
24
+
25
+ require 'avro/builder/railtie' if defined?(Rails)
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.8.0
4
+ version: 0.9.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-06-28 00:00:00.000000000 Z
11
+ date: 2016-08-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: avro
@@ -155,6 +155,9 @@ files:
155
155
  - lib/avro/builder/file_handler.rb
156
156
  - lib/avro/builder/fixed.rb
157
157
  - lib/avro/builder/namespaceable.rb
158
+ - lib/avro/builder/railtie.rb
159
+ - lib/avro/builder/rake/avro_generate_task.rb
160
+ - lib/avro/builder/rake/rails_avro_generate_task.rake
158
161
  - lib/avro/builder/record.rb
159
162
  - lib/avro/builder/schema_serializer_reference_state.rb
160
163
  - lib/avro/builder/schema_store.rb
@@ -194,7 +197,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
194
197
  version: '0'
195
198
  requirements: []
196
199
  rubyforge_project:
197
- rubygems_version: 2.5.1
200
+ rubygems_version: 2.6.6
198
201
  signing_key:
199
202
  specification_version: 4
200
203
  summary: Ruby DSL to create Avro schemas