Class: Deimos::SchemaBackends::Mock

Inherits:
Base
  • Object
show all
Defined in:
lib/deimos/schema_backends/mock.rb,
sig/defs.rbs

Overview

Mock implementation of a schema backend that does no encoding or validation.

Instance Attribute Summary

Attributes inherited from Base

#key_schema, #namespace, #schema

Instance Method Summary collapse

Methods inherited from Base

#coerce, content_type, #decode, #encode, field_type, #initialize, #load_schema, mock_backend, #sql_type

Constructor Details

This class inherits a constructor from Deimos::SchemaBackends::Base

Instance Method Details

#coerce_field(_field, value) ⇒ Object

Parameters:

  • _field (Object)
  • value (Object)

Returns:

  • (Object)


27
28
29
# File 'lib/deimos/schema_backends/mock.rb', line 27

def coerce_field(_field, value)
  value
end

#decode_key(payload, key_id) ⇒ String

Parameters:

  • payload (::Hash[untyped, untyped])
  • key_id (String, Symbol)

Returns:

  • (String)


37
38
39
# File 'lib/deimos/schema_backends/mock.rb', line 37

def decode_key(payload, key_id)
  payload[key_id]
end

#decode_payload(payload, schema:) ⇒ ::Hash[untyped, untyped]

Parameters:

  • payload (String)
  • schema: (String, Symbol)

Returns:

  • (::Hash[untyped, untyped])


8
9
10
# File 'lib/deimos/schema_backends/mock.rb', line 8

def decode_payload(payload, schema:)
  payload.is_a?(String) ? 'payload-decoded' : payload.map { |k, v| [k, "decoded-#{v}"] }
end

#encode_key(key_id, key, topic: nil) ⇒ String

Parameters:

  • key_id (String, Symbol)
  • key (String, ::Hash[untyped, untyped])

Returns:

  • (String)


32
33
34
# File 'lib/deimos/schema_backends/mock.rb', line 32

def encode_key(key_id, key, topic: nil)
  { key_id => key }
end

#encode_payload(payload, schema:, topic: nil) ⇒ String

Parameters:

  • payload (::Hash[untyped, untyped])
  • schema: (String, Symbol)
  • topic: (String, nil) (defaults to: nil)

Returns:

  • (String)


13
14
15
# File 'lib/deimos/schema_backends/mock.rb', line 13

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

#schema_fields::Array[SchemaField]

Returns:



22
23
24
# File 'lib/deimos/schema_backends/mock.rb', line 22

def schema_fields
  []
end

#validate(payload, schema:) ⇒ void

This method returns an undefined value.

Parameters:

  • payload (::Hash[untyped, untyped])
  • schema: (String, Symbol)


18
19
# File 'lib/deimos/schema_backends/mock.rb', line 18

def validate(payload, schema:)
end