Sha256: d93a3b4fbf1aa36f64a6e40a6b956db322fdb4758a7a51a5e8b78a553863f5f7

Contents?: true

Size: 906 Bytes

Versions: 1

Compression:

Stored size: 906 Bytes

Contents

# frozen_string_literal: true

require "dry/initializer"

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

1 entries across 1 versions & 1 rubygems

Version Path
dry-schema-1.10.3 lib/dry/schema/messages/template.rb