Sha256: bf39784ee9acc7758060e438a06d170410493d23663dd2fd321daf738c90a3cf

Contents?: true

Size: 928 Bytes

Versions: 2

Compression:

Stored size: 928 Bytes

Contents

# frozen_string_literal: true

module Deimos
  module SchemaBackends
    # Mock implementation of a schema backend that does no encoding or validation.
    class Mock < Base
      # @override
      def decode_payload(payload, schema:)
        payload.is_a?(String) ? 'payload-decoded' : payload.map { |k, v| [k, "decoded-#{v}"] }
      end

      # @override
      def encode_payload(payload, schema:, topic: nil)
        payload.is_a?(String) ? 'payload-encoded' : payload.map { |k, v| [k, "encoded-#{v}"] }
      end

      # @override
      def validate(payload, schema:)
      end

      # @override
      def schema_fields
        []
      end

      # @override
      def coerce_field(_field, value)
        value
      end

      # @override
      def encode_key(key_id, key)
        { key_id => key }
      end

      # @override
      def decode_key(payload, key_id)
        payload[key_id]
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
deimos-ruby-1.17.1 lib/deimos/schema_backends/mock.rb
deimos-ruby-1.17.0 lib/deimos/schema_backends/mock.rb