Class: Sinatra::DocDsl::DocEntry
- Inherits:
-
Object
- Object
- Sinatra::DocDsl::DocEntry
- Defined in:
- lib/docdsl.rb
Instance Attribute Summary collapse
-
#desc ⇒ Object
Returns the value of attribute desc.
-
#headers ⇒ Object
Returns the value of attribute headers.
-
#params ⇒ Object
Returns the value of attribute params.
-
#paths ⇒ Object
Returns the value of attribute paths.
-
#query_params ⇒ Object
Returns the value of attribute query_params.
-
#sample_request ⇒ Object
Returns the value of attribute sample_request.
-
#sample_response ⇒ Object
Returns the value of attribute sample_response.
-
#status_codes ⇒ Object
Returns the value of attribute status_codes.
-
#the_payload ⇒ Object
Returns the value of attribute the_payload.
-
#the_response ⇒ Object
Returns the value of attribute the_response.
Instance Method Summary collapse
- #<<(path) ⇒ Object
- #describe(desc) ⇒ Object
- #header(name, desc) ⇒ Object
-
#initialize(description, &block) ⇒ DocEntry
constructor
A new instance of DocEntry.
- #json ⇒ Object
- #param(name, desc) ⇒ Object
- #payload(desc, example = nil) ⇒ Object
- #query_param(name, desc) ⇒ Object
- #response(desc, example = nil) ⇒ Object
- #status(code, meaning = nil) ⇒ Object
- #status_codes_map ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(description, &block) ⇒ DocEntry
Returns a new instance of DocEntry.
284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 |
# File 'lib/docdsl.rb', line 284 def initialize(description, &block) @paths=[] @desc=description @params={} @query_params={} @headers={} @the_payload=nil @sample_request=nil @the_response=nil @sample_response=nil @status_codes={} if(block) if block.arity == 1 block(self) else instance_eval(&block) end end end |
Instance Attribute Details
#desc ⇒ Object
Returns the value of attribute desc.
282 283 284 |
# File 'lib/docdsl.rb', line 282 def desc @desc end |
#headers ⇒ Object
Returns the value of attribute headers.
282 283 284 |
# File 'lib/docdsl.rb', line 282 def headers @headers end |
#params ⇒ Object
Returns the value of attribute params.
282 283 284 |
# File 'lib/docdsl.rb', line 282 def params @params end |
#paths ⇒ Object
Returns the value of attribute paths.
282 283 284 |
# File 'lib/docdsl.rb', line 282 def paths @paths end |
#query_params ⇒ Object
Returns the value of attribute query_params.
282 283 284 |
# File 'lib/docdsl.rb', line 282 def query_params @query_params end |
#sample_request ⇒ Object
Returns the value of attribute sample_request.
282 283 284 |
# File 'lib/docdsl.rb', line 282 def sample_request @sample_request end |
#sample_response ⇒ Object
Returns the value of attribute sample_response.
282 283 284 |
# File 'lib/docdsl.rb', line 282 def sample_response @sample_response end |
#status_codes ⇒ Object
Returns the value of attribute status_codes.
282 283 284 |
# File 'lib/docdsl.rb', line 282 def status_codes @status_codes end |
#the_payload ⇒ Object
Returns the value of attribute the_payload.
282 283 284 |
# File 'lib/docdsl.rb', line 282 def the_payload @the_payload end |
#the_response ⇒ Object
Returns the value of attribute the_response.
282 283 284 |
# File 'lib/docdsl.rb', line 282 def the_response @the_response end |
Instance Method Details
#<<(path) ⇒ Object
304 305 306 |
# File 'lib/docdsl.rb', line 304 def <<(path) self.paths << path end |
#describe(desc) ⇒ Object
312 313 314 |
# File 'lib/docdsl.rb', line 312 def describe(desc) @desc=desc end |
#header(name, desc) ⇒ Object
330 331 332 |
# File 'lib/docdsl.rb', line 330 def header(name,desc) @headers[name]=desc end |
#json ⇒ Object
390 391 392 393 394 395 396 397 398 399 400 401 402 403 |
# File 'lib/docdsl.rb', line 390 def json { :description=>@desc, :url_parameters=>@params, :paths=>@paths, :query_parameters=>@query_params, :headers=>@headers, :payload=>@the_payload, :sample_request=>@sample_request, :response=>@the_response, :status_codes=>@status_codes, :sample_response=>@sample_response } end |
#param(name, desc) ⇒ Object
326 327 328 |
# File 'lib/docdsl.rb', line 326 def param(name,desc) @params[name]=desc end |
#payload(desc, example = nil) ⇒ Object
316 317 318 319 |
# File 'lib/docdsl.rb', line 316 def payload(desc, example=nil) @the_payload=desc @sample_request=example end |
#query_param(name, desc) ⇒ Object
334 335 336 |
# File 'lib/docdsl.rb', line 334 def query_param(name,desc) @query_params[name]=desc end |
#response(desc, example = nil) ⇒ Object
321 322 323 324 |
# File 'lib/docdsl.rb', line 321 def response(desc,example=nil) @the_response=desc @sample_response=example end |
#status(code, meaning = nil) ⇒ Object
338 339 340 341 342 343 344 345 |
# File 'lib/docdsl.rb', line 338 def status(code,meaning=nil) official_meaning=status_codes_map[code] if meaning @status_codes[code]="#{official_meaning} - #{meaning}" else @status_codes[code]=official_meaning end end |
#status_codes_map ⇒ Object
347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 |
# File 'lib/docdsl.rb', line 347 def status_codes_map { 100=> 'Continue', 101=> 'Switching Protocols', 102=> 'Processing', 200=> 'OK', 201=> 'Created', 202=> 'Accepted', 203=> 'Non Authoritative Information', 204=> 'No Content', 205=> 'Reset Content', 206=> 'Partial Content', 207=> 'Multi-Status', 300=> 'Mutliple Choices', 301=> 'Moved Permanently', 302=> 'Moved Temporarily', 303=> 'See Other', 304=> 'Not Modified', 305=> 'Use Proxy', 307=> 'Temporary Redirect', 400=> 'Bad Request', 401=> 'Unauthorized', 402=> 'Payment Required', 403=> 'Forbidden', 404=> 'Not Found', 405=> 'Method Not Allowed', 406=> 'Not Acceptable', 407=> 'Proxy Authentication Required', 408=> 'Request Timeout', 409=> 'Conflict', 410=> 'Gone', 411=> 'Length Required', 412=> 'Precondition Failed', 413=> 'Request Entity Too Large', 414=> 'Request-URI Too Long', 415=> 'Unsupported Media Type', 416=> 'Requested Range Not Satisfiable', 417=> 'Expectation Failed', 500=> 'Internal Server Error', 503=> 'Temporarily Unavailable' } end |
#to_s ⇒ Object
308 309 310 |
# File 'lib/docdsl.rb', line 308 def to_s self.inspect end |