lib/avro/schema_validator.rb in avro-salsify-fork-1.9.0.4 vs lib/avro/schema_validator.rb in avro-salsify-fork-1.9.0.5

- old
+ new

@@ -84,17 +84,17 @@ when :boolean fail TypeMismatchError unless [true, false].include?(datum) when :string, :bytes fail TypeMismatchError unless datum.is_a?(String) when :int - fail TypeMismatchError unless datum.is_a?(Fixnum) || datum.is_a?(Bignum) + fail TypeMismatchError unless datum.is_a?(Integer) result.add_error(path, "out of bound value #{datum}") unless INT_RANGE.cover?(datum) when :long - fail TypeMismatchError unless datum.is_a?(Fixnum) || datum.is_a?(Bignum) + fail TypeMismatchError unless datum.is_a?(Integer) result.add_error(path, "out of bound value #{datum}") unless LONG_RANGE.cover?(datum) when :float, :double - fail TypeMismatchError unless [Float, Fixnum, Bignum].any?(&datum.method(:is_a?)) + fail TypeMismatchError unless [Float, Integer].any?(&datum.method(:is_a?)) when :fixed if datum.is_a? String message = "expected fixed with size #{expected_schema.size}, got \"#{datum}\" with size #{datum.size}" result.add_error(path, message) unless datum.bytesize == expected_schema.size else @@ -169,11 +169,15 @@ end private def actual_value_message(value) - avro_type = ruby_to_avro_type(value.class) + avro_type = if value.class == Integer + ruby_integer_to_avro_type(value) + else + ruby_to_avro_type(value.class) + end if value.nil? avro_type else "#{avro_type} with value #{value.inspect}" end @@ -186,9 +190,13 @@ Fixnum => 'int', Bignum => 'long', Float => 'float', Hash => 'record' }.fetch(ruby_class, ruby_class) + end + + def ruby_integer_to_avro_type(value) + INT_RANGE.cover?(value) ? 'int' : 'long' end end end end