Module: Syro::Deck::API
- Included in:
- Syro::Deck
- Defined in:
- lib/syro.rb
Instance Method Summary collapse
- #call(env, inbox) ⇒ Object
- #capture(arg) ⇒ Object
- #consume(arg) ⇒ Object
- #default ⇒ Object
- #default_headers ⇒ Object
- #delete ⇒ Object
- #env ⇒ Object
- #get ⇒ Object
- #halt(response) ⇒ Object
- #inbox ⇒ Object
- #initialize(code) ⇒ Object
- #match(arg) ⇒ Object
- #on(arg) ⇒ Object
- #patch ⇒ Object
- #path ⇒ Object
- #post ⇒ Object
- #put ⇒ Object
- #req ⇒ Object
- #request_class ⇒ Object
- #res ⇒ Object
- #response_class ⇒ Object
- #root ⇒ Object
- #root? ⇒ Boolean
- #run(app, inbox = {}) ⇒ Object
Instance Method Details
#call(env, inbox) ⇒ Object
231 232 233 234 235 236 237 238 239 240 241 242 243 |
# File 'lib/syro.rb', line 231 def call(env, inbox) @syro_env = env @syro_req = request_class.new(env) @syro_res = response_class.new(default_headers) @syro_path = Seg.new(env.fetch(Rack::PATH_INFO)) @syro_inbox = inbox catch(:halt) do instance_eval(&@syro_code) @syro_res.finish end end |
#capture(arg) ⇒ Object
265 266 267 |
# File 'lib/syro.rb', line 265 def capture(arg) @syro_path.capture(arg, inbox) end |
#consume(arg) ⇒ Object
261 262 263 |
# File 'lib/syro.rb', line 261 def consume(arg) @syro_path.consume(arg) end |
#default ⇒ Object
282 283 284 |
# File 'lib/syro.rb', line 282 def default yield; halt(res.finish) end |
#default_headers ⇒ Object
219 220 221 |
# File 'lib/syro.rb', line 219 def default_headers return {} end |
#delete ⇒ Object
310 311 312 |
# File 'lib/syro.rb', line 310 def delete root { yield } if req.delete? end |
#env ⇒ Object
199 200 201 |
# File 'lib/syro.rb', line 199 def env @syro_env end |
#get ⇒ Object
294 295 296 |
# File 'lib/syro.rb', line 294 def get root { yield } if req.get? end |
#halt(response) ⇒ Object
257 258 259 |
# File 'lib/syro.rb', line 257 def halt(response) throw(:halt, response) end |
#inbox ⇒ Object
215 216 217 |
# File 'lib/syro.rb', line 215 def inbox @syro_inbox end |
#initialize(code) ⇒ Object
195 196 197 |
# File 'lib/syro.rb', line 195 def initialize(code) @syro_code = code end |
#match(arg) ⇒ Object
273 274 275 276 277 278 279 280 |
# File 'lib/syro.rb', line 273 def match(arg) case arg when String then consume(arg) when Symbol then capture(arg) when true then true else false end end |
#on(arg) ⇒ Object
286 287 288 |
# File 'lib/syro.rb', line 286 def on(arg) default { yield } if match(arg) end |
#patch ⇒ Object
306 307 308 |
# File 'lib/syro.rb', line 306 def patch root { yield } if req.patch? end |
#path ⇒ Object
211 212 213 |
# File 'lib/syro.rb', line 211 def path @syro_path end |
#post ⇒ Object
302 303 304 |
# File 'lib/syro.rb', line 302 def post root { yield } if req.post? end |
#put ⇒ Object
298 299 300 |
# File 'lib/syro.rb', line 298 def put root { yield } if req.put? end |
#req ⇒ Object
203 204 205 |
# File 'lib/syro.rb', line 203 def req @syro_req end |
#request_class ⇒ Object
223 224 225 |
# File 'lib/syro.rb', line 223 def request_class Rack::Request end |
#res ⇒ Object
207 208 209 |
# File 'lib/syro.rb', line 207 def res @syro_res end |
#response_class ⇒ Object
227 228 229 |
# File 'lib/syro.rb', line 227 def response_class Syro::Response end |
#root ⇒ Object
290 291 292 |
# File 'lib/syro.rb', line 290 def root default { yield } if root? end |
#root? ⇒ Boolean
269 270 271 |
# File 'lib/syro.rb', line 269 def root? @syro_path.root? end |
#run(app, inbox = {}) ⇒ Object
245 246 247 248 249 250 251 252 253 254 255 |
# File 'lib/syro.rb', line 245 def run(app, inbox = {}) path, script = env[Rack::PATH_INFO], env[Rack::SCRIPT_NAME] env[Rack::PATH_INFO] = @syro_path.curr env[Rack::SCRIPT_NAME] = @syro_path.prev env[Syro::INBOX] = inbox halt(app.call(env)) ensure env[Rack::PATH_INFO], env[Rack::SCRIPT_NAME] = path, script end |