lib/avro/builder/field.rb in avro-builder-0.11.0 vs lib/avro/builder/field.rb in avro-builder-0.12.0

- old
+ new

@@ -15,11 +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 - def initialize(name:, avro_type_name:, record:, cache:, internal: {}, options: {}, &block) + def initialize(name:, avro_type_or_name:, record:, cache:, internal: {}, options: {}, &block) @cache = cache @record = record @name = name.to_s internal.each do |key, value| @@ -29,22 +29,19 @@ type_options = options.dup options.keys.each do |key| send(key, type_options.delete(key)) if dsl_attribute?(key) end - @field_type = if builtin_type?(avro_type_name) - create_and_configure_builtin_type(avro_type_name, - field: self, - cache: cache, - internal: internal, - validate_type: false, - options: type_options) - elsif avro_type_name.is_a?(Avro::Builder::Types::Type) - raise 'Type name must be an Avro builtin type '\ - "or a previously defined type name. Got #{avro_type_name}" - else - cache.lookup_named_type(avro_type_name, namespace) - end + # Find existing Type or build a new instance of a builtin Type using + # the supplied block + @field_type = type_lookup(avro_type_or_name, namespace) do |avro_type_name| + create_and_configure_builtin_type(avro_type_name, + field: self, + cache: cache, + internal: internal, + validate_type: false, + options: type_options) + end # DSL calls must be evaluated after the type has been constructed instance_eval(&block) if block_given? @field_type.validate! end