avro-builder 0.14.1 → 0.15.0.rc0

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: 69d3eb1e937d77bb8d5f3b868509c69dc105b2aa
4
- data.tar.gz: f638c4459b959ecb39abad6d311e360a31185d42
3
+ metadata.gz: 6bd5352172e109727099592f904b03ecfba50d48
4
+ data.tar.gz: a729d03c744b064c9a9677c88c9c93225c9db52a
5
5
  SHA512:
6
- metadata.gz: 779bb6e3904c33882b733bde8b2c93b17763c272dbe27191d153b4dafacef47172b491a91dcd3ff98e4c9326a572997eb1b47862ef50f79e78a960d14e9f65fe
7
- data.tar.gz: 63680ea96c10abe0848185190df7b0472fef02c6083b3dff9fc75f97d766590edb95026738082b8485c10e1b1e5a0303e5b83d8a55d63be41b73ec9cb773a487
6
+ metadata.gz: 5f918eb9cbfb7afc951945162092b869819ef3ef3880fca68d49534afc0d3eda73bf0916a75f889c68e98db2a26f551de62e4e08acb3c94198fb92230ef63642
7
+ data.tar.gz: 6f33b3efe33499c221769e744b5cccd3aa053012adef5f57b75ca12a89590044755a01f02072b1517a96f58449073aea07a134508b8a1bc5660a8968096d0324
@@ -1,5 +1,8 @@
1
1
  # avro-builder changelog
2
2
 
3
+ ## v0.15.0
4
+ - Add support for declaring types as abstract.
5
+
3
6
  ## v0.14.1
4
7
  - File handling fixes.
5
8
 
data/README.md CHANGED
@@ -316,6 +316,25 @@ record :with_date_array
316
316
  end
317
317
  ```
318
318
 
319
+ ### Abstract Types
320
+
321
+ Types can be declared as abstract in the DSL. Declaring a type as abstract
322
+ prevents the rake task from generating an Avro JSON schema for the type.
323
+
324
+ A type can be declared as abstract using either an option or a method in the
325
+ DSL when defining the type:
326
+
327
+ ```ruby
328
+ record :unique_id, abstract: true
329
+ required :uuid, :fixed, size: 38
330
+ end
331
+
332
+ enum :status do
333
+ symbols %w(valid invalid)
334
+ abstract true
335
+ end
336
+ ```
337
+
319
338
  ### Type Macros
320
339
 
321
340
  `avro-builder` allows type macros to be defined that expand to types that
@@ -339,6 +358,9 @@ type_macro :timestamp, long(logical_type: 'timestamp-millis'),
339
358
  namespace: 'com.my_company'
340
359
  ```
341
360
 
361
+ Type macros are always marked as abstract and do not generate an Avro JSON
362
+ schema file when using the rake task.
363
+
342
364
  ### Auto-loading and Imports
343
365
 
344
366
  Specify paths to search for definitions:
@@ -25,6 +25,7 @@ Gem::Specification.new do |spec|
25
25
  spec.add_development_dependency 'bundler', '~> 1.11'
26
26
  spec.add_development_dependency 'rake', '~> 10.0'
27
27
  spec.add_development_dependency 'rspec', '~> 3.0'
28
+ spec.add_development_dependency 'rspec-its'
28
29
  spec.add_development_dependency 'json_spec'
29
30
  spec.add_development_dependency 'simplecov'
30
31
  spec.add_development_dependency 'salsify_rubocop', '~> 0.47.0'
@@ -5,12 +5,17 @@ require 'avro/builder/schema_store'
5
5
  module Avro
6
6
  module Builder
7
7
 
8
+ # Accepts a string or block to eval and returns the Avro::Builder::DSL object
9
+ def self.build_dsl(str = nil, filename: nil, &block)
10
+ Avro::Builder::DSL.new(str, filename: filename, &block)
11
+ end
12
+
8
13
  # Accepts a string or block to eval to define a JSON schema
9
14
  def self.build(str = nil, filename: nil, &block)
10
15
  Avro::Builder::DSL.new(str, filename: filename, &block).to_json
11
16
  end
12
17
 
13
- # Accepts a string or block to eval and returns an Avro::Schema
18
+ # Accepts a string or block to eval and returns an Avro::Schema object
14
19
  def self.build_schema(str = nil, filename: nil, &block)
15
20
  Avro::Builder::DSL.new(str, filename: filename, &block).as_schema
16
21
  end
@@ -38,6 +38,10 @@ module Avro
38
38
  end
39
39
  end
40
40
 
41
+ def abstract?
42
+ @last_object && @last_object.abstract?
43
+ end
44
+
41
45
  # Define an Avro schema record
42
46
  def record(name = nil, options = {}, &block)
43
47
  create_named_type(name, :record, options, &block)
@@ -92,7 +96,10 @@ module Avro
92
96
  def type_macro(name, type_object, options = {})
93
97
  raise "#{type_object.inspect} must be a type object" unless type_object.is_a?(Types::Type)
94
98
  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)
99
+ type_clone = type_object.clone
100
+ type_clone.send(:abstract=, true)
101
+ cache.add_type_by_name(type_clone, name, options[:namespace] || namespace)
102
+ @last_object = type_clone
96
103
  end
97
104
 
98
105
  private
@@ -35,9 +35,17 @@ module Avro
35
35
  Dir["#{root}/**/*.rb"].each do |dsl_file|
36
36
  puts "Generating Avro schema from #{dsl_file}"
37
37
  output_file = dsl_file.sub('/dsl/', '/schema/').sub(/\.rb$/, ".#{filetype}")
38
- schema = Avro::Builder.build(filename: dsl_file)
39
- FileUtils.mkdir_p(File.dirname(output_file))
40
- File.write(output_file, schema.end_with?("\n") ? schema : schema << "\n")
38
+ dsl = Avro::Builder.build_dsl(filename: dsl_file)
39
+ if dsl.abstract?
40
+ if File.exist?(output_file)
41
+ puts "... Removing #{output_file} for abstract type"
42
+ FileUtils.rm(output_file)
43
+ end
44
+ else
45
+ schema = dsl.to_json
46
+ FileUtils.mkdir_p(File.dirname(output_file))
47
+ File.write(output_file, schema.end_with?("\n") ? schema : schema << "\n")
48
+ end
41
49
  end
42
50
  end
43
51
  end
@@ -18,7 +18,7 @@ module Avro
18
18
 
19
19
  dsl_attribute_alias :type_aliases, :aliases
20
20
 
21
- # This module most be included after options are defined
21
+ # This module must be included after options are defined
22
22
  include Avro::Builder::Types::NamedErrorHandling
23
23
 
24
24
  def name(value = nil)
@@ -8,7 +8,7 @@ module Avro
8
8
  include Avro::Builder::DslOptions
9
9
  include Avro::Builder::DslAttributes
10
10
 
11
- dsl_attribute :logical_type
11
+ dsl_attributes :logical_type, :abstract
12
12
 
13
13
  attr_reader :avro_type_name
14
14
 
@@ -18,6 +18,10 @@ module Avro
18
18
  @field = field
19
19
  end
20
20
 
21
+ def abstract?
22
+ !!abstract
23
+ end
24
+
21
25
  def serialize(_reference_state)
22
26
  if logical_type
23
27
  { type: avro_type_name, logicalType: logical_type }
@@ -1,5 +1,5 @@
1
1
  module Avro
2
2
  module Builder
3
- VERSION = '0.14.1'.freeze
3
+ VERSION = '0.15.0.rc0'.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.14.1
4
+ version: 0.15.0.rc0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Salsify Engineering
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-03-22 00:00:00.000000000 Z
11
+ date: 2017-03-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: avro
@@ -80,6 +80,20 @@ dependencies:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: '3.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec-its
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: json_spec
85
99
  requirement: !ruby/object:Gem::Requirement
@@ -209,9 +223,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
209
223
  version: '0'
210
224
  required_rubygems_version: !ruby/object:Gem::Requirement
211
225
  requirements:
212
- - - ">="
226
+ - - ">"
213
227
  - !ruby/object:Gem::Version
214
- version: '0'
228
+ version: 1.3.1
215
229
  requirements: []
216
230
  rubyforge_project:
217
231
  rubygems_version: 2.6.10