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.
278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 |
# File 'lib/docdsl.rb', line 278 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.
276 277 278 |
# File 'lib/docdsl.rb', line 276 def desc @desc end |
#headers ⇒ Object
Returns the value of attribute headers.
276 277 278 |
# File 'lib/docdsl.rb', line 276 def headers @headers end |
#params ⇒ Object
Returns the value of attribute params.
276 277 278 |
# File 'lib/docdsl.rb', line 276 def params @params end |
#paths ⇒ Object
Returns the value of attribute paths.
276 277 278 |
# File 'lib/docdsl.rb', line 276 def paths @paths end |
#query_params ⇒ Object
Returns the value of attribute query_params.
276 277 278 |
# File 'lib/docdsl.rb', line 276 def query_params @query_params end |
#sample_request ⇒ Object
Returns the value of attribute sample_request.
276 277 278 |
# File 'lib/docdsl.rb', line 276 def sample_request @sample_request end |
#sample_response ⇒ Object
Returns the value of attribute sample_response.
276 277 278 |
# File 'lib/docdsl.rb', line 276 def sample_response @sample_response end |
#status_codes ⇒ Object
Returns the value of attribute status_codes.
276 277 278 |
# File 'lib/docdsl.rb', line 276 def status_codes @status_codes end |
#the_payload ⇒ Object
Returns the value of attribute the_payload.
276 277 278 |
# File 'lib/docdsl.rb', line 276 def the_payload @the_payload end |
#the_response ⇒ Object
Returns the value of attribute the_response.
276 277 278 |
# File 'lib/docdsl.rb', line 276 def the_response @the_response end |
Instance Method Details
#<<(path) ⇒ Object
298 299 300 |
# File 'lib/docdsl.rb', line 298 def <<(path) self.paths << path end |
#describe(desc) ⇒ Object
310 311 312 |
# File 'lib/docdsl.rb', line 310 def describe(desc) @desc=desc end |
#header(name, desc) ⇒ Object
328 329 330 |
# File 'lib/docdsl.rb', line 328 def header(name,desc) @headers[name]=desc end |
#inspect ⇒ Object
306 307 308 |
# File 'lib/docdsl.rb', line 306 def inspect "#{@paths.join(', ')} # #{@desc}" end |
#json ⇒ Object
388 389 390 391 392 393 394 395 396 397 398 399 400 401 |
# File 'lib/docdsl.rb', line 388 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
324 325 326 |
# File 'lib/docdsl.rb', line 324 def param(name,desc) @params[name]=desc end |
#payload(desc, example = nil) ⇒ Object
314 315 316 317 |
# File 'lib/docdsl.rb', line 314 def payload(desc, example=nil) @the_payload=desc @sample_request=example end |
#query_param(name, desc) ⇒ Object
332 333 334 |
# File 'lib/docdsl.rb', line 332 def query_param(name,desc) @query_params[name]=desc end |
#response(desc, example = nil) ⇒ Object
319 320 321 322 |
# File 'lib/docdsl.rb', line 319 def response(desc,example=nil) @the_response=desc @sample_response=example end |
#status(code, meaning = nil) ⇒ Object
336 337 338 339 340 341 342 343 |
# File 'lib/docdsl.rb', line 336 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
345 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 |
# File 'lib/docdsl.rb', line 345 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
302 303 304 |
# File 'lib/docdsl.rb', line 302 def to_s self.inspect end |