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.13.3 lib/dry/schema/messages/template.rb
dry-schema-1.13.2 lib/dry/schema/messages/template.rb
dry-schema-1.13.1 lib/dry/schema/messages/template.rb
dry-schema-1.13.0 lib/dry/schema/messages/template.rb
dry-schema-1.12.0 lib/dry/schema/messages/template.rb
dry-schema-1.11.3 lib/dry/schema/messages/template.rb
dry-schema-1.11.2 lib/dry/schema/messages/template.rb
dry-schema-1.11.1 lib/dry/schema/messages/template.rb
dry-schema-1.11.0 lib/dry/schema/messages/template.rb
dry-schema-1.10.6 lib/dry/schema/messages/template.rb
dry-schema-1.10.5 lib/dry/schema/messages/template.rb
dry-schema-1.10.4 lib/dry/schema/messages/template.rb
dry-schema-1.10.2 lib/dry/schema/messages/template.rb
dry-schema-1.10.1 lib/dry/schema/messages/template.rb
dry-schema-1.9.3 lib/dry/schema/messages/template.rb
dry-schema-1.9.2 lib/dry/schema/messages/template.rb
dry-schema-1.9.1 lib/dry/schema/messages/template.rb
dry-schema-1.9.0 lib/dry/schema/messages/template.rb
dry-schema-1.8.0 lib/dry/schema/messages/template.rb
dry-schema-1.7.1 lib/dry/schema/messages/template.rb