Module: Dry::Types::Options

Included in:
Decorator, Definition, Sum
Defined in:
lib/dry/types/options.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#optionsHash (readonly)

Returns:



5
6
7
# File 'lib/dry/types/options.rb', line 5

def options
  @options
end

Instance Method Details

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



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

def initialize(*args, meta: EMPTY_HASH, **options)
  @__args__ = args
  @options = options
  @meta = meta
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



26
27
28
29
30
31
32
33
34
# File 'lib/dry/types/options.rb', line 26

def meta(data = nil)
  if !data
    @meta
  elsif data.empty?
    self
  else
    with(meta: @meta.merge(data))
  end
end

#pristineDry::Types::Type

Resets meta

Returns:



38
39
40
# File 'lib/dry/types/options.rb', line 38

def pristine
  with(meta: EMPTY_HASH)
end

#with(new_options) ⇒ Type

Parameters:

  • new_options (Hash)

Returns:



16
17
18
# File 'lib/dry/types/options.rb', line 16

def with(new_options)
  self.class.new(*@__args__, **options, meta: @meta, **new_options)
end