Sha256: 65d5735ff1f9d1bba06babc7e81bc71dff12dc4ed0d45f39758e19490a7f8c43

Contents?: true

Size: 990 Bytes

Versions: 6

Compression:

Stored size: 990 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)
        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

6 entries across 6 versions & 1 rubygems

Version Path
dry-types-0.12.3 lib/dry/types/options.rb
dry-types-0.12.2 lib/dry/types/options.rb
dry-types-0.12.1 lib/dry/types/options.rb
dry-types-0.12.0 lib/dry/types/options.rb
dry-types-0.11.1 lib/dry/types/options.rb
dry-types-0.11.0 lib/dry/types/options.rb