Module: Deimos::Utils::SchemaClass

Defined in:
lib/deimos/utils/schema_class.rb

Overview

Class used by SchemaClassGenerator and Consumer/Producer interfaces

Class Method Summary collapse

Class Method Details

.instance(payload, schema) ⇒ Deimos::SchemaClass::Record

Converts a raw payload into an instance of the Schema Class

Parameters:

  • payload (Hash)
  • schema (String)

Returns:



12
13
14
15
16
17
# File 'lib/deimos/utils/schema_class.rb', line 12

def instance(payload, schema)
  klass = "Schemas::#{schema.underscore.camelize}".safe_constantize
  return payload if klass.nil? || payload.nil?

  klass.new(**payload.symbolize_keys)
end

.use?(config) ⇒ Boolean

Parameters:

  • config (Hash)

    Producer or Consumer config

Returns:

  • (Boolean)


21
22
23
24
# File 'lib/deimos/utils/schema_class.rb', line 21

def use?(config)
  use_schema_classes = config[:use_schema_classes]
  use_schema_classes.present? ? use_schema_classes : Deimos.config.schema.use_schema_classes
end