avro-builder 0.15.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. checksums.yaml +5 -5
  2. data/.circleci/config.yml +77 -0
  3. data/.gitignore +1 -0
  4. data/.rubocop.yml +8 -0
  5. data/.ruby-version +1 -1
  6. data/Appraisals +6 -4
  7. data/CHANGELOG.md +21 -0
  8. data/Gemfile +2 -0
  9. data/README.md +39 -13
  10. data/Rakefile +2 -0
  11. data/avro-builder.gemspec +12 -7
  12. data/gemfiles/{avro_official.gemfile → avro_1.10.gemfile} +2 -2
  13. data/gemfiles/avro_1.9.gemfile +7 -0
  14. data/lib/avro/builder.rb +2 -0
  15. data/lib/avro/builder/aliasable.rb +2 -0
  16. data/lib/avro/builder/anonymous_types.rb +2 -0
  17. data/lib/avro/builder/definition_cache.rb +4 -3
  18. data/lib/avro/builder/dsl.rb +14 -2
  19. data/lib/avro/builder/dsl_attributes.rb +2 -0
  20. data/lib/avro/builder/dsl_options.rb +2 -0
  21. data/lib/avro/builder/enum.rb +2 -0
  22. data/lib/avro/builder/errors.rb +2 -0
  23. data/lib/avro/builder/field.rb +3 -1
  24. data/lib/avro/builder/file_handler.rb +5 -1
  25. data/lib/avro/builder/fixed.rb +2 -0
  26. data/lib/avro/builder/namespaceable.rb +2 -0
  27. data/lib/avro/builder/railtie.rb +3 -1
  28. data/lib/avro/builder/rake/avro_generate_task.rb +4 -0
  29. data/lib/avro/builder/rake/rails_avro_generate_task.rake +3 -1
  30. data/lib/avro/builder/record.rb +2 -0
  31. data/lib/avro/builder/schema_serializer_reference_state.rb +2 -0
  32. data/lib/avro/builder/schema_store.rb +2 -0
  33. data/lib/avro/builder/type_factory.rb +4 -2
  34. data/lib/avro/builder/types.rb +2 -0
  35. data/lib/avro/builder/types/array_type.rb +2 -0
  36. data/lib/avro/builder/types/complex_type.rb +2 -0
  37. data/lib/avro/builder/types/enum_type.rb +11 -2
  38. data/lib/avro/builder/types/fixed_type.rb +2 -0
  39. data/lib/avro/builder/types/map_type.rb +2 -0
  40. data/lib/avro/builder/types/named_error_handling.rb +2 -0
  41. data/lib/avro/builder/types/named_type.rb +2 -0
  42. data/lib/avro/builder/types/record_type.rb +7 -4
  43. data/lib/avro/builder/types/top_level.rb +2 -0
  44. data/lib/avro/builder/types/type.rb +3 -3
  45. data/lib/avro/builder/types/type_referencer.rb +2 -0
  46. data/lib/avro/builder/types/union_type.rb +3 -1
  47. data/lib/avro/builder/version.rb +3 -1
  48. metadata +66 -33
  49. data/.travis.yml +0 -13
  50. data/gemfiles/avro_salsify_fork.gemfile +0 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 357f3e243725cab3c4a9d595b9dc5354516a59c2
4
- data.tar.gz: 54c370ee125d1840cbba0bce0879e6f806655c69
2
+ SHA256:
3
+ metadata.gz: dec624f01d72838e79c5d671db5e8e5df329fecc72bb2cb4b782a5f50f591936
4
+ data.tar.gz: 02d143c8181c2e196b3d488a086104c528d45b843be9319d4a1766716056b63a
5
5
  SHA512:
6
- metadata.gz: 6ab7ebf14ce0260287ca1bf23fb3b60ca13eeb276543bc67c391dc63be4b407f554133eec462b062336c715ad8b82bd09140e9eccebb1b4e824e2531607e5ed9
7
- data.tar.gz: cc50e28935cc9ff1c7d58ac6518e44ffcf02a225e32eb8d8b0b9f66cf47a2efd7e1171b78d060663ff26a7b015f07782997d349453d098cb0c243719ab7c9872
6
+ metadata.gz: 22c5c781421196c20ec4232ec0341d0c10420a5dbb6e7a9b9ddf4864f7372419763f9a7d36671fb323e94a077dc1fdffb76df6347bfe71d961fff2255951abbb
7
+ data.tar.gz: 0dc6f9d230c3719e268fa433798f440402d169f63eb8b522a73641e94769792c6a66c0cd9dda145cc5cc2faa4ae44b66723690afd8995d7b4eb43ae8adfb125c
@@ -0,0 +1,77 @@
1
+ version: 2.1
2
+ jobs:
3
+ lint:
4
+ docker:
5
+ - image: salsify/ruby_ci:2.6.6
6
+ working_directory: ~/avro-builder
7
+ steps:
8
+ - checkout
9
+ - restore_cache:
10
+ keys:
11
+ - v2-gems-ruby-2.6.6-{{ checksum "avro-builder.gemspec" }}-{{ checksum "Gemfile" }}
12
+ - v2-gems-ruby-2.6.6-
13
+ - run:
14
+ name: Install Gems
15
+ command: |
16
+ if ! bundle check --path=vendor/bundle; then
17
+ bundle install --path=vendor/bundle --jobs=4 --retry=3
18
+ bundle clean
19
+ fi
20
+ - save_cache:
21
+ key: v2-gems-ruby-2.6.6-{{ checksum "avro-builder.gemspec" }}-{{ checksum "Gemfile" }}
22
+ paths:
23
+ - "vendor/bundle"
24
+ - "gemfiles/vendor/bundle"
25
+ - run:
26
+ name: Run Rubocop
27
+ command: bundle exec rubocop
28
+ test:
29
+ parameters:
30
+ gemfile:
31
+ type: string
32
+ ruby-version:
33
+ type: string
34
+ docker:
35
+ - image: salsify/ruby_ci:<< parameters.ruby-version >>
36
+ environment:
37
+ CIRCLE_TEST_REPORTS: "test-results"
38
+ BUNDLE_GEMFILE: << parameters.gemfile >>
39
+ working_directory: ~/avro-builder
40
+ steps:
41
+ - checkout
42
+ - restore_cache:
43
+ keys:
44
+ - v2-gems-ruby-<< parameters.ruby-version >>-{{ checksum "avro-builder.gemspec" }}-{{ checksum "<< parameters.gemfile >>" }}
45
+ - v2-gems-ruby-<< parameters.ruby-version >>-
46
+ - run:
47
+ name: Install Gems
48
+ command: |
49
+ if ! bundle check --path=vendor/bundle; then
50
+ bundle install --path=vendor/bundle --jobs=4 --retry=3
51
+ bundle clean
52
+ fi
53
+ - save_cache:
54
+ key: v2-gems-ruby-<< parameters.ruby-version >>-{{ checksum "avro-builder.gemspec" }}-{{ checksum "<< parameters.gemfile >>" }}
55
+ paths:
56
+ - "vendor/bundle"
57
+ - "gemfiles/vendor/bundle"
58
+ - run:
59
+ name: Run Tests
60
+ command: |
61
+ bundle exec rspec --format RspecJunitFormatter --out $CIRCLE_TEST_REPORTS/rspec/junit.xml --format progress spec
62
+ - store_test_results:
63
+ path: "test-results"
64
+ workflows:
65
+ build:
66
+ jobs:
67
+ - lint
68
+ - test:
69
+ matrix:
70
+ parameters:
71
+ gemfile:
72
+ - "gemfiles/avro_1.9.gemfile"
73
+ - "gemfiles/avro_1.10.gemfile"
74
+ ruby-version:
75
+ - "2.6.6"
76
+ - "2.7.2"
77
+ - "3.0.0"
data/.gitignore CHANGED
@@ -8,3 +8,4 @@
8
8
  /spec/reports/
9
9
  /tmp/
10
10
  /gemfiles/*.lock
11
+ /gemfiles/.bundle
data/.rubocop.yml CHANGED
@@ -1,5 +1,13 @@
1
1
  inherit_gem:
2
2
  salsify_rubocop: conf/rubocop.yml
3
3
 
4
+ AllCops:
5
+ inherit_mode:
6
+ merge:
7
+ - Exclude
8
+ NewCops: disable
9
+ Exclude:
10
+ - "gemfiles/**/*"
11
+
4
12
  Style/RaiseArgs:
5
13
  EnforcedStyle: compact
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- ruby-2.3.3
1
+ 2.6.6
data/Appraisals CHANGED
@@ -1,7 +1,9 @@
1
- appraise 'avro-official' do
2
- gem 'avro', '1.8.1'
1
+ # frozen_string_literal: true
2
+
3
+ appraise 'avro-1.9' do
4
+ gem 'avro', '1.9.2'
3
5
  end
4
6
 
5
- appraise 'avro-salsify-fork' do
6
- gem 'avro-salsify-fork', '1.9.0.0', require: 'avro'
7
+ appraise 'avro-1.10' do
8
+ gem 'avro', '1.10.1'
7
9
  end
data/CHANGELOG.md CHANGED
@@ -1,5 +1,26 @@
1
1
  # avro-builder changelog
2
2
 
3
+ ## v1.0.0
4
+ - Drop support for Avro < 1.9.
5
+ - Drop support for Ruby < 2.6.
6
+ - Add Ruby 3.0 support.
7
+ - Bug fix: Use multi_json to encode schemas and ensure that a JSON encoder
8
+ is always present.
9
+
10
+ ## v0.17.0
11
+ - Add support for enum defaults introduced in Avro v1.10.0.
12
+
13
+ ## v0.16.2
14
+ - Allow avro version up to v1.10.x. Support will be added for new
15
+ functionality in Avro v1.10 in a later release.
16
+
17
+ ## v0.16.1
18
+ - Require avro version prior to v1.10.0.
19
+
20
+ ## v0.16.0
21
+ - Add support for providing an explicit `namespace` on `extend`.
22
+ - Default lookup to current namespace before falling back on global search.
23
+
3
24
  ## v0.15.0
4
25
  - Add support for declaring types as abstract.
5
26
 
data/Gemfile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
 
3
5
  # Specify your gem's dependencies in avro-builder.gemspec
data/README.md CHANGED
@@ -1,9 +1,9 @@
1
1
  # Avro::Builder
2
2
 
3
- [![Build Status](https://travis-ci.org/salsify/avro-builder.svg?branch=master)][travis]
3
+ [![Build Status](https://circleci.com/gh/salsify/avro-builder.svg?style=svg)][circleci]
4
4
  [![Gem Version](https://badge.fury.io/rb/avro-builder.svg)](https://badge.fury.io/rb/avro-builder)
5
5
 
6
- [travis]: http://travis-ci.org/salsify/avro-builder
6
+ [circleci]: https://circleci.com/gh/salsify/avro-builder
7
7
 
8
8
  `Avro::Builder` provides a Ruby DSL to create [Apache Avro](https://avro.apache.org/docs/current/) Schemas.
9
9
 
@@ -165,6 +165,9 @@ fixed :g, size: 8
165
165
  enum :e, :X, :Y, :Z
166
166
  enum :d, symbols: [:A, :B]
167
167
 
168
+ # defaults can be set for enums with Ruby Avro v1.10.0
169
+ enum :c, symbols: [:A, :B], default: :A
170
+
168
171
  record :my_record_with_named do
169
172
  required :f_ref, :f
170
173
  required :fixed_inline, :fixed, size: 9
@@ -280,17 +283,6 @@ The DSL supports setting a logical type on any type except a union. The logical
280
283
  types defined in the Avro [spec](https://avro.apache.org/docs/1.8.1/spec.html#Logical+Types)
281
284
  are more limited.
282
285
 
283
- The official Ruby `avro` gem does not yet support logical types:
284
- [AVRO-1695](https://issues.apache.org/jira/browse/AVRO-1695).
285
-
286
- There is a `avro-salsify-fork` gem released from this
287
- [fork](https://github.com/salsify/avro) that includes changes to support
288
- encoding and decoding logical types. To use this gem, reference it in your Gemfile:
289
-
290
- ```ruby
291
- gem 'avro-salsify-fork', require: 'avro'
292
- ```
293
-
294
286
  A logical type can be specified for a field using the `logical_type` attribute:
295
287
 
296
288
  ```ruby
@@ -381,6 +373,40 @@ record using `extends <record_name>`. This adds all of the fields from
381
373
  the referenced record to the current record. The current record may override
382
374
  fields in the record that it extends.
383
375
 
376
+ ```
377
+ record :original do
378
+ required :first, :string
379
+ required :second, :int
380
+ end
381
+
382
+ record :extended do
383
+ extends :original
384
+ optional :first, :string
385
+ end
386
+ ```
387
+
388
+ Additionally you can provide a `namespace` to `extends` if necessary to remove ambiguity.
389
+
390
+ ```
391
+ namespace 'com.newbie'
392
+
393
+ record :original, namespace: 'com.og' do
394
+ required :first, :string
395
+ required :second, :int
396
+ end
397
+
398
+ record :original do
399
+ required :first, :string
400
+ required :second, :int
401
+ end
402
+
403
+ record :extended do
404
+ extends :original, namespace: 'com.og'
405
+ optional :first, :string
406
+ end
407
+ ```
408
+
409
+
384
410
  ## Schema Store
385
411
 
386
412
  The `Avro::Builder::SchemaStore` can be used to load DSL files and return cached
data/Rakefile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'bundler/gem_tasks'
2
4
  require 'rspec/core/rake_task'
3
5
  require 'appraisal/task'
data/avro-builder.gemspec CHANGED
@@ -1,5 +1,6 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
3
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
5
  require 'avro/builder/version'
5
6
 
@@ -19,15 +20,19 @@ Gem::Specification.new do |spec|
19
20
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
21
  spec.require_paths = ['lib']
21
22
 
22
- spec.add_runtime_dependency 'avro', '>= 1.7.0'
23
+ spec.required_ruby_version = '>= 2.6'
24
+
25
+ spec.add_runtime_dependency 'avro', '>= 1.9.0', '< 1.11'
26
+ spec.add_runtime_dependency 'multi_json'
23
27
 
24
28
  spec.add_development_dependency 'appraisal'
25
- spec.add_development_dependency 'bundler', '~> 1.11'
29
+ spec.add_development_dependency 'bundler', '~> 2.0'
30
+ spec.add_development_dependency 'json_spec'
31
+ spec.add_development_dependency 'overcommit'
26
32
  spec.add_development_dependency 'rake', '~> 10.0'
27
33
  spec.add_development_dependency 'rspec', '~> 3.0'
28
34
  spec.add_development_dependency 'rspec-its'
29
- spec.add_development_dependency 'json_spec'
35
+ spec.add_development_dependency 'rspec_junit_formatter'
36
+ spec.add_development_dependency 'salsify_rubocop', '~> 1.0.1'
30
37
  spec.add_development_dependency 'simplecov'
31
- spec.add_development_dependency 'salsify_rubocop', '~> 0.47.0'
32
- spec.add_development_dependency 'overcommit'
33
38
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- gem "avro", "1.8.1"
5
+ gem "avro", "1.10.1"
6
6
 
7
- gemspec :path => "../"
7
+ gemspec path: "../"
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "avro", "1.9.2"
6
+
7
+ gemspec path: "../"
data/lib/avro/builder.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'avro/builder/version'
2
4
  require 'avro/builder/dsl'
3
5
  require 'avro/builder/schema_store'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'avro/builder/dsl_attributes'
2
4
 
3
5
  module Avro
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Avro
2
4
  module Builder
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Avro
2
4
  module Builder
3
5
 
@@ -22,9 +24,7 @@ module Avro
22
24
  key_str = Avro::Name.make_fullname(key.to_s, namespace && namespace.to_s)
23
25
  object = schema_objects[key_str]
24
26
 
25
- if object.nil? && !schema_names.include?(key.to_s)
26
- object = builder.import(key)
27
- end
27
+ object = builder.import(key) if object.nil? && !schema_names.include?(key.to_s)
28
28
 
29
29
  raise DefinitionNotFoundError.new(key) if object.nil? && namespace.nil?
30
30
 
@@ -59,6 +59,7 @@ module Avro
59
59
 
60
60
  def store_by_fullname(object, fullname = object.fullname)
61
61
  raise DuplicateDefinitionError.new(fullname, object, schema_objects[fullname]) if schema_objects.key?(fullname)
62
+
62
63
  schema_objects.store(fullname, object)
63
64
  end
64
65
 
@@ -1,4 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'avro'
4
+ require 'multi_json'
2
5
  require 'avro/builder/errors'
3
6
  require 'avro/builder/dsl_options'
4
7
  require 'avro/builder/dsl_attributes'
@@ -75,7 +78,7 @@ module Avro
75
78
  # Return the last schema object processed as an Avro JSON schema
76
79
  def to_json(validate: true, pretty: true)
77
80
  hash = to_h
78
- (pretty ? JSON.pretty_generate(hash) : hash.to_json).tap do |json|
81
+ MultiJson.dump(hash, { pretty: pretty }).tap do |json|
79
82
  # Uncomment the next line to debug:
80
83
  # puts json
81
84
  # Parse the schema to validate before returning
@@ -96,6 +99,7 @@ module Avro
96
99
  def type_macro(name, type_object, options = {})
97
100
  raise "#{type_object.inspect} must be a type object" unless type_object.is_a?(Types::Type)
98
101
  raise "namespace cannot be included in name: #{name}" if name.to_s.index('.')
102
+
99
103
  type_clone = type_object.clone
100
104
  type_clone.send(:abstract=, true)
101
105
  cache.add_type_by_name(type_clone, name, options[:namespace] || namespace)
@@ -118,7 +122,15 @@ module Avro
118
122
  end
119
123
 
120
124
  def eval_file(name)
121
- file_path = find_file(name)
125
+ file_path = if namespace
126
+ begin
127
+ find_file([namespace, name].join('.'))
128
+ rescue FileNotFoundError
129
+ find_file(name)
130
+ end
131
+ else
132
+ find_file(name)
133
+ end
122
134
  instance_eval(File.read(file_path), file_path)
123
135
  end
124
136
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Avro
2
4
  module Builder
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Avro
2
4
  module Builder
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Avro
2
4
  module Builder
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Avro
2
4
  module Builder
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'avro/builder/type_factory'
2
4
  require 'avro/builder/aliasable'
3
5
 
@@ -12,7 +14,7 @@ module Avro
12
14
  include Avro::Builder::Aliasable
13
15
  include Avro::Builder::AnonymousTypes
14
16
 
15
- INTERNAL_ATTRIBUTES = %i(optional_field).to_set.freeze
17
+ INTERNAL_ATTRIBUTES = [:optional_field].to_set.freeze
16
18
 
17
19
  # These attributes may be set as options or via a block in the DSL
18
20
  dsl_attributes :doc, :default, :order
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Avro
2
4
  module Builder
3
5
  # TODO: eventually this should be refactored into something standalone
@@ -19,6 +21,8 @@ module Avro
19
21
  File.read(find_file(name))
20
22
  end
21
23
 
24
+ FileNotFoundError = Class.new(StandardError)
25
+
22
26
  def find_file(name)
23
27
  # Ensure that the file_name that is searched for begins with a slash (/)
24
28
  # and ends with a .rb extension. Additionally, if the name contains
@@ -31,7 +35,7 @@ module Avro
31
35
  end
32
36
  end.uniq
33
37
  raise "Multiple matches: #{matches}" if matches.size > 1
34
- raise "File not found #{file_name}" if matches.empty?
38
+ raise FileNotFoundError.new("File not found #{file_name}") if matches.empty?
35
39
 
36
40
  matches.first
37
41
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Avro
2
4
  module Builder
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Avro
2
4
  module Builder
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Avro
2
4
  module Builder
3
5
  class Railtie < Rails::Railtie
@@ -7,7 +9,7 @@ module Avro
7
9
  end
8
10
 
9
11
  rake_tasks do
10
- load File.expand_path('../rake/rails_avro_generate_task.rake', __FILE__)
12
+ load File.expand_path('rake/rails_avro_generate_task.rake', __dir__)
11
13
  end
12
14
  end
13
15
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rake/tasklib'
2
4
  require 'avro/builder'
3
5
 
@@ -10,6 +12,7 @@ module Avro
10
12
  :load_paths, :dependencies, :filetype
11
13
 
12
14
  def initialize(name: :generate, dependencies: [])
15
+ super()
13
16
  @name = name
14
17
  @task_namespace = :avro
15
18
  @task_desc = 'Generate Avro schema files from Avro::Builder DSL'
@@ -31,6 +34,7 @@ module Avro
31
34
  desc task_desc
32
35
  task(name.to_sym => dependencies) do
33
36
  raise '"root" must be specified for Avro DSL files' unless root
37
+
34
38
  Avro::Builder.add_load_path(*[root, load_paths].flatten)
35
39
  Dir["#{root}/**/*.rb"].each do |dsl_file|
36
40
  puts "Generating Avro schema from #{dsl_file}"
@@ -1,2 +1,4 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'avro/builder/rake/avro_generate_task'
2
- Avro::Builder::Rake::AvroGenerateTask.new(dependencies: %i(environment))
4
+ Avro::Builder::Rake::AvroGenerateTask.new(dependencies: [:environment])
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Avro
2
4
  module Builder
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Avro
2
4
  module Builder
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Avro
2
4
  module Builder
3
5
  # This class implements a schema store that loads Avro::Builder
@@ -1,11 +1,13 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Avro
2
4
  module Builder
3
5
 
4
6
  # This concern is used by classes that create new Type instances.
5
7
  module TypeFactory
6
8
 
7
- NAMED_TYPES = %w(enum fixed record).map(&:freeze).to_set.freeze
8
- COMPLEX_TYPES = %w(array enum fixed map record union).map(&:freeze).to_set.freeze
9
+ NAMED_TYPES = ['enum', 'fixed', 'record'].map(&:freeze).to_set.freeze
10
+ COMPLEX_TYPES = ['array', 'enum', 'fixed', 'map', 'record', 'union'].map(&:freeze).to_set.freeze
9
11
  BUILTIN_TYPES = Avro::Schema::PRIMITIVE_TYPES.union(COMPLEX_TYPES).freeze
10
12
 
11
13
  private
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'avro/builder/types/type'
2
4
  require 'avro/builder/types/complex_type'
3
5
  require 'avro/builder/types/type_referencer'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Avro
2
4
  module Builder
3
5
  module Types
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Avro
2
4
  module Builder
3
5
  module Types
@@ -1,9 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Avro
2
4
  module Builder
3
5
  module Types
4
6
  class EnumType < NamedType
5
7
 
6
- dsl_attribute :doc
8
+ dsl_attributes :doc, :default
7
9
 
8
10
  dsl_attribute :symbols do |*values|
9
11
  # Define symbols explicitly to support values as a splat or single array
@@ -25,12 +27,19 @@ module Avro
25
27
  def validate!
26
28
  super
27
29
  validate_required_attribute!(:symbols)
30
+ validate_enum_default!
28
31
  end
29
32
 
30
33
  private
31
34
 
35
+ def validate_enum_default!
36
+ if !default.nil? && !symbols.map(&:to_sym).include?(default.to_sym)
37
+ raise AttributeError.new("enum default '#{default}' must be one of the enum symbols: #{symbols}")
38
+ end
39
+ end
40
+
32
41
  def serialized_attributes
33
- { symbols: symbols, doc: doc }
42
+ { symbols: symbols, doc: doc, default: default }
34
43
  end
35
44
  end
36
45
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Avro
2
4
  module Builder
3
5
  module Types
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Avro
2
4
  module Builder
3
5
  module Types
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Avro
2
4
  module Builder
3
5
  module Types
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'avro/builder/namespaceable'
2
4
  require 'avro/builder/aliasable'
3
5
  require 'avro/builder/types/named_error_handling'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Avro
2
4
  module Builder
3
5
  module Types
@@ -6,12 +8,13 @@ module Avro
6
8
  class RecordType < Avro::Builder::Types::NamedType
7
9
  include Avro::Builder::AnonymousTypes
8
10
 
9
- DSL_METHODS = %i(required optional extends).to_set.freeze
11
+ DSL_METHODS = [:required, :optional, :extends].to_set.freeze
10
12
 
11
13
  dsl_attribute :doc
12
14
  dsl_attribute_alias :type_doc, :doc
13
15
 
14
- def initialize(name = nil, options: {}, cache:, field: nil, &block)
16
+ def initialize(name = nil, cache:, options: {}, field: nil, &block) # rubocop:disable Lint/MissingSuper
17
+ # TODO: Fix missing call to super
15
18
  @avro_type_name = :record
16
19
  @name = name
17
20
  @cache = cache
@@ -53,8 +56,8 @@ module Avro
53
56
 
54
57
  # Adds fields from the record with the specified name to the current
55
58
  # record.
56
- def extends(name)
57
- fields.merge!(cache.lookup_named_type(name, namespace).duplicated_fields)
59
+ def extends(name, options = {})
60
+ fields.merge!(cache.lookup_named_type(name, options.delete(:namespace) || namespace).duplicated_fields)
58
61
  end
59
62
 
60
63
  def to_h(reference_state = SchemaSerializerReferenceState.new)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Avro
2
4
  module Builder
3
5
  module Types
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Avro
2
4
  module Builder
3
5
  module Types
@@ -82,9 +84,7 @@ module Avro
82
84
 
83
85
  def validate_required_attribute!(attribute_name)
84
86
  value = public_send(attribute_name)
85
- if value.nil? || value.respond_to?(:empty?) && value.empty?
86
- required_attribute_error!(attribute_name)
87
- end
87
+ required_attribute_error!(attribute_name) if value.nil? || value.respond_to?(:empty?) && value.empty?
88
88
  end
89
89
 
90
90
  attr_accessor :field, :cache
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'avro/builder/type_factory'
2
4
 
3
5
  module Avro
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Avro
2
4
  module Builder
3
5
  module Types
@@ -5,7 +7,7 @@ module Avro
5
7
  include Avro::Builder::Types::ComplexType
6
8
  include Avro::Builder::Types::TypeReferencer
7
9
 
8
- NULL_TYPE = 'null'.freeze
10
+ NULL_TYPE = 'null'
9
11
 
10
12
  dsl_attribute :types do |*types|
11
13
  if !types.empty?
@@ -1,5 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Avro
2
4
  module Builder
3
- VERSION = '0.15.0'.freeze
5
+ VERSION = '1.0.0'
4
6
  end
5
7
  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.15.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Salsify Engineering
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-03-27 00:00:00.000000000 Z
11
+ date: 2021-02-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: avro
@@ -16,14 +16,34 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 1.7.0
19
+ version: 1.9.0
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '1.11'
20
23
  type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
23
26
  requirements:
24
27
  - - ">="
25
28
  - !ruby/object:Gem::Version
26
- version: 1.7.0
29
+ version: 1.9.0
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '1.11'
33
+ - !ruby/object:Gem::Dependency
34
+ name: multi_json
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ type: :runtime
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
27
47
  - !ruby/object:Gem::Dependency
28
48
  name: appraisal
29
49
  requirement: !ruby/object:Gem::Requirement
@@ -44,58 +64,72 @@ dependencies:
44
64
  requirements:
45
65
  - - "~>"
46
66
  - !ruby/object:Gem::Version
47
- version: '1.11'
67
+ version: '2.0'
48
68
  type: :development
49
69
  prerelease: false
50
70
  version_requirements: !ruby/object:Gem::Requirement
51
71
  requirements:
52
72
  - - "~>"
53
73
  - !ruby/object:Gem::Version
54
- version: '1.11'
74
+ version: '2.0'
55
75
  - !ruby/object:Gem::Dependency
56
- name: rake
76
+ name: json_spec
57
77
  requirement: !ruby/object:Gem::Requirement
58
78
  requirements:
59
- - - "~>"
79
+ - - ">="
60
80
  - !ruby/object:Gem::Version
61
- version: '10.0'
81
+ version: '0'
62
82
  type: :development
63
83
  prerelease: false
64
84
  version_requirements: !ruby/object:Gem::Requirement
65
85
  requirements:
66
- - - "~>"
86
+ - - ">="
67
87
  - !ruby/object:Gem::Version
68
- version: '10.0'
88
+ version: '0'
69
89
  - !ruby/object:Gem::Dependency
70
- name: rspec
90
+ name: overcommit
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ type: :development
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ - !ruby/object:Gem::Dependency
104
+ name: rake
71
105
  requirement: !ruby/object:Gem::Requirement
72
106
  requirements:
73
107
  - - "~>"
74
108
  - !ruby/object:Gem::Version
75
- version: '3.0'
109
+ version: '10.0'
76
110
  type: :development
77
111
  prerelease: false
78
112
  version_requirements: !ruby/object:Gem::Requirement
79
113
  requirements:
80
114
  - - "~>"
81
115
  - !ruby/object:Gem::Version
82
- version: '3.0'
116
+ version: '10.0'
83
117
  - !ruby/object:Gem::Dependency
84
- name: rspec-its
118
+ name: rspec
85
119
  requirement: !ruby/object:Gem::Requirement
86
120
  requirements:
87
- - - ">="
121
+ - - "~>"
88
122
  - !ruby/object:Gem::Version
89
- version: '0'
123
+ version: '3.0'
90
124
  type: :development
91
125
  prerelease: false
92
126
  version_requirements: !ruby/object:Gem::Requirement
93
127
  requirements:
94
- - - ">="
128
+ - - "~>"
95
129
  - !ruby/object:Gem::Version
96
- version: '0'
130
+ version: '3.0'
97
131
  - !ruby/object:Gem::Dependency
98
- name: json_spec
132
+ name: rspec-its
99
133
  requirement: !ruby/object:Gem::Requirement
100
134
  requirements:
101
135
  - - ">="
@@ -109,7 +143,7 @@ dependencies:
109
143
  - !ruby/object:Gem::Version
110
144
  version: '0'
111
145
  - !ruby/object:Gem::Dependency
112
- name: simplecov
146
+ name: rspec_junit_formatter
113
147
  requirement: !ruby/object:Gem::Requirement
114
148
  requirements:
115
149
  - - ">="
@@ -128,16 +162,16 @@ dependencies:
128
162
  requirements:
129
163
  - - "~>"
130
164
  - !ruby/object:Gem::Version
131
- version: 0.47.0
165
+ version: 1.0.1
132
166
  type: :development
133
167
  prerelease: false
134
168
  version_requirements: !ruby/object:Gem::Requirement
135
169
  requirements:
136
170
  - - "~>"
137
171
  - !ruby/object:Gem::Version
138
- version: 0.47.0
172
+ version: 1.0.1
139
173
  - !ruby/object:Gem::Dependency
140
- name: overcommit
174
+ name: simplecov
141
175
  requirement: !ruby/object:Gem::Requirement
142
176
  requirements:
143
177
  - - ">="
@@ -157,12 +191,12 @@ executables: []
157
191
  extensions: []
158
192
  extra_rdoc_files: []
159
193
  files:
194
+ - ".circleci/config.yml"
160
195
  - ".gitignore"
161
196
  - ".overcommit.yml"
162
197
  - ".rspec"
163
198
  - ".rubocop.yml"
164
199
  - ".ruby-version"
165
- - ".travis.yml"
166
200
  - Appraisals
167
201
  - CHANGELOG.md
168
202
  - Gemfile
@@ -172,8 +206,8 @@ files:
172
206
  - avro-builder.gemspec
173
207
  - bin/console
174
208
  - bin/setup
175
- - gemfiles/avro_official.gemfile
176
- - gemfiles/avro_salsify_fork.gemfile
209
+ - gemfiles/avro_1.10.gemfile
210
+ - gemfiles/avro_1.9.gemfile
177
211
  - lib/avro/builder.rb
178
212
  - lib/avro/builder/aliasable.rb
179
213
  - lib/avro/builder/anonymous_types.rb
@@ -212,7 +246,7 @@ homepage: https://github.com/salsify/avro-builder.git
212
246
  licenses:
213
247
  - MIT
214
248
  metadata: {}
215
- post_install_message:
249
+ post_install_message:
216
250
  rdoc_options: []
217
251
  require_paths:
218
252
  - lib
@@ -220,16 +254,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
220
254
  requirements:
221
255
  - - ">="
222
256
  - !ruby/object:Gem::Version
223
- version: '0'
257
+ version: '2.6'
224
258
  required_rubygems_version: !ruby/object:Gem::Requirement
225
259
  requirements:
226
260
  - - ">="
227
261
  - !ruby/object:Gem::Version
228
262
  version: '0'
229
263
  requirements: []
230
- rubyforge_project:
231
- rubygems_version: 2.6.10
232
- signing_key:
264
+ rubygems_version: 3.0.3
265
+ signing_key:
233
266
  specification_version: 4
234
267
  summary: Ruby DSL to create Avro schemas
235
268
  test_files: []
data/.travis.yml DELETED
@@ -1,13 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - 2.4.0
4
- - 2.3.3
5
- - 2.2.6
6
- before_install:
7
- - gem update --system
8
- before_script:
9
- - bundle exec appraisal install --jobs=3
10
- script:
11
- - bundle exec rubocop
12
- - bundle exec appraisal avro-official rspec
13
- - bundle exec appraisal avro-salsify-fork rspec
@@ -1,7 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "avro-salsify-fork", "1.9.0.0", :require => "avro"
6
-
7
- gemspec :path => "../"