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.
283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 |
# File 'lib/docdsl.rb', line 283 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.
281 282 283 |
# File 'lib/docdsl.rb', line 281 def desc @desc end |
#headers ⇒ Object
Returns the value of attribute headers.
281 282 283 |
# File 'lib/docdsl.rb', line 281 def headers @headers end |
#params ⇒ Object
Returns the value of attribute params.
281 282 283 |
# File 'lib/docdsl.rb', line 281 def params @params end |
#paths ⇒ Object
Returns the value of attribute paths.
281 282 283 |
# File 'lib/docdsl.rb', line 281 def paths @paths end |
#query_params ⇒ Object
Returns the value of attribute query_params.
281 282 283 |
# File 'lib/docdsl.rb', line 281 def query_params @query_params end |
#sample_request ⇒ Object
Returns the value of attribute sample_request.
281 282 283 |
# File 'lib/docdsl.rb', line 281 def sample_request @sample_request end |
#sample_response ⇒ Object
Returns the value of attribute sample_response.
281 282 283 |
# File 'lib/docdsl.rb', line 281 def sample_response @sample_response end |
#status_codes ⇒ Object
Returns the value of attribute status_codes.
281 282 283 |
# File 'lib/docdsl.rb', line 281 def status_codes @status_codes end |
#the_payload ⇒ Object
Returns the value of attribute the_payload.
281 282 283 |
# File 'lib/docdsl.rb', line 281 def the_payload @the_payload end |
#the_response ⇒ Object
Returns the value of attribute the_response.
281 282 283 |
# File 'lib/docdsl.rb', line 281 def the_response @the_response end |
Instance Method Details
#<<(path) ⇒ Object
303 304 305 |
# File 'lib/docdsl.rb', line 303 def <<(path) self.paths << path end |
#describe(desc) ⇒ Object
311 312 313 |
# File 'lib/docdsl.rb', line 311 def describe(desc) @desc=desc end |
#header(name, desc) ⇒ Object
329 330 331 |
# File 'lib/docdsl.rb', line 329 def header(name,desc) @headers[name]=desc end |
#json ⇒ Object
389 390 391 392 393 394 395 396 397 398 399 400 401 402 |
# File 'lib/docdsl.rb', line 389 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
325 326 327 |
# File 'lib/docdsl.rb', line 325 def param(name,desc) @params[name]=desc end |
#payload(desc, example = nil) ⇒ Object
315 316 317 318 |
# File 'lib/docdsl.rb', line 315 def payload(desc, example=nil) @the_payload=desc @sample_request=example end |
#query_param(name, desc) ⇒ Object
333 334 335 |
# File 'lib/docdsl.rb', line 333 def query_param(name,desc) @query_params[name]=desc end |
#response(desc, example = nil) ⇒ Object
320 321 322 323 |
# File 'lib/docdsl.rb', line 320 def response(desc,example=nil) @the_response=desc @sample_response=example end |
#status(code, meaning = nil) ⇒ Object
337 338 339 340 341 342 343 344 |
# File 'lib/docdsl.rb', line 337 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
346 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 |
# File 'lib/docdsl.rb', line 346 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
307 308 309 |
# File 'lib/docdsl.rb', line 307 def to_s self.inspect end |