Sha256: 94ead115528a73b12b8da6a9e687776c282be5ef6c887f07a7f8b4d012131fb9

Contents?: true

Size: 904 Bytes

Versions: 3

Compression:

Stored size: 904 Bytes

Contents

module Dry
  module Types
    module Options
      # @return [Hash]
      attr_reader :options

      # @see Definition#initialize
      def initialize(*args, meta: EMPTY_HASH, **options)
        @__args__ = args
        @options = options
        @meta = meta
      end

      # @param [Hash] new_options
      # @return [Type]
      def with(new_options)
        self.class.new(*@__args__, **options, meta: @meta, **new_options)
      end

      # @overload meta
      #   @return [Hash] metadata associated with type
      #
      # @overload meta(data)
      #   @param [Hash] new metadata to merge into existing metadata
      #   @return [Type] new type with added metadata
      def meta(data = nil)
        data ? with(meta: @meta.merge(data)) : @meta
      end

      # Resets meta
      # @return [Dry::Types::Type]
      def pristine
        with(meta: EMPTY_HASH)
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
dry-types-0.10.3 lib/dry/types/options.rb
dry-types-0.10.2 lib/dry/types/options.rb
dry-types-0.10.1 lib/dry/types/options.rb