Sha256: 01e877d246863ad038914b1ab2f916fe69a844a0552992b86c301c0b58bf488c

Contents?: true

Size: 975 Bytes

Versions: 4

Compression:

Stored size: 975 Bytes

Contents

module Avro
  module Builder

    # This concern is used by classes that create new Type instances.
    module TypeFactory

      private

      # Return a new Type instance
      def create_type(type_name)
        case
        when Avro::Schema::PRIMITIVE_TYPES_SYM.include?(type_name.to_sym)
          Avro::Builder::Types::Type.new(type_name)
        else
          type_class_name = "#{type_name.to_s.capitalize}Type"
          Avro::Builder::Types.const_get(type_class_name).new
        end
      end

      # Return a new Type instance, including propagating internal state
      # and setting attributes via the DSL
      def build_type(type_name, field: nil, builder: nil, internal: {}, options: {}, &block)
        create_type(type_name).tap do |type|
          type.field = field
          type.builder = builder
          type.configure_options(internal.merge(options))
          type.instance_eval(&block) if block_given?
        end
      end

    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
avro-builder-0.3.1 lib/avro/builder/type_factory.rb
avro-builder-0.3.0 lib/avro/builder/type_factory.rb
avro-builder-0.2.0 lib/avro/builder/type_factory.rb
avro-builder-0.1.0 lib/avro/builder/type_factory.rb