Sha256: 2955732307cbdd8e3b8164bb16a89efe367e41c76a13cab11efc5768195b0d53

Contents?: true

Size: 1.5 KB

Versions: 28

Compression:

Stored size: 1.5 KB

Contents

class AvroTurf
  module AvroGemPatch
    module RecordSchema
      module ClassMethods
        def make_field_objects(field_data, names, namespace=nil)
          new_field_data = []
          field_data.each do |field|
            if field.respond_to?(:[]) && !field.key?('default')
              field = field.clone
              field['default'] = :no_default
            end
            new_field_data << field
          end
          super(new_field_data, names, namespace)
        end
      end
      
      def self.prepended(base)
        class << base
          prepend ClassMethods
        end
      end
    end
    
    module Field
      def initialize(type, name, default=:no_default, order=nil, names=nil, namespace=nil)
        super(type, name, default, order, names, namespace)
      end
      
      def to_avro(names=Set.new)
        {'name' => name, 'type' => type.to_avro(names)}.tap do |avro|
          avro['default'] = default unless default == :no_default
          avro['order'] = order if order
        end
      end
    end

    module DatumReader
      def read_default_value(field_schema, default_value)
        if default_value == :no_default
          raise Avro::AvroError, "Missing data for #{field_schema} with no default"
        end

        super
      end
    end
  end
end

Avro::Schema::RecordSchema.send(:prepend, AvroTurf::AvroGemPatch::RecordSchema)
Avro::Schema::Field.send(:prepend, AvroTurf::AvroGemPatch::Field)
Avro::IO::DatumReader.send(:prepend, AvroTurf::AvroGemPatch::DatumReader)

Version data entries

28 entries across 28 versions & 2 rubygems

Version Path
avro_turf-1.17.0 lib/avro_turf/schema_to_avro_patch.rb
avro_turf-1.16.0 lib/avro_turf/schema_to_avro_patch.rb
avro_turf-1.15.0 lib/avro_turf/schema_to_avro_patch.rb
avro_turf-1.14.0 lib/avro_turf/schema_to_avro_patch.rb
avro_turf-1.13.0 lib/avro_turf/schema_to_avro_patch.rb
avro_turf-1.12.0 lib/avro_turf/schema_to_avro_patch.rb
avro_turf-1.11.0 lib/avro_turf/schema_to_avro_patch.rb
avro_turf-1.10.0 lib/avro_turf/schema_to_avro_patch.rb
avro_turf-1.9.0 lib/avro_turf/schema_to_avro_patch.rb
avro_turf-1.8.0 lib/avro_turf/schema_to_avro_patch.rb
avro_turf-1.7.0 lib/avro_turf/schema_to_avro_patch.rb
avro_turf-1.6.0 lib/avro_turf/schema_to_avro_patch.rb
avro_turf-1.5.0 lib/avro_turf/schema_to_avro_patch.rb
avro_turf-1.4.1 lib/avro_turf/schema_to_avro_patch.rb
avro_turf-1.4.0 lib/avro_turf/schema_to_avro_patch.rb
avro_turf-1.3.1 lib/avro_turf/schema_to_avro_patch.rb
avro_turf-1.3.0 lib/avro_turf/schema_to_avro_patch.rb
avro_turf-1.2.0 lib/avro_turf/schema_to_avro_patch.rb
avro_turf-1.1.0 lib/avro_turf/schema_to_avro_patch.rb
avro_turf-1.0.0 lib/avro_turf/schema_to_avro_patch.rb