Class: Taro::ReturnDef

Inherits:
Object
  • Object
show all
Defined in:
lib/taro/return_def.rb

Overview

Lazily-evaluated response type definition.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(code:, defined_at: nil, desc: nil, nesting: nil, **params) ⇒ ReturnDef

Returns a new instance of ReturnDef.



5
6
7
8
9
10
11
12
# File 'lib/taro/return_def.rb', line 5

def initialize(code:, defined_at: nil, desc: nil, nesting: nil, **params)
  @code = Taro::StatusCode.coerce_to_int(code)
  @defined_at = defined_at
  @desc = desc
  @nesting = nesting
  @params = params
  validate
end

Instance Attribute Details

#codeObject (readonly)

Returns the value of attribute code.



3
4
5
# File 'lib/taro/return_def.rb', line 3

def code
  @code
end

#defined_atObject (readonly)

Returns the value of attribute defined_at.



3
4
5
# File 'lib/taro/return_def.rb', line 3

def defined_at
  @defined_at
end

#descObject (readonly)

Returns the value of attribute desc.



3
4
5
# File 'lib/taro/return_def.rb', line 3

def desc
  @desc
end

#nestingObject (readonly)

Returns the value of attribute nesting.



3
4
5
# File 'lib/taro/return_def.rb', line 3

def nesting
  @nesting
end

#paramsObject (readonly)

Returns the value of attribute params.



3
4
5
# File 'lib/taro/return_def.rb', line 3

def params
  @params
end

Instance Method Details

#evaluateObject



14
15
16
17
18
19
20
21
22
# File 'lib/taro/return_def.rb', line 14

def evaluate
  if nesting
    Class.new(Taro::Types::NestedResponseType).tap do |type|
      type.field(nesting, defined_at:, null: false, **params)
    end
  else
    Taro::Types::Coercion.call(params)
  end
end