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:

Returns:



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

def instance(payload, schema)
  return payload if payload.is_a?(Deimos::SchemaClass::Base)

  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)


23
24
25
26
# File 'lib/deimos/utils/schema_class.rb', line 23

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