lib/avro/builder/field.rb in avro-builder-0.6.0 vs lib/avro/builder/field.rb in avro-builder-0.7.0
- old
+ new
@@ -15,13 +15,11 @@
INTERNAL_ATTRIBUTES = %i(optional_field).to_set.freeze
# These attributes may be set as options or via a block in the DSL
dsl_attributes :doc, :default, :order
- attr_reader :name
-
- def initialize(name:, type_name:, record:, cache:, internal: {}, options: {}, &block)
+ def initialize(name:, avro_type_name:, record:, cache:, internal: {}, options: {}, &block)
@cache = cache
@record = record
@name = name.to_s
internal.each do |key, value|
@@ -31,18 +29,18 @@
type_options = options.dup
options.keys.each do |key|
send(key, type_options.delete(key)) if dsl_attribute?(key)
end
- @type = if builtin_type?(type_name)
- create_and_configure_builtin_type(type_name,
+ @type = if builtin_type?(avro_type_name)
+ create_and_configure_builtin_type(avro_type_name,
field: self,
cache: cache,
internal: internal,
options: type_options)
else
- cache.lookup_named_type(type_name, namespace)
+ cache.lookup_named_type(avro_type_name, namespace)
end
# DSL calls must be evaluated after the type has been constructed
instance_eval(&block) if block_given?
@type.validate!
@@ -64,23 +62,19 @@
# Delegate setting namespace explicitly via DSL to type
# and return the namespace value from the enclosing record.
def namespace(value = nil)
if value
- raise UnsupportedBlockAttributeError.new(attribute: :namespace,
- field: @name,
- type: type.type_name)
+ type.namespace(value)
else
record.namespace
end
end
# Delegate setting name explicitly via DSL to type
def name(value = nil)
if value
- raise UnsupportedBlockAttributeError.new(attribute: :name,
- field: @name,
- type: type.type_name)
+ type.name(value)
else
# Return the name of the field
@name
end
end