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.
- #inspect ⇒ Object
- #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.
288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 |
# File 'lib/docdsl.rb', line 288 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.
286 287 288 |
# File 'lib/docdsl.rb', line 286 def desc @desc end |
#headers ⇒ Object
Returns the value of attribute headers.
286 287 288 |
# File 'lib/docdsl.rb', line 286 def headers @headers end |
#params ⇒ Object
Returns the value of attribute params.
286 287 288 |
# File 'lib/docdsl.rb', line 286 def params @params end |
#paths ⇒ Object
Returns the value of attribute paths.
286 287 288 |
# File 'lib/docdsl.rb', line 286 def paths @paths end |
#query_params ⇒ Object
Returns the value of attribute query_params.
286 287 288 |
# File 'lib/docdsl.rb', line 286 def query_params @query_params end |
#sample_request ⇒ Object
Returns the value of attribute sample_request.
286 287 288 |
# File 'lib/docdsl.rb', line 286 def sample_request @sample_request end |
#sample_response ⇒ Object
Returns the value of attribute sample_response.
286 287 288 |
# File 'lib/docdsl.rb', line 286 def sample_response @sample_response end |
#status_codes ⇒ Object
Returns the value of attribute status_codes.
286 287 288 |
# File 'lib/docdsl.rb', line 286 def status_codes @status_codes end |
#the_payload ⇒ Object
Returns the value of attribute the_payload.
286 287 288 |
# File 'lib/docdsl.rb', line 286 def the_payload @the_payload end |
#the_response ⇒ Object
Returns the value of attribute the_response.
286 287 288 |
# File 'lib/docdsl.rb', line 286 def the_response @the_response end |
Instance Method Details
#<<(path) ⇒ Object
308 309 310 |
# File 'lib/docdsl.rb', line 308 def <<(path) self.paths << path end |
#describe(desc) ⇒ Object
320 321 322 |
# File 'lib/docdsl.rb', line 320 def describe(desc) @desc=desc end |
#header(name, desc) ⇒ Object
338 339 340 |
# File 'lib/docdsl.rb', line 338 def header(name,desc) @headers[name]=desc end |
#inspect ⇒ Object
316 317 318 |
# File 'lib/docdsl.rb', line 316 def inspect "#{@paths.join(', ')} # #{@desc}" end |
#json ⇒ Object
398 399 400 401 402 403 404 405 406 407 408 409 410 411 |
# File 'lib/docdsl.rb', line 398 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
334 335 336 |
# File 'lib/docdsl.rb', line 334 def param(name,desc) @params[name]=desc end |
#payload(desc, example = nil) ⇒ Object
324 325 326 327 |
# File 'lib/docdsl.rb', line 324 def payload(desc, example=nil) @the_payload=desc @sample_request=example end |
#query_param(name, desc) ⇒ Object
342 343 344 |
# File 'lib/docdsl.rb', line 342 def query_param(name,desc) @query_params[name]=desc end |
#response(desc, example = nil) ⇒ Object
329 330 331 332 |
# File 'lib/docdsl.rb', line 329 def response(desc,example=nil) @the_response=desc @sample_response=example end |
#status(code, meaning = nil) ⇒ Object
346 347 348 349 350 351 352 353 |
# File 'lib/docdsl.rb', line 346 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
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 389 390 391 392 393 394 395 396 |
# File 'lib/docdsl.rb', line 355 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
312 313 314 |
# File 'lib/docdsl.rb', line 312 def to_s self.inspect end |