Class: DoctorSwagger::Endpoint
- Inherits:
-
Object
- Object
- DoctorSwagger::Endpoint
- Defined in:
- lib/doctor_swagger/endpoint.rb
Instance Method Summary collapse
- #as_json ⇒ Object
- #description(desc) ⇒ Object
-
#initialize(path, &block) ⇒ Endpoint
constructor
A new instance of Endpoint.
- #operation(nickname, &block) ⇒ Object
- #operations_as_json ⇒ Object
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_json ⇒ Object
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_json ⇒ Object
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 |