module Dry::Types::Meta

Storage for meta-data

@api public

Public Class Methods

new(*args, meta: EMPTY_HASH, **options) click to toggle source
Calls superclass method
# File lib/dry/types/meta.rb, line 9
def initialize(*args, meta: EMPTY_HASH, **options)
  super(*args, **options)
  @meta = meta.freeze
end

Public Instance Methods

meta(data = Undefined) click to toggle source

@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

@api public

# File lib/dry/types/meta.rb, line 31
def meta(data = Undefined)
  if Undefined.equal?(data)
    @meta
  elsif data.empty?
    self
  else
    with(meta: @meta.merge(data))
  end
end
pristine() click to toggle source

Resets meta

@return [Dry::Types::Type]

@api public

# File lib/dry/types/meta.rb, line 46
def pristine
  with(meta: EMPTY_HASH)
end
with(**options) click to toggle source

@param options [Hash] new_options

@return [Type]

@api public

Calls superclass method
# File lib/dry/types/meta.rb, line 19
def with(**options)
  super(meta: @meta, **options)
end