Class: Apiwork::Contract::Action::Response
- Inherits:
-
Object
- Object
- Apiwork::Contract::Action::Response
- Defined in:
- lib/apiwork/contract/action/response.rb
Overview
Defines body for a response.
Returns Object via ‘body`.
Instance Attribute Summary collapse
- #action_name ⇒ Object readonly
- #contract_class ⇒ Object readonly
Instance Method Summary collapse
-
#body {|body| ... } ⇒ Contract::Object
Defines the response body for this response.
-
#description(value = nil) ⇒ String?
The description for this response.
-
#initialize(contract_class, action_name) ⇒ Response
constructor
A new instance of Response.
-
#no_content! ⇒ void
Declares this response as 204 No Content.
-
#no_content? ⇒ Boolean
Whether this response has no content.
Constructor Details
#initialize(contract_class, action_name) ⇒ Response
Returns a new instance of Response.
14 15 16 17 18 19 20 |
# File 'lib/apiwork/contract/action/response.rb', line 14 def initialize(contract_class, action_name) @contract_class = contract_class @action_name = action_name @body = nil @description = nil @no_content = false end |
Instance Attribute Details
#action_name ⇒ Object (readonly)
11 12 13 |
# File 'lib/apiwork/contract/action/response.rb', line 11 def action_name @action_name end |
#contract_class ⇒ Object (readonly)
11 12 13 |
# File 'lib/apiwork/contract/action/response.rb', line 11 def contract_class @contract_class end |
Instance Method Details
#body {|body| ... } ⇒ Contract::Object
Defines the response body for this response.
92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/apiwork/contract/action/response.rb', line 92 def body(&block) if block @body ||= Object.new( @contract_class, action_name: @action_name, wrapped: true, ) block.arity.positive? ? yield(@body) : @body.instance_eval(&block) end @body end |
#description(value = nil) ⇒ String?
The description for this response.
Metadata included in exports.
37 38 39 40 41 |
# File 'lib/apiwork/contract/action/response.rb', line 37 def description(value = nil) return @description if value.nil? @description = value end |
#no_content! ⇒ void
This method returns an undefined value.
Declares this response as 204 No Content.
Use for actions that don’t return a response body, like DELETE or actions that only perform side effects.
68 69 70 |
# File 'lib/apiwork/contract/action/response.rb', line 68 def no_content! @no_content = true end |
#no_content? ⇒ Boolean
Whether this response has no content.
47 48 49 |
# File 'lib/apiwork/contract/action/response.rb', line 47 def no_content? @no_content end |