Sha256: f36d16f8ae27cd99078f65033ffea10d7c13022ab6f7121072887a4e256b3e2f

Contents?: true

Size: 720 Bytes

Versions: 8

Compression:

Stored size: 720 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.setting_names.include?(k) }

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

        return messages.namespaced(namespace) if namespace

        messages
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
dry-schema-1.14.0 lib/dry/schema/messages.rb
dry-schema-1.13.3 lib/dry/schema/messages.rb
dry-schema-1.13.2 lib/dry/schema/messages.rb
dry-schema-1.13.1 lib/dry/schema/messages.rb
dry-schema-1.13.0 lib/dry/schema/messages.rb
dry-schema-1.12.0 lib/dry/schema/messages.rb
dry-schema-1.11.3 lib/dry/schema/messages.rb
dry-schema-1.11.2 lib/dry/schema/messages.rb