Class: APIGatewayDSL::Mapping

Inherits:
Object
  • Object
show all
Defined in:
lib/api_gateway_dsl/mapping.rb,
lib/api_gateway_dsl/mapping/collection.rb

Defined Under Namespace

Classes: Collection

Constant Summary collapse

TYPES =

Maps Swagger parameter types to API Gateway parameter types

{
  'path'   => 'path',
  'query'  => 'querystring',
  'header' => 'header'
}.freeze
DEFAULT_SOURCE =
{
  'integration' => 'method',
  'method'      => 'integration'
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(destination, direction, type, name, source) ⇒ Mapping

Returns a new instance of Mapping.



16
17
18
19
20
21
22
# File 'lib/api_gateway_dsl/mapping.rb', line 16

def initialize(destination, direction, type, name, source)
  @destination = destination
  @direction   = direction
  @type        = type
  @name        = name
  @source      = source
end

Instance Method Details

#as_jsonObject



28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/api_gateway_dsl/mapping.rb', line 28

def as_json
  case @source
  when ::NilClass
    flatten(default_source => { @direction => { type => @name } })
  when ::Symbol
    flatten(default_source => { @direction => { type => @source } })
  when ::Hash
    flatten(@source)
  else
    "'#{@source}'"
  end
end

#keyObject



24
25
26
# File 'lib/api_gateway_dsl/mapping.rb', line 24

def key
  "#{@destination}.#{@direction}.#{type}.#{@name}"
end

#response_headerObject



41
42
43
# File 'lib/api_gateway_dsl/mapping.rb', line 41

def response_header
  ResponseHeader.new(@name)
end