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.
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'lib/docdsl.rb', line 155 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.
153 154 155 |
# File 'lib/docdsl.rb', line 153 def desc @desc end |
#headers ⇒ Object
Returns the value of attribute headers.
153 154 155 |
# File 'lib/docdsl.rb', line 153 def headers @headers end |
#params ⇒ Object
Returns the value of attribute params.
153 154 155 |
# File 'lib/docdsl.rb', line 153 def params @params end |
#paths ⇒ Object
Returns the value of attribute paths.
153 154 155 |
# File 'lib/docdsl.rb', line 153 def paths @paths end |
#query_params ⇒ Object
Returns the value of attribute query_params.
153 154 155 |
# File 'lib/docdsl.rb', line 153 def query_params @query_params end |
#sample_request ⇒ Object
Returns the value of attribute sample_request.
153 154 155 |
# File 'lib/docdsl.rb', line 153 def sample_request @sample_request end |
#sample_response ⇒ Object
Returns the value of attribute sample_response.
153 154 155 |
# File 'lib/docdsl.rb', line 153 def sample_response @sample_response end |
#status_codes ⇒ Object
Returns the value of attribute status_codes.
153 154 155 |
# File 'lib/docdsl.rb', line 153 def status_codes @status_codes end |
#the_payload ⇒ Object
Returns the value of attribute the_payload.
153 154 155 |
# File 'lib/docdsl.rb', line 153 def the_payload @the_payload end |
#the_response ⇒ Object
Returns the value of attribute the_response.
153 154 155 |
# File 'lib/docdsl.rb', line 153 def the_response @the_response end |
Instance Method Details
#<<(path) ⇒ Object
175 176 177 |
# File 'lib/docdsl.rb', line 175 def <<(path) self.paths << path end |
#describe(desc) ⇒ Object
187 188 189 |
# File 'lib/docdsl.rb', line 187 def describe(desc) @desc=desc end |
#header(name, desc) ⇒ Object
205 206 207 |
# File 'lib/docdsl.rb', line 205 def header(name,desc) @headers[name]=desc end |
#inspect ⇒ Object
183 184 185 |
# File 'lib/docdsl.rb', line 183 def inspect "#{@paths.join(', ')} # #{@desc}" end |
#json ⇒ Object
265 266 267 268 269 270 271 272 273 274 275 276 277 278 |
# File 'lib/docdsl.rb', line 265 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
201 202 203 |
# File 'lib/docdsl.rb', line 201 def param(name,desc) @params[name]=desc end |
#payload(desc, example = nil) ⇒ Object
191 192 193 194 |
# File 'lib/docdsl.rb', line 191 def payload(desc, example=nil) @the_payload=desc @sample_request=example end |
#query_param(name, desc) ⇒ Object
209 210 211 |
# File 'lib/docdsl.rb', line 209 def query_param(name,desc) @query_params[name]=desc end |
#response(desc, example = nil) ⇒ Object
196 197 198 199 |
# File 'lib/docdsl.rb', line 196 def response(desc,example=nil) @the_response=desc @sample_response=example end |
#status(code, meaning = nil) ⇒ Object
213 214 215 216 217 218 219 220 |
# File 'lib/docdsl.rb', line 213 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
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 |
# File 'lib/docdsl.rb', line 222 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
179 180 181 |
# File 'lib/docdsl.rb', line 179 def to_s self.inspect end |