Module: Dry::Tuple::ClassDecorator

Included in:
ClassInterface, StructClassInterface
Defined in:
lib/dry/tuple.rb

Overview

Pure class type decorator mixin.

Instance Method Summary collapse

Instance Method Details

#call_safe(input, &block) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



46
47
48
49
50
51
52
53
54
# File 'lib/dry/tuple.rb', line 46

def call_safe(input, &block)
  if input.is_a?(self)
    input
  elsif input.is_a?(Array)
    resolve_tuple_safe(input, &block)
  else
    super
  end
end

#call_unsafe(input) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



57
58
59
60
61
62
63
64
65
# File 'lib/dry/tuple.rb', line 57

def call_unsafe(input)
  if input.is_a?(self)
    input
  elsif input.is_a?(Array)
    resolve_tuple_unsafe(input)
  else
    super
  end
end

#coerce_tuple(input) ⇒ Array

Note:

Will be invoked on input that was passed thru tuple validation & coercion.

Returns coerced input.

Parameters:

  • input (Array)

    the result of tuple#call

Returns:

  • (Array)

    coerced input



41
42
43
# File 'lib/dry/tuple.rb', line 41

def coerce_tuple(input)
  defined?(super) ? super(input) : input
end

#new_from_tuple(input) ⇒ self

This method is abstract.

It is designed to be redefined for example to splat arguments on constructor.

Note:

Will be invoked on input that was passed thru tuple validation & coercion.

Parameters:

Returns:

  • (self)


33
34
35
# File 'lib/dry/tuple.rb', line 33

def new_from_tuple(input)
  defined?(super) ? super(input) : new(input)
end