Sha256: e20fdee5186f65f719dcd6d80ca93d066f3309eb2998a70a02b86678c0a6ccee

Contents?: true

Size: 884 Bytes

Versions: 19

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

19 entries across 19 versions & 1 rubygems

Version Path
dry-schema-1.4.3 lib/dry/schema/messages.rb
dry-schema-1.4.2 lib/dry/schema/messages.rb
dry-schema-1.4.1 lib/dry/schema/messages.rb
dry-schema-1.4.0 lib/dry/schema/messages.rb
dry-schema-1.3.4 lib/dry/schema/messages.rb
dry-schema-1.3.3 lib/dry/schema/messages.rb
dry-schema-1.3.2 lib/dry/schema/messages.rb
dry-schema-1.3.1 lib/dry/schema/messages.rb
dry-schema-1.3.0 lib/dry/schema/messages.rb
dry-schema-1.2.0 lib/dry/schema/messages.rb
dry-schema-1.1.0 lib/dry/schema/messages.rb
dry-schema-1.0.3 lib/dry/schema/messages.rb
dry-schema-1.0.2 lib/dry/schema/messages.rb
dry-schema-1.0.1 lib/dry/schema/messages.rb
dry-schema-1.0.0 lib/dry/schema/messages.rb
dry-schema-0.6.0 lib/dry/schema/messages.rb
dry-schema-0.5.1 lib/dry/schema/messages.rb
dry-schema-0.5.0 lib/dry/schema/messages.rb
dry-schema-0.4.0 lib/dry/schema/messages.rb