Sha256: 997b9db81696fc74d95765e4229be055b118d983eb9e1a98af8d5a39aab42034

Contents?: true

Size: 884 Bytes

Versions: 23

Compression:

Stored size: 884 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

require "dry/schema/messages/abstract"
require "dry/schema/messages/namespaced"
require "dry/schema/messages/yaml"
require "dry/schema/messages/i18n" if defined?(I18n)

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
dry-schema-1.10.6 lib/dry/schema/messages.rb
dry-schema-1.10.5 lib/dry/schema/messages.rb
dry-schema-1.10.4 lib/dry/schema/messages.rb
dry-schema-1.10.3 lib/dry/schema/messages.rb
dry-schema-1.10.2 lib/dry/schema/messages.rb
dry-schema-1.10.1 lib/dry/schema/messages.rb
dry-schema-1.9.3 lib/dry/schema/messages.rb
dry-schema-1.9.2 lib/dry/schema/messages.rb
dry-schema-1.9.1 lib/dry/schema/messages.rb
dry-schema-1.9.0 lib/dry/schema/messages.rb
dry-schema-1.8.0 lib/dry/schema/messages.rb
dry-schema-1.7.1 lib/dry/schema/messages.rb
dry-schema-1.7.0 lib/dry/schema/messages.rb
dry-schema-1.6.2 lib/dry/schema/messages.rb
dry-schema-1.6.1 lib/dry/schema/messages.rb
dry-schema-1.6.0 lib/dry/schema/messages.rb
dry-schema-1.5.6 lib/dry/schema/messages.rb
dry-schema-1.5.5 lib/dry/schema/messages.rb
dry-schema-1.5.4 lib/dry/schema/messages.rb
dry-schema-1.5.3 lib/dry/schema/messages.rb