avro-builder 0.3.2 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rspec +2 -0
- data/CHANGELOG.md +5 -0
- data/README.md +17 -2
- data/lib/avro/builder/dsl.rb +6 -12
- data/lib/avro/builder/errors.rb +15 -0
- data/lib/avro/builder/field.rb +1 -0
- data/lib/avro/builder/types/array_type.rb +4 -0
- data/lib/avro/builder/types/enum_type.rb +5 -0
- data/lib/avro/builder/types/fixed_type.rb +5 -0
- data/lib/avro/builder/types/map_type.rb +4 -0
- data/lib/avro/builder/types/named_type.rb +4 -0
- data/lib/avro/builder/types/type.rb +21 -0
- data/lib/avro/builder/types/union_type.rb +4 -0
- data/lib/avro/builder/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a2caec0734e6bf6ba5d83e453fe9d067f9f47fa6
|
4
|
+
data.tar.gz: 79fca4e7bf6c5bc9ad9bbcb2425afb902e1b9026
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 73e3846ea11202adb26505a47bc3ec7a7772f10f1ff7560593788926922a9c9b45ece9c49bc2fecb0df48627923b44dcc23603cad25020d7c45314f64fcd191f
|
7
|
+
data.tar.gz: ae4ffe269bbd87c8fdc6f548898eb3fbf3749781604744f8f79deb38133670a5cdc4a5f2dec0347ff94fb568c0e2e2ae5a1411b4d69efecd32db0f4ceff8bd57
|
data/.rspec
ADDED
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,10 @@
|
|
1
1
|
# avro-builder changelog
|
2
2
|
|
3
|
+
## v0.4.0
|
4
|
+
- Add validation for required DSL attributes that are not specified.
|
5
|
+
- Allow name to be configured via a block for top-level record, enum, and fixed
|
6
|
+
types.
|
7
|
+
|
3
8
|
## v0.3.2
|
4
9
|
- Fix a bug that allowed the partial matching of filenames.
|
5
10
|
- Fix a bug that prevented namespace from being specified as an option on
|
data/README.md
CHANGED
@@ -24,7 +24,7 @@ This DSL was created because:
|
|
24
24
|
* Only Avro Schemas, not Protocols are supported.
|
25
25
|
* See [Issues](https://github.com/salsify/avro-builder/issues) for functionality
|
26
26
|
that has yet to be implemented.
|
27
|
-
* This is
|
27
|
+
* This is beta quality code. There may be breaking changes until version 1.0 is
|
28
28
|
released.
|
29
29
|
|
30
30
|
## Installation
|
@@ -60,6 +60,8 @@ record :user do
|
|
60
60
|
required :type, :user_type, default: :REGULAR
|
61
61
|
required :pw, :password
|
62
62
|
optional :full_name, :string
|
63
|
+
required :nicknames, :array, items: :string
|
64
|
+
required :permissions, :map, values: :bytes
|
63
65
|
end
|
64
66
|
```
|
65
67
|
|
@@ -110,6 +112,20 @@ This generates the following Avro JSON schema:
|
|
110
112
|
"string"
|
111
113
|
],
|
112
114
|
"default": null
|
115
|
+
},
|
116
|
+
{
|
117
|
+
"name": "nicknames",
|
118
|
+
"type": {
|
119
|
+
"type": "array",
|
120
|
+
"items": "string"
|
121
|
+
}
|
122
|
+
},
|
123
|
+
{
|
124
|
+
"name": "permissions",
|
125
|
+
"type": {
|
126
|
+
"type": "map",
|
127
|
+
"values": "bytes"
|
128
|
+
}
|
113
129
|
}
|
114
130
|
]
|
115
131
|
}
|
@@ -243,4 +259,3 @@ Issues and pull requests are welcome on GitHub at https://github.com/salsify/avr
|
|
243
259
|
## License
|
244
260
|
|
245
261
|
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
246
|
-
|
data/lib/avro/builder/dsl.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'avro'
|
2
|
+
require 'avro/builder/errors'
|
2
3
|
require 'avro/builder/dsl_attributes'
|
3
4
|
require 'avro/builder/namespaceable'
|
4
5
|
require 'avro/builder/type_factory'
|
@@ -25,8 +26,8 @@ module Avro
|
|
25
26
|
end
|
26
27
|
|
27
28
|
# Define an Avro schema record
|
28
|
-
def record(name, options = {}, &block)
|
29
|
-
|
29
|
+
def record(name = nil, options = {}, &block)
|
30
|
+
create_named_type(name, :record, options, &block)
|
30
31
|
end
|
31
32
|
|
32
33
|
# Imports from the file with specified name fragment.
|
@@ -38,11 +39,11 @@ module Avro
|
|
38
39
|
|
39
40
|
## DSL methods for Types
|
40
41
|
|
41
|
-
def enum(name, *symbols, **options, &block)
|
42
|
+
def enum(name = nil, *symbols, **options, &block)
|
42
43
|
create_named_type(name, :enum, { symbols: symbols }.merge(options), &block)
|
43
44
|
end
|
44
45
|
|
45
|
-
def fixed(name, size = nil, options = {}, &block)
|
46
|
+
def fixed(name = nil, size = nil, options = {}, &block)
|
46
47
|
size_option = size.is_a?(Hash) ? size : { size: size }
|
47
48
|
create_named_type(name, :fixed, size_option.merge(options), &block)
|
48
49
|
end
|
@@ -104,18 +105,11 @@ module Avro
|
|
104
105
|
internal: { name: name, namespace: namespace },
|
105
106
|
options: options,
|
106
107
|
&block).tap do |type|
|
108
|
+
type.validate!
|
107
109
|
add_schema_object(type)
|
108
110
|
end
|
109
111
|
end
|
110
112
|
|
111
|
-
def build_record(name, options, &block)
|
112
|
-
Avro::Builder::Types::RecordType
|
113
|
-
.new(name, { namespace: namespace }.merge(options)).tap do |record|
|
114
|
-
record.builder = builder
|
115
|
-
record.instance_eval(&block)
|
116
|
-
end
|
117
|
-
end
|
118
|
-
|
119
113
|
def eval_file(name)
|
120
114
|
instance_eval(read_file(name))
|
121
115
|
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Avro
|
2
|
+
module Builder
|
3
|
+
|
4
|
+
class RequiredAttributeError < StandardError
|
5
|
+
def initialize(type:, attribute:, field: nil, name: nil)
|
6
|
+
location = if field
|
7
|
+
"field '#{field}' of "
|
8
|
+
elsif name
|
9
|
+
"'#{name}' of "
|
10
|
+
end
|
11
|
+
super("attribute :#{attribute} missing for #{location}type :#{type}")
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/lib/avro/builder/field.rb
CHANGED
@@ -30,6 +30,27 @@ module Avro
|
|
30
30
|
def self.union_with_null(serialized)
|
31
31
|
[:null, serialized]
|
32
32
|
end
|
33
|
+
|
34
|
+
# Subclasses should override this method to check for the presence
|
35
|
+
# of required DSL attributes.
|
36
|
+
def validate!
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
def required_attribute_error!(attribute_name)
|
42
|
+
raise RequiredAttributeError.new(type: type_name,
|
43
|
+
attribute: attribute_name,
|
44
|
+
field: field && field.name,
|
45
|
+
name: @name)
|
46
|
+
end
|
47
|
+
|
48
|
+
def validate_required_attribute!(attribute_name)
|
49
|
+
value = public_send(attribute_name)
|
50
|
+
if value.nil? || value.respond_to?(:empty?) && value.empty?
|
51
|
+
required_attribute_error!(attribute_name)
|
52
|
+
end
|
53
|
+
end
|
33
54
|
end
|
34
55
|
end
|
35
56
|
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.4.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-
|
11
|
+
date: 2016-05-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: avro
|
@@ -102,6 +102,7 @@ extensions: []
|
|
102
102
|
extra_rdoc_files: []
|
103
103
|
files:
|
104
104
|
- ".gitignore"
|
105
|
+
- ".rspec"
|
105
106
|
- ".travis.yml"
|
106
107
|
- CHANGELOG.md
|
107
108
|
- Gemfile
|
@@ -114,6 +115,7 @@ files:
|
|
114
115
|
- lib/avro/builder.rb
|
115
116
|
- lib/avro/builder/dsl.rb
|
116
117
|
- lib/avro/builder/dsl_attributes.rb
|
118
|
+
- lib/avro/builder/errors.rb
|
117
119
|
- lib/avro/builder/field.rb
|
118
120
|
- lib/avro/builder/file_handler.rb
|
119
121
|
- lib/avro/builder/namespaceable.rb
|