Module: Dry::Types::Meta

Included in:
Composition, Nominal
Defined in:
lib/dry/types/meta.rb

Overview

Storage for meta-data

Instance Method Summary collapse

Instance Method Details

#initialize(*args, meta: EMPTY_HASH, **options) ⇒ Object



9
10
11
12
# File 'lib/dry/types/meta.rb', line 9

def initialize(*args, meta: EMPTY_HASH, **options)
  super(*args, **options)
  @meta = meta.freeze
end

#metaHash #meta(data) ⇒ Type

Overloads:

  • #metaHash

    Returns metadata associated with type.

    Returns:

    • (Hash)

      metadata associated with type

  • #meta(data) ⇒ Type

    Returns new type with added metadata.

    Parameters:

    • new (Hash)

      metadata to merge into existing metadata

    Returns:

    • (Type)

      new type with added metadata



31
32
33
34
35
36
37
38
39
# 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

#pristineDry::Types::Type

Resets meta

Returns:



46
47
48
# File 'lib/dry/types/meta.rb', line 46

def pristine
  with(meta: EMPTY_HASH)
end

#with(**options) ⇒ Type

Parameters:

  • options (Hash)

    new_options

Returns:



19
20
21
# File 'lib/dry/types/meta.rb', line 19

def with(**options)
  super(meta: @meta, **options)
end