Module: Dry::Types::Meta

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

Overview

Storage for meta-data

API:

  • public

Instance Method Summary collapse

Instance Method Details

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

API:

  • public



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:

    • metadata associated with type

  • #meta(data) ⇒ Type

    Returns new type with added metadata.

    Parameters:

    • metadata to merge into existing metadata

    Returns:

    • new type with added metadata

API:

  • public



35
36
37
38
39
40
41
42
43
# File 'lib/dry/types/meta.rb', line 35

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:

API:

  • public



50
# File 'lib/dry/types/meta.rb', line 50

def pristine = with(meta: EMPTY_HASH)

#with(**options) ⇒ Type

Parameters:

  • new_options

Returns:

API:

  • public



19
20
21
22
23
24
25
# File 'lib/dry/types/meta.rb', line 19

def with(**options)
  if options.empty?
    self
  else
    super(meta: @meta, **options)
  end
end