Sha256: f372f08ef72632d93d092d747cfc4d8bd64b91e407141f720b6df66c5d9c84e1

Contents?: true

Size: 715 Bytes

Versions: 1

Compression:

Stored size: 715 Bytes

Contents

# frozen_string_literal: true

module Dry
  module Schema
    # An API for configuring message backends
    #
    # @api private
    module Messages
      BACKENDS = {
        i18n: "I18n",
        yaml: "YAML"
      }.freeze

      module_function

      public def setup(config)
        backend_class = BACKENDS.fetch(config.backend) do
          raise "+#{config.backend}+ is not a valid messages identifier"
        end

        namespace = config.namespace
        options = config.to_h.select { |k, _| Abstract.settings.include?(k) }

        messages = Messages.const_get(backend_class).build(options)

        return messages.namespaced(namespace) if namespace

        messages
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
dry-schema-1.11.0 lib/dry/schema/messages.rb