Sha256: 2c1b2c2802e12073f19f91abf658c27dfbf37be8da6cab3b282120966a3ab5b6

Contents?: true

Size: 901 Bytes

Versions: 1

Compression:

Stored size: 901 Bytes

Contents

# frozen_string_literal: true

module Deimos
  module Utils
    # Class used by SchemaClassGenerator and Consumer/Producer interfaces
    module SchemaClass
      class << self
        # Converts a raw payload into an instance of the Schema Class
        # @param payload [Hash]
        # @param schema [String]
        # @return [Deimos::SchemaClass::Record]
        def instance(payload, schema)
          klass = "Deimos::#{schema.underscore.camelize}".safe_constantize
          return payload if klass.nil? || payload.nil?

          klass.new(**payload.symbolize_keys)
        end

        # @param config [Hash] Producer or Consumer config
        # @return [Boolean]
        def use?(config)
          use_schema_classes = config[:use_schema_classes]
          use_schema_classes.present? ? use_schema_classes : Deimos.config.schema.use_schema_classes
        end

      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
deimos-ruby-1.12.0 lib/deimos/utils/schema_class.rb