Class: APIGatewayDSL::Operation
- Inherits:
-
Object
- Object
- APIGatewayDSL::Operation
- Defined in:
- lib/api_gateway_dsl/operation.rb,
lib/api_gateway_dsl/operation/collection.rb
Defined Under Namespace
Classes: Collection
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#cors ⇒ Object
readonly
Returns the value of attribute cors.
-
#description ⇒ Object
Returns the value of attribute description.
-
#integrations ⇒ Object
readonly
Returns the value of attribute integrations.
-
#parameters ⇒ Object
readonly
Returns the value of attribute parameters.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#responses ⇒ Object
readonly
Returns the value of attribute responses.
-
#summary ⇒ Object
Returns the value of attribute summary.
Instance Method Summary collapse
-
#as_json ⇒ Object
rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity.
- #cors_method ⇒ Object
-
#initialize(context, method, path, **options, &block) ⇒ Operation
constructor
A new instance of Operation.
- #method ⇒ Object
- #parameters_with_body ⇒ Object
Constructor Details
#initialize(context, method, path, **options, &block) ⇒ Operation
Returns a new instance of Operation.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/api_gateway_dsl/operation.rb', line 7 def initialize(context, method, path, **, &block) @context = context.dup @method = method @path = path @cors = [:cors] @security = [:security] @parameters = Parameter::Collection.new @integrations = Integration::Collection.new @responses = Response::Collection.new DSL::OperationNode.new(self, &block) end |
Instance Attribute Details
#context ⇒ Object (readonly)
Returns the value of attribute context.
4 5 6 |
# File 'lib/api_gateway_dsl/operation.rb', line 4 def context @context end |
#cors ⇒ Object (readonly)
Returns the value of attribute cors.
4 5 6 |
# File 'lib/api_gateway_dsl/operation.rb', line 4 def cors @cors end |
#description ⇒ Object
Returns the value of attribute description.
5 6 7 |
# File 'lib/api_gateway_dsl/operation.rb', line 5 def description @description end |
#integrations ⇒ Object (readonly)
Returns the value of attribute integrations.
4 5 6 |
# File 'lib/api_gateway_dsl/operation.rb', line 4 def integrations @integrations end |
#parameters ⇒ Object (readonly)
Returns the value of attribute parameters.
4 5 6 |
# File 'lib/api_gateway_dsl/operation.rb', line 4 def parameters @parameters end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
4 5 6 |
# File 'lib/api_gateway_dsl/operation.rb', line 4 def path @path end |
#responses ⇒ Object (readonly)
Returns the value of attribute responses.
4 5 6 |
# File 'lib/api_gateway_dsl/operation.rb', line 4 def responses @responses end |
#summary ⇒ Object
Returns the value of attribute summary.
5 6 7 |
# File 'lib/api_gateway_dsl/operation.rb', line 5 def summary @summary end |
Instance Method Details
#as_json ⇒ Object
rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/api_gateway_dsl/operation.rb', line 43 def as_json {}.tap do |result| result[:summary] = summary if summary result[:description] = description.strip_heredoc if description result[:security] = [@security => []] if @security if (produces = responses.content_types).present? result[:produces] = produces end result[:responses] = responses.as_json if (integration = integrations.first) if (consumes = integration.templates.content_types).present? result[:consumes] = consumes end if (params = parameters_with_body.as_json).present? result[:parameters] = params end result[:'x-amazon-apigateway-integration'] = integration.as_json end end end |
#cors_method ⇒ Object
38 39 40 |
# File 'lib/api_gateway_dsl/operation.rb', line 38 def cors_method @method # not downcased end |
#method ⇒ Object
31 32 33 34 35 36 |
# File 'lib/api_gateway_dsl/operation.rb', line 31 def method case @method when 'ANY' then 'x-amazon-apigateway-any-method' else @method.downcase end end |
#parameters_with_body ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/api_gateway_dsl/operation.rb', line 23 def parameters_with_body Parameter::Collection.new.concat(parameters).tap do |result| if (integration = integrations.first) result.concat(integration.templates.parameters) end end end |