Sha256: b02c151f086c08333a7b8e53d5f4a776e7a7721154cd379f9be8213bd9322c13

Contents?: true

Size: 1.05 KB

Versions: 1

Compression:

Stored size: 1.05 KB

Contents

module Dry
  module Schema
    # An API for configuring message backends
    #
    # @api private
    module Messages
      def self.setup(config)
        messages = build(config)

        if config.messages_file && config.namespace
          messages.merge(config.messages_file).namespaced(config.namespace)
        elsif config.messages_file
          messages.merge(config.messages_file)
        elsif config.namespace
          messages.namespaced(config.namespace)
        else
          messages
        end
      end

      # @api private
      def self.build(config)
        klass = case config.messages
        when :yaml then default
        when :i18n then Messages::I18n
        else
          raise "+#{config.messages}+ is not a valid messages identifier"
        end

        klass.build
      end

      # @api private
      def self.default
        Messages::YAML
      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

1 entries across 1 versions & 1 rubygems

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