Class: ApiSketch::DSL::Responses

Inherits:
Base
  • Object
show all
Defined in:
lib/api_sketch/dsl/responses.rb

Instance Method Summary collapse

Methods inherited from Base

#use_shared_block

Constructor Details

#initialize(&block) ⇒ Responses

Returns a new instance of Responses.



3
4
5
6
7
# File 'lib/api_sketch/dsl/responses.rb', line 3

def initialize(&block)
  @list = []
  define_singleton_method(:initialize_responses_list, block)
  initialize_responses_list
end

Instance Method Details

#context(name, &block) ⇒ Object



13
14
15
16
17
18
19
20
# File 'lib/api_sketch/dsl/responses.rb', line 13

def context(name, &block)
  attributes = ::ApiSketch::DSL::AttributeParser.new(:root, &block).to_h
  if attributes[:parameters]
    params = ::ApiSketch::DSL::Parameters.new(&attributes[:parameters]).to_h
    attributes[:parameters] = ::ApiSketch::Model::Parameters.new(params)
  end
  @list << ::ApiSketch::Model::Response.new(attributes.merge(name: name))
end

#to_aObject



9
10
11
# File 'lib/api_sketch/dsl/responses.rb', line 9

def to_a
  @list
end