Class: Apiwork::Introspection::Action::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/apiwork/introspection/action/response.rb

Overview

Wraps action response definitions.

Examples:

Response with body

response = action.response
response.body? # => true
response.no_content? # => false
response.body # => Param for response body

No content response

response.no_content? # => true
response.body? # => false

Instance Method Summary collapse

Constructor Details

#initialize(dump) ⇒ Response

Returns a new instance of Response.



19
20
21
# File 'lib/apiwork/introspection/action/response.rb', line 19

def initialize(dump)
  @dump = dump
end

Instance Method Details

#bodyParam?

The body for this response.

Returns:



27
28
29
# File 'lib/apiwork/introspection/action/response.rb', line 27

def body
  @body ||= @dump[:body] ? Param.build(@dump[:body]) : nil
end

#body?Boolean

Whether this response has a body.

Returns:

  • (Boolean)


51
52
53
# File 'lib/apiwork/introspection/action/response.rb', line 51

def body?
  body.present?
end

#descriptionString?

The description for this response.

Returns:

  • (String, nil)


35
36
37
# File 'lib/apiwork/introspection/action/response.rb', line 35

def description
  @dump[:description]
end

#no_content?Boolean

Whether this response has no content.

Returns:

  • (Boolean)


43
44
45
# File 'lib/apiwork/introspection/action/response.rb', line 43

def no_content?
  @dump[:no_content]
end

#to_hHash

Converts this response to a hash.

Returns:

  • (Hash)


59
60
61
# File 'lib/apiwork/introspection/action/response.rb', line 59

def to_h
  { description:, body: body&.to_h, no_content: no_content? }
end