Sha256: 28e7a112d11beb94a18295c04c7f1cab9e0ff9e1cd2a8602186abeeac9ce2892
Contents?: true
Size: 1.21 KB
Versions: 16
Compression:
Stored size: 1.21 KB
Contents
module Avromatic module Model # This concern adds methods for configuration for a model generated from # Avro schema(s). module Configurable extend ActiveSupport::Concern module ClassMethods attr_accessor :config delegate :avro_schema, :value_avro_schema, :key_avro_schema, to: :config def value_avro_field_names @value_avro_field_names ||= value_avro_schema.fields.map(&:name).map(&:to_sym).freeze end def key_avro_field_names @key_avro_field_names ||= key_avro_schema.fields.map(&:name).map(&:to_sym).freeze end def value_avro_fields_by_name @value_avro_fields_by_name ||= mapped_by_name(value_avro_schema) end def key_avro_fields_by_name @key_avro_fields_by_name ||= mapped_by_name(key_avro_schema) end private def mapped_by_name(schema) schema.fields.each_with_object(Hash.new) do |field, result| result[field.name.to_sym] = field end end end delegate :avro_schema, :value_avro_schema, :key_avro_schema, :value_avro_field_names, :key_avro_field_names, to: :class end end end
Version data entries
16 entries across 16 versions & 1 rubygems