Sha256: 4c47cc86d3642c372161ffa1e926f19c4e387d6712f978163aded5d3d075ed89

Contents?: true

Size: 1011 Bytes

Versions: 7

Compression:

Stored size: 1011 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.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

7 entries across 7 versions & 1 rubygems

Version Path
dry-types-0.14.1 lib/dry/types/options.rb
dry-types-0.14.0 lib/dry/types/options.rb
dry-types-0.13.4 lib/dry/types/options.rb
dry-types-0.13.3 lib/dry/types/options.rb
dry-types-0.13.2 lib/dry/types/options.rb
dry-types-0.13.1 lib/dry/types/options.rb
dry-types-0.13.0 lib/dry/types/options.rb