Sha256: 18afa2ce503080a743c7fa602e306d66c307e0cae9a2392edad363e8cb5a4a67

Contents?: true

Size: 1010 Bytes

Versions: 1

Compression:

Stored size: 1010 Bytes

Contents

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

      # @see Nominal#initialize
      def initialize(*args, meta: EMPTY_HASH, **options)
        @__args__ = args.freeze
        @options = options.freeze
        @meta = meta.freeze
      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)
        if !data
          @meta
        elsif data.empty?
          self
        else
          with(meta: @meta.merge(data))
        end
      end

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
dry-types-0.15.0 lib/dry/types/options.rb