Sha256: 4ea422c6f6a5c731ed3617e997b518e4301a59f94e49d925fa784d70a79ac5b3
Contents?: true
Size: 1.69 KB
Versions: 6
Compression:
Stored size: 1.69 KB
Contents
module Avromatic module Model # This class holds configuration for a model build from Avro schema(s). class Configuration attr_reader :avro_schema, :key_avro_schema delegate :schema_store, to: Avromatic # Either schema(_name) or value_schema(_name), but not both, must be # specified. # # @param options [Hash] # @option options [Avro::Schema] :schema # @option options [String, Symbol] :schema_name # @option options [Avro::Schema] :value_schema # @option options [String, Symbol] :value_schema_name # @option options [Avro::Schema] :key_schema # @option options [String, Symbol] :key_schema_name # @option options [schema store] :schema_store def initialize(**options) @avro_schema = find_avro_schema(**options) raise ArgumentError.new('value_schema(_name) or schema(_name) must be specified') unless avro_schema @key_avro_schema = find_schema_by_option(:key_schema, **options) end alias_method :value_avro_schema, :avro_schema private def find_avro_schema(**options) if (options[:value_schema] || options[:value_schema_name]) && (options[:schema] || options[:schema_name]) raise ArgumentError.new('Only one of value_schema(_name) and schema(_name) can be specified') end find_schema_by_option(:value_schema, **options) || find_schema_by_option(:schema, **options) end def find_schema_by_option(option_name, **options) schema_name_option = :"#{option_name}_name" options[option_name] || (options[schema_name_option] && schema_store.find(options[schema_name_option])) end end end end
Version data entries
6 entries across 6 versions & 1 rubygems