lib/avro/schema.rb in avro-salsify-fork-1.9.0.0 vs lib/avro/schema.rb in avro-salsify-fork-1.9.0.1

- old
+ new

@@ -92,11 +92,17 @@ raise UnknownSchemaError.new(json_obj) end end # Determine if a ruby datum is an instance of a schema - def self.validate(expected_schema, datum) + def self.validate(expected_schema, logical_datum, encoded = false) + datum = if encoded + logical_datum + else + expected_schema.type_adapter.encode(logical_datum) + end + case expected_schema.type_sym when :null datum.nil? when :boolean datum == true || datum == false @@ -179,10 +185,12 @@ raise SchemaParseError, "Sub-schema for #{self.class.name} not a valid Avro schema. Bad schema: #{json_obj}" end end def to_avro(names=nil) - {'type' => type} + props = {'type' => type} + props['logicalType'] = logical_type if logical_type + props end def to_s MultiJson.dump to_avro end