Sha256: 86e48b104991fe4d5d399a554578e898d9fd0dfbc2c2c29743aeea567422f1d7

Contents?: true

Size: 935 Bytes

Versions: 24

Compression:

Stored size: 935 Bytes

Contents

# frozen_string_literal: true

require "dry/initializer"
require "dry/core/equalizer"

require "dry/schema/constants"

module Dry
  module Schema
    module Messages
      # @api private
      class Template
        extend Dry::Initializer
        include Dry::Equalizer(:messages, :key, :options)

        option :messages
        option :key
        option :options

        # @api private
        def data(data = EMPTY_HASH)
          ensure_message!
          messages.interpolatable_data(key, options, **options, **data)
        end

        # @api private
        def call(data = EMPTY_HASH)
          ensure_message!
          messages.interpolate(key, options, **data)
        end
        alias_method :[], :call

        private

        def ensure_message!
          return if messages.key?(key, options)

          raise KeyError, "No message found for template, template=#{inspect}"
        end
      end
    end
  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
dry-schema-1.7.0 lib/dry/schema/messages/template.rb
dry-schema-1.6.2 lib/dry/schema/messages/template.rb
dry-schema-1.6.1 lib/dry/schema/messages/template.rb
dry-schema-1.6.0 lib/dry/schema/messages/template.rb