Class: DoctorSwagger::Endpoint

Inherits:
Object
  • Object
show all
Defined in:
lib/doctor_swagger/endpoint.rb

Instance Method Summary collapse

Constructor Details

#initialize(path, &block) ⇒ Endpoint

Returns a new instance of Endpoint.


3
4
5
6
7
# File 'lib/doctor_swagger/endpoint.rb', line 3

def initialize(path, &block)
  @path = path
  @operations = []
  instance_eval(&block)
end

Instance Method Details

#as_jsonObject


17
18
19
20
21
22
# File 'lib/doctor_swagger/endpoint.rb', line 17

def as_json(*)
  {
    'path' => @path,
    'description' => @description,
  }.merge(operations_as_json)
end

#description(desc) ⇒ Object


24
25
26
# File 'lib/doctor_swagger/endpoint.rb', line 24

def description(desc)
  @description = desc
end

#operation(nickname, &block) ⇒ Object


28
29
30
# File 'lib/doctor_swagger/endpoint.rb', line 28

def operation(nickname, &block)
  @operations << Operation.new(nickname, &block)
end

#operations_as_jsonObject


9
10
11
12
13
14
15
# File 'lib/doctor_swagger/endpoint.rb', line 9

def operations_as_json
  if @operations && !@operations.empty?
    {'operations' => @operations.map(&:as_json)}
  else
    {}
  end
end