Class: APIGatewayDSL::Response
- Inherits:
-
Object
- Object
- APIGatewayDSL::Response
- Defined in:
- lib/api_gateway_dsl/response.rb,
lib/api_gateway_dsl/response/collection.rb
Defined Under Namespace
Classes: Collection
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#mappings ⇒ Object
readonly
Returns the value of attribute mappings.
-
#status_code ⇒ Object
readonly
Returns the value of attribute status_code.
-
#templates ⇒ Object
readonly
Returns the value of attribute templates.
Instance Method Summary collapse
- #as_json ⇒ Object
- #content_types ⇒ Object
-
#initialize(operation, status_code, regexp, &block) ⇒ Response
constructor
A new instance of Response.
- #response_integration ⇒ Object
Constructor Details
#initialize(operation, status_code, regexp, &block) ⇒ Response
Returns a new instance of Response.
6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/api_gateway_dsl/response.rb', line 6 def initialize(operation, status_code, regexp, &block) @context = operation.context.dup.tap { |c| c.default_body_file = "response/#{status_code}" } @status_code = status_code.to_s @regexp = regexp(regexp) @mappings = Mapping::Collection.new @templates = Template::Collection.new(@context) DSL::ResponseNode.new(self, &block) end |
Instance Attribute Details
#context ⇒ Object (readonly)
Returns the value of attribute context.
4 5 6 |
# File 'lib/api_gateway_dsl/response.rb', line 4 def context @context end |
#mappings ⇒ Object (readonly)
Returns the value of attribute mappings.
4 5 6 |
# File 'lib/api_gateway_dsl/response.rb', line 4 def mappings @mappings end |
#status_code ⇒ Object (readonly)
Returns the value of attribute status_code.
4 5 6 |
# File 'lib/api_gateway_dsl/response.rb', line 4 def status_code @status_code end |
#templates ⇒ Object (readonly)
Returns the value of attribute templates.
4 5 6 |
# File 'lib/api_gateway_dsl/response.rb', line 4 def templates @templates end |
Instance Method Details
#as_json ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/api_gateway_dsl/response.rb', line 22 def as_json {}.tap do |result| result[:description] = "#{status_code} response" if (headers = mappings.response_headers.as_json).present? result[:headers] = headers end if (template = templates.current) result[:schema] = template.schema_value end end end |
#content_types ⇒ Object
18 19 20 |
# File 'lib/api_gateway_dsl/response.rb', line 18 def content_types templates.content_types end |
#response_integration ⇒ Object
36 37 38 |
# File 'lib/api_gateway_dsl/response.rb', line 36 def response_integration ResponseIntegration.new(@regexp, status_code, mappings, templates) end |