avro-builder 0.5.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.overcommit.yml +13 -0
- data/.rubocop.yml +5 -0
- data/CHANGELOG.md +9 -0
- data/Rakefile +3 -3
- data/avro-builder.gemspec +16 -14
- data/bin/setup +1 -2
- data/lib/avro/builder/aliasable.rb +20 -0
- data/lib/avro/builder/dsl.rb +3 -1
- data/lib/avro/builder/dsl_attributes.rb +42 -14
- data/lib/avro/builder/dsl_options.rb +72 -0
- data/lib/avro/builder/errors.rb +14 -4
- data/lib/avro/builder/field.rb +21 -12
- data/lib/avro/builder/file_handler.rb +1 -1
- data/lib/avro/builder/type_factory.rb +3 -3
- data/lib/avro/builder/types/configurable_type.rb +3 -3
- data/lib/avro/builder/types/named_type.rb +7 -8
- data/lib/avro/builder/types/record_type.rb +10 -3
- data/lib/avro/builder/types/type.rb +12 -2
- data/lib/avro/builder/version.rb +1 -1
- metadata +34 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5420ca208ea3fd4e3656158ed44ef8270eb0d22a
|
4
|
+
data.tar.gz: 74375f766022da155afa1421c0cd6068aa24e812
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4a3f0b4e0f8a9107d56d60e85586295b9ca18ae0c0197a646ee917d6ee9f6617148ab47b02cc3ef017e6298dd611bc1cf8e8ff2d08432ead66f1585d0350f7e4
|
7
|
+
data.tar.gz: 6de4bceaee6e27726d62100cece189dc9ef574c2790b23c495a4cc74d6f9852f03805e819edb0d28c63f67ad1d3d0cce7899edc619290b2905aac03cd37b294f
|
data/.overcommit.yml
ADDED
data/.rubocop.yml
ADDED
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,14 @@
|
|
1
1
|
# avro-builder changelog
|
2
2
|
|
3
|
+
## v0.6.0
|
4
|
+
- Support recursive definitions.
|
5
|
+
- Coerce aliases to be represented as an array.
|
6
|
+
- Only allow name and namespace to be set via options, not via a block, for
|
7
|
+
record, enum, and fixed types.
|
8
|
+
- Allow `doc` and `aliases` to be set on both a field and a type defined inline
|
9
|
+
for the field. To set these attributes on the inline type `type_doc` and
|
10
|
+
`type_aliases` must be used in the DSL.
|
11
|
+
|
3
12
|
## v0.5.0
|
4
13
|
- Support references to named types that are defined inline.
|
5
14
|
- Raise an error for duplicate definitions with the same fullname.
|
data/Rakefile
CHANGED
data/avro-builder.gemspec
CHANGED
@@ -4,26 +4,28 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
require 'avro/builder/version'
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name =
|
7
|
+
spec.name = 'avro-builder'
|
8
8
|
spec.version = Avro::Builder::VERSION
|
9
|
-
spec.authors = [
|
10
|
-
spec.email = [
|
9
|
+
spec.authors = ['Salsify Engineering']
|
10
|
+
spec.email = ['engineering@salsify.com']
|
11
11
|
|
12
|
-
spec.summary =
|
12
|
+
spec.summary = 'Ruby DSL to create Avro schemas'
|
13
13
|
spec.description = spec.summary
|
14
|
-
spec.homepage =
|
15
|
-
spec.license =
|
14
|
+
spec.homepage = 'https://github.com/salsify/avro-builder.git'
|
15
|
+
spec.license = 'MIT'
|
16
16
|
|
17
17
|
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
-
spec.bindir =
|
18
|
+
spec.bindir = 'exe'
|
19
19
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
-
spec.require_paths = [
|
20
|
+
spec.require_paths = ['lib']
|
21
21
|
|
22
|
-
spec.add_runtime_dependency
|
22
|
+
spec.add_runtime_dependency 'avro', '>= 1.7.0'
|
23
23
|
|
24
|
-
spec.add_development_dependency
|
25
|
-
spec.add_development_dependency
|
26
|
-
spec.add_development_dependency
|
27
|
-
spec.add_development_dependency
|
28
|
-
spec.add_development_dependency
|
24
|
+
spec.add_development_dependency 'bundler', '~> 1.11'
|
25
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
26
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
27
|
+
spec.add_development_dependency 'json_spec'
|
28
|
+
spec.add_development_dependency 'simplecov'
|
29
|
+
spec.add_development_dependency 'salsify_rubocop', '~> 0.40.0'
|
30
|
+
spec.add_development_dependency 'overcommit'
|
29
31
|
end
|
data/bin/setup
CHANGED
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'avro/builder/dsl_attributes'
|
2
|
+
|
3
|
+
module Avro
|
4
|
+
module Builder
|
5
|
+
|
6
|
+
# This is a shared concern for objects that support aliases via the DSL.
|
7
|
+
module Aliasable
|
8
|
+
def self.included(base)
|
9
|
+
base.dsl_attribute(:aliases) do |*names|
|
10
|
+
if !names.empty?
|
11
|
+
@aliases = names.flatten
|
12
|
+
else
|
13
|
+
@aliases
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
data/lib/avro/builder/dsl.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'avro'
|
2
2
|
require 'avro/builder/errors'
|
3
|
+
require 'avro/builder/dsl_options'
|
3
4
|
require 'avro/builder/dsl_attributes'
|
4
5
|
require 'avro/builder/namespaceable'
|
5
6
|
require 'avro/builder/definition_cache'
|
@@ -14,6 +15,7 @@ module Avro
|
|
14
15
|
# This class is used to construct Avro schemas (not protocols) using a ruby
|
15
16
|
# DSL
|
16
17
|
class DSL
|
18
|
+
include Avro::Builder::DslOptions
|
17
19
|
include Avro::Builder::DslAttributes
|
18
20
|
include Avro::Builder::FileHandler
|
19
21
|
include Avro::Builder::TypeFactory
|
@@ -84,7 +86,7 @@ module Avro
|
|
84
86
|
options: options,
|
85
87
|
&block).tap do |type|
|
86
88
|
type.validate!
|
87
|
-
@last_object =
|
89
|
+
@last_object = type
|
88
90
|
end
|
89
91
|
end
|
90
92
|
|
@@ -2,14 +2,14 @@ module Avro
|
|
2
2
|
module Builder
|
3
3
|
|
4
4
|
# This module provides methods for defining attributes that can be
|
5
|
-
# set
|
5
|
+
# set via the DSL on various objects.
|
6
6
|
#
|
7
7
|
# The methods generated for DSL attributes are combined getter/setters
|
8
8
|
# of the form:
|
9
9
|
#
|
10
10
|
# attribute(value = nil)
|
11
11
|
#
|
12
|
-
# When value is provided the attribute is set, and when it is nil the
|
12
|
+
# When a value is provided the attribute is set, and when it is nil the
|
13
13
|
# current value is returned.
|
14
14
|
#
|
15
15
|
# When a DSL attribute is defined, the class also keeps track of the
|
@@ -19,32 +19,38 @@ module Avro
|
|
19
19
|
base.extend ClassMethods
|
20
20
|
end
|
21
21
|
|
22
|
-
def
|
22
|
+
def dsl_attribute?(name)
|
23
23
|
self.class.dsl_attribute_names.include?(name.to_sym)
|
24
24
|
end
|
25
25
|
|
26
26
|
module ClassMethods
|
27
|
-
def dsl_attributes(*names)
|
28
|
-
names.each do |name|
|
29
|
-
dsl_attribute_names << name
|
30
|
-
ivar = :"@#{name}"
|
31
|
-
define_method(name) do |value = nil|
|
32
|
-
value ? instance_variable_set(ivar, value) : instance_variable_get(ivar)
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
27
|
# If a block is specified then it is used to define the
|
38
28
|
# combined getter/setter method for the DSL attribute.
|
39
29
|
def dsl_attribute(name, &block)
|
40
30
|
if block_given?
|
41
|
-
|
31
|
+
add_attribute_name(name)
|
42
32
|
define_method(name, &block)
|
33
|
+
alias_writer(name)
|
43
34
|
else
|
44
35
|
dsl_attributes(name)
|
45
36
|
end
|
46
37
|
end
|
47
38
|
|
39
|
+
def dsl_attributes(*names)
|
40
|
+
raise 'a block can only be specified with dsl_attribute' if block_given?
|
41
|
+
|
42
|
+
names.each do |name|
|
43
|
+
add_attribute_name(name)
|
44
|
+
define_accessor(name)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def dsl_attribute_alias(new_name, old_name)
|
49
|
+
alias_method(new_name, old_name)
|
50
|
+
alias_writer(new_name)
|
51
|
+
add_attribute_name(new_name)
|
52
|
+
end
|
53
|
+
|
48
54
|
def dsl_attribute_names
|
49
55
|
@dsl_attribute_names ||=
|
50
56
|
if superclass.respond_to?(:dsl_attribute_names)
|
@@ -53,6 +59,28 @@ module Avro
|
|
53
59
|
Set.new
|
54
60
|
end
|
55
61
|
end
|
62
|
+
|
63
|
+
private
|
64
|
+
|
65
|
+
def add_attribute_name(name)
|
66
|
+
dsl_attribute_names << name
|
67
|
+
add_option_name(name)
|
68
|
+
end
|
69
|
+
|
70
|
+
def define_accessor(name)
|
71
|
+
ivar = :"@#{name}"
|
72
|
+
define_method(name) do |value = nil|
|
73
|
+
value.nil? ? instance_variable_get(ivar) : instance_variable_set(ivar, value)
|
74
|
+
end
|
75
|
+
alias_writer(name)
|
76
|
+
end
|
77
|
+
|
78
|
+
# The writer (name=) method is used to set attributes via options.
|
79
|
+
def alias_writer(name)
|
80
|
+
writer = "#{name}="
|
81
|
+
alias_method(writer, name)
|
82
|
+
private(writer)
|
83
|
+
end
|
56
84
|
end
|
57
85
|
end
|
58
86
|
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
module Avro
|
2
|
+
module Builder
|
3
|
+
|
4
|
+
# This module provides methods for defining options that can be
|
5
|
+
# set via the DSL on various objects.
|
6
|
+
#
|
7
|
+
# These attributes can only be set as options via the private
|
8
|
+
# #attribute= methods, and not as methods in DSL block.
|
9
|
+
#
|
10
|
+
# When a DSL option is defined, the class also keeps track of the
|
11
|
+
# option names.
|
12
|
+
module DslOptions
|
13
|
+
def self.included(base)
|
14
|
+
base.extend ClassMethods
|
15
|
+
end
|
16
|
+
|
17
|
+
def dsl_option?(name)
|
18
|
+
self.class.dsl_option_names.include?(name.to_sym)
|
19
|
+
end
|
20
|
+
|
21
|
+
module ClassMethods
|
22
|
+
# A DSL option is only settable as an option, not as method in a block.
|
23
|
+
def dsl_option(name, &block)
|
24
|
+
add_option_name(name)
|
25
|
+
define_private_writer(name)
|
26
|
+
define_reader(name, &block)
|
27
|
+
end
|
28
|
+
|
29
|
+
def dsl_option_names
|
30
|
+
@dsl_option_names ||=
|
31
|
+
if superclass.respond_to?(:dsl_option_names)
|
32
|
+
superclass.dsl_option_names.dup
|
33
|
+
else
|
34
|
+
Set.new
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
def add_option_name(name)
|
41
|
+
dsl_option_names << name
|
42
|
+
end
|
43
|
+
|
44
|
+
def define_private_writer(name)
|
45
|
+
attr_writer(name)
|
46
|
+
private("#{name}=")
|
47
|
+
end
|
48
|
+
|
49
|
+
# Define a accessor method that raises an error if called as a writer.
|
50
|
+
# If the optional block is specified then it is evaluated as the reader.
|
51
|
+
def define_reader(name, &block)
|
52
|
+
if block_given?
|
53
|
+
define_method(name) do |value = nil|
|
54
|
+
value ? unsupported_block_attribute(name, type_name) : instance_eval(&block)
|
55
|
+
end
|
56
|
+
else
|
57
|
+
define_method(name) do |value = nil|
|
58
|
+
value ? unsupported_block_attribute(name, type_name) : instance_variable_get("@#{name}")
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
private
|
65
|
+
|
66
|
+
def unsupported_block_attribute(attribute, type)
|
67
|
+
raise UnsupportedBlockAttributeError.new(attribute: attribute,
|
68
|
+
type: type)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
data/lib/avro/builder/errors.rb
CHANGED
@@ -28,15 +28,25 @@ module Avro
|
|
28
28
|
|
29
29
|
class DefinitionNotFoundError < StandardError
|
30
30
|
def initialize(name)
|
31
|
-
super("definition not found for '#{name
|
31
|
+
super("definition not found for '#{name}'.#{suggest_namespace(name)}")
|
32
32
|
end
|
33
33
|
|
34
34
|
private
|
35
35
|
|
36
36
|
def suggest_namespace(name)
|
37
|
-
unless name.to_s.index('.')
|
38
|
-
|
39
|
-
|
37
|
+
' Try specifying the full namespace.' unless name.to_s.index('.')
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
class UnsupportedBlockAttributeError < StandardError
|
42
|
+
def initialize(attribute:, type:, field: nil)
|
43
|
+
target = if field
|
44
|
+
"field '#{field}' of type :#{type}"
|
45
|
+
else
|
46
|
+
"type :#{type}"
|
47
|
+
end
|
48
|
+
super("'#{attribute}' must be set directly using an option on #{target}, "\
|
49
|
+
'not via a block')
|
40
50
|
end
|
41
51
|
end
|
42
52
|
end
|
data/lib/avro/builder/field.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'avro/builder/type_factory'
|
2
|
+
require 'avro/builder/aliasable'
|
2
3
|
|
3
4
|
module Avro
|
4
5
|
module Builder
|
@@ -6,13 +7,17 @@ module Avro
|
|
6
7
|
# This class represents a field in a record.
|
7
8
|
# A field must be initialized with a type.
|
8
9
|
class Field
|
10
|
+
include Avro::Builder::DslOptions
|
9
11
|
include Avro::Builder::DslAttributes
|
10
12
|
include Avro::Builder::TypeFactory
|
13
|
+
include Avro::Builder::Aliasable
|
11
14
|
|
12
|
-
INTERNAL_ATTRIBUTES =
|
15
|
+
INTERNAL_ATTRIBUTES = %i(optional_field).to_set.freeze
|
13
16
|
|
14
17
|
# These attributes may be set as options or via a block in the DSL
|
15
|
-
dsl_attributes :doc, :
|
18
|
+
dsl_attributes :doc, :default, :order
|
19
|
+
|
20
|
+
attr_reader :name
|
16
21
|
|
17
22
|
def initialize(name:, type_name:, record:, cache:, internal: {}, options: {}, &block)
|
18
23
|
@cache = cache
|
@@ -23,8 +28,9 @@ module Avro
|
|
23
28
|
send("#{key}=", value) if INTERNAL_ATTRIBUTES.include?(key)
|
24
29
|
end
|
25
30
|
|
26
|
-
options.
|
27
|
-
|
31
|
+
type_options = options.dup
|
32
|
+
options.keys.each do |key|
|
33
|
+
send(key, type_options.delete(key)) if dsl_attribute?(key)
|
28
34
|
end
|
29
35
|
|
30
36
|
@type = if builtin_type?(type_name)
|
@@ -32,26 +38,24 @@ module Avro
|
|
32
38
|
field: self,
|
33
39
|
cache: cache,
|
34
40
|
internal: internal,
|
35
|
-
options:
|
41
|
+
options: type_options)
|
36
42
|
else
|
37
|
-
named_type = true
|
38
43
|
cache.lookup_named_type(type_name, namespace)
|
39
44
|
end
|
40
45
|
|
41
46
|
# DSL calls must be evaluated after the type has been constructed
|
42
47
|
instance_eval(&block) if block_given?
|
43
48
|
@type.validate!
|
44
|
-
@type.cache! unless named_type
|
45
49
|
end
|
46
50
|
|
47
51
|
## Delegate additional DSL calls to the type
|
48
52
|
|
49
|
-
def respond_to_missing?(id,
|
50
|
-
|
53
|
+
def respond_to_missing?(id, _include_all)
|
54
|
+
type.dsl_respond_to?(id) || super
|
51
55
|
end
|
52
56
|
|
53
57
|
def method_missing(id, *args, &block)
|
54
|
-
type.
|
58
|
+
type.dsl_respond_to?(id) ? type.send(id, *args, &block) : super
|
55
59
|
end
|
56
60
|
|
57
61
|
def name_fragment
|
@@ -62,7 +66,9 @@ module Avro
|
|
62
66
|
# and return the namespace value from the enclosing record.
|
63
67
|
def namespace(value = nil)
|
64
68
|
if value
|
65
|
-
|
69
|
+
raise UnsupportedBlockAttributeError.new(attribute: :namespace,
|
70
|
+
field: @name,
|
71
|
+
type: type.type_name)
|
66
72
|
else
|
67
73
|
record.namespace
|
68
74
|
end
|
@@ -71,7 +77,9 @@ module Avro
|
|
71
77
|
# Delegate setting name explicitly via DSL to type
|
72
78
|
def name(value = nil)
|
73
79
|
if value
|
74
|
-
|
80
|
+
raise UnsupportedBlockAttributeError.new(attribute: :name,
|
81
|
+
field: @name,
|
82
|
+
type: type.type_name)
|
75
83
|
else
|
76
84
|
# Return the name of the field
|
77
85
|
@name
|
@@ -79,6 +87,7 @@ module Avro
|
|
79
87
|
end
|
80
88
|
|
81
89
|
def serialize(reference_state)
|
90
|
+
# TODO: order is not included here
|
82
91
|
{
|
83
92
|
name: name,
|
84
93
|
type: serialized_type(reference_state),
|
@@ -26,7 +26,7 @@ module Avro
|
|
26
26
|
# and ends with a .rb extension. Additionally, if the name contains
|
27
27
|
# a namespace then ensure that periods (.) are replaced by forward
|
28
28
|
# slashes. E.g. for 'test.example' search for '/test/example.rb'.
|
29
|
-
file_name = "/#{name.to_s.
|
29
|
+
file_name = "/#{name.to_s.tr('.', '/').sub(/^\//, '').sub(/\.rb$/, '')}.rb"
|
30
30
|
matches = self.class.load_paths.flat_map do |load_path|
|
31
31
|
Dir["#{load_path}/**/*.rb"].select do |file_path|
|
32
32
|
file_path.end_with?(file_name)
|
@@ -12,10 +12,9 @@ module Avro
|
|
12
12
|
# Return a new Type instance
|
13
13
|
def create_builtin_type(type_name, field:, cache:)
|
14
14
|
name = type_name.to_s.downcase
|
15
|
-
|
16
|
-
when Avro::Schema::PRIMITIVE_TYPES.include?(name)
|
15
|
+
if Avro::Schema::PRIMITIVE_TYPES.include?(name)
|
17
16
|
Avro::Builder::Types::Type.new(name, field: field, cache: cache)
|
18
|
-
|
17
|
+
elsif COMPLEX_TYPES.include?(name)
|
19
18
|
Avro::Builder::Types.const_get("#{name.capitalize}Type").new(field: field, cache: cache)
|
20
19
|
else
|
21
20
|
raise "Invalid builtin type: #{type_name}"
|
@@ -32,6 +31,7 @@ module Avro
|
|
32
31
|
&block)
|
33
32
|
create_builtin_type(type_name, field: field, cache: cache).tap do |type|
|
34
33
|
type.configure_options(internal.merge(options))
|
34
|
+
type.cache!
|
35
35
|
type.instance_eval(&block) if block_given?
|
36
36
|
end
|
37
37
|
end
|
@@ -2,12 +2,12 @@ module Avro
|
|
2
2
|
module Builder
|
3
3
|
module Types
|
4
4
|
|
5
|
-
# This concern is used by Types that can be configured
|
6
|
-
# attributes.
|
5
|
+
# This concern is used by Types that can be configured via the DSL.
|
6
|
+
# Only attributes that can be set via options are configured here.
|
7
7
|
module ConfigurableType
|
8
8
|
def configure_options(options = {})
|
9
9
|
options.each do |key, value|
|
10
|
-
send(key, value) if
|
10
|
+
send("#{key}=", value) if dsl_option?(key)
|
11
11
|
end
|
12
12
|
end
|
13
13
|
end
|
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'avro/builder/types/configurable_type'
|
2
2
|
require 'avro/builder/namespaceable'
|
3
|
+
require 'avro/builder/aliasable'
|
3
4
|
|
4
5
|
module Avro
|
5
6
|
module Builder
|
@@ -11,17 +12,15 @@ module Avro
|
|
11
12
|
include Avro::Builder::Types::ComplexType
|
12
13
|
include Avro::Builder::Namespaceable
|
13
14
|
include Avro::Builder::Types::ConfigurableType
|
15
|
+
include Avro::Builder::Aliasable
|
14
16
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
if value
|
19
|
-
@name = value
|
20
|
-
else
|
21
|
-
@name || "__#{name_fragment}_#{type_name}"
|
22
|
-
end
|
17
|
+
dsl_option :namespace
|
18
|
+
dsl_option :name do
|
19
|
+
@name || "__#{name_fragment}_#{type_name}"
|
23
20
|
end
|
24
21
|
|
22
|
+
dsl_attribute_alias :type_aliases, :aliases
|
23
|
+
|
25
24
|
def validate!
|
26
25
|
required_attribute_error!(:name) if field.nil? && @name.nil?
|
27
26
|
end
|
@@ -1,11 +1,14 @@
|
|
1
1
|
module Avro
|
2
2
|
module Builder
|
3
3
|
module Types
|
4
|
-
|
5
|
-
|
4
|
+
# This class represents a record in an Avro schema. Records may be defined
|
5
|
+
# at the top-level or as the type for a field in a record.
|
6
6
|
class RecordType < Avro::Builder::Types::NamedType
|
7
7
|
|
8
|
-
|
8
|
+
DSL_METHODS = %i(required optional extends).to_set.freeze
|
9
|
+
|
10
|
+
dsl_attribute :doc
|
11
|
+
dsl_attribute_alias :type_doc, :doc
|
9
12
|
|
10
13
|
def initialize(name = nil, options: {}, cache:, field: nil, &block)
|
11
14
|
@type_name = :record
|
@@ -17,6 +20,10 @@ module Avro
|
|
17
20
|
instance_eval(&block) if block_given?
|
18
21
|
end
|
19
22
|
|
23
|
+
def dsl_method?(name)
|
24
|
+
DSL_METHODS.include?(name)
|
25
|
+
end
|
26
|
+
|
20
27
|
# Add a required field to the record
|
21
28
|
def required(name, type_name, options = {}, &block)
|
22
29
|
new_field = Avro::Builder::Field.new(name: name,
|
@@ -5,6 +5,7 @@ module Avro
|
|
5
5
|
# type is constructed. The type has no additional attributes, and
|
6
6
|
# the type is serialized as just the type name.
|
7
7
|
class Type
|
8
|
+
include Avro::Builder::DslOptions
|
8
9
|
include Avro::Builder::DslAttributes
|
9
10
|
|
10
11
|
attr_reader :type_name
|
@@ -42,6 +43,17 @@ module Avro
|
|
42
43
|
def cache!
|
43
44
|
end
|
44
45
|
|
46
|
+
# Subclasses can override this method to indicate that the name
|
47
|
+
# is a method that the type exposes in the DSL. These methods are in
|
48
|
+
# addition to the methods for setting attributes on a type.
|
49
|
+
def dsl_method?(_name)
|
50
|
+
false
|
51
|
+
end
|
52
|
+
|
53
|
+
def dsl_respond_to?(name)
|
54
|
+
dsl_attribute?(name) || dsl_method?(name)
|
55
|
+
end
|
56
|
+
|
45
57
|
private
|
46
58
|
|
47
59
|
def required_attribute_error!(attribute_name)
|
@@ -58,8 +70,6 @@ module Avro
|
|
58
70
|
end
|
59
71
|
end
|
60
72
|
|
61
|
-
private
|
62
|
-
|
63
73
|
attr_accessor :field, :cache
|
64
74
|
end
|
65
75
|
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.6.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-
|
11
|
+
date: 2016-05-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: avro
|
@@ -94,6 +94,34 @@ dependencies:
|
|
94
94
|
- - ">="
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: salsify_rubocop
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 0.40.0
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 0.40.0
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: overcommit
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
97
125
|
description: Ruby DSL to create Avro schemas
|
98
126
|
email:
|
99
127
|
- engineering@salsify.com
|
@@ -102,7 +130,9 @@ extensions: []
|
|
102
130
|
extra_rdoc_files: []
|
103
131
|
files:
|
104
132
|
- ".gitignore"
|
133
|
+
- ".overcommit.yml"
|
105
134
|
- ".rspec"
|
135
|
+
- ".rubocop.yml"
|
106
136
|
- ".travis.yml"
|
107
137
|
- CHANGELOG.md
|
108
138
|
- Gemfile
|
@@ -113,9 +143,11 @@ files:
|
|
113
143
|
- bin/console
|
114
144
|
- bin/setup
|
115
145
|
- lib/avro/builder.rb
|
146
|
+
- lib/avro/builder/aliasable.rb
|
116
147
|
- lib/avro/builder/definition_cache.rb
|
117
148
|
- lib/avro/builder/dsl.rb
|
118
149
|
- lib/avro/builder/dsl_attributes.rb
|
150
|
+
- lib/avro/builder/dsl_options.rb
|
119
151
|
- lib/avro/builder/errors.rb
|
120
152
|
- lib/avro/builder/field.rb
|
121
153
|
- lib/avro/builder/file_handler.rb
|