class Satriani::Application
Attributes
env[R]
req[R]
res[R]
Public Class Methods
new(&block)
click to toggle source
# File lib/satriani/application.rb, line 18 def initialize(&block) @block = block end
Public Instance Methods
_call(env)
click to toggle source
# File lib/satriani/application.rb, line 26 def _call(env) @env = env @req = Rack::Request.new(env) @res = Rack::Response.new @matched = false catch(:satriani_run_next_app) { instance_eval(&@block) @res.status = 404 unless @matched || !@res.empty? return @res.finish }.call(env) end
accept(mimetype)
click to toggle source
# File lib/satriani/application.rb, line 101 def accept(mimetype) lambda do env['HTTP_ACCEPT'].split(',').any? { |s| s.strip == mimetype } && res['Content-Type'] = mimetype end end
also()
click to toggle source
# File lib/satriani/application.rb, line 50 def also @matched = false end
any(*args)
click to toggle source
# File lib/satriani/application.rb, line 46 def any(*args) args.any? { |a| a == true || (a != false && a.call) } end
call(env)
click to toggle source
# File lib/satriani/application.rb, line 22 def call(env) dup._call(env) end
check(&block)
click to toggle source
# File lib/satriani/application.rb, line 108 def check(&block) block end
default()
click to toggle source
# File lib/satriani/application.rb, line 84 def default true end
delete()
click to toggle source
# File lib/satriani/application.rb, line 99 def delete; req.delete?; end
extension(e="\\w+")
click to toggle source
# File lib/satriani/application.rb, line 72 def extension(e="\\w+") lambda { env["PATH_INFO"] =~ /\.(#{e})\z/ && $1 } end
get()
click to toggle source
# File lib/satriani/application.rb, line 96 def get; req.get?; end
header(p, default = nil)
click to toggle source
# File lib/satriani/application.rb, line 80 def header(p, default = nil) lambda { env[p.upcase.tr('-','_')] || default } end
host(h)
click to toggle source
# File lib/satriani/application.rb, line 88 def host(h) req.host == h end
method(m)
click to toggle source
# File lib/satriani/application.rb, line 92 def method(m) req.request_method = m end
number()
click to toggle source
# File lib/satriani/application.rb, line 64 def number path("\\d+") end
on(*arg) { |*map { |a| a == true || (a != false && call) || return }| ... }
click to toggle source
# File lib/satriani/application.rb, line 38 def on(*arg, &block) return if @matched s, p = env["SCRIPT_NAME"], env["PATH_INFO"] yield *arg.map { |a| a == true || (a != false && a.call) || return } env["SCRIPT_NAME"], env["PATH_INFO"] = s, p @matched = true end
param(p, default = nil)
click to toggle source
# File lib/satriani/application.rb, line 76 def param(p, default = nil) lambda { request[p] || default } end
path(p)
click to toggle source
# File lib/satriani/application.rb, line 54 def path(p) lambda { if env["PATH_INFO"] =~ /\A\/(#{p})(\/|\z)/ env["SCRIPT_NAME"] += "/#{$1}" env["PATH_INFO"] = $2 + $' $1 end } end
post()
click to toggle source
# File lib/satriani/application.rb, line 97 def post; req.post?; end
print(*args)
click to toggle source
# File lib/satriani/application.rb, line 123 def print(*args) args.each do |s| res.write s end end
put()
click to toggle source
# File lib/satriani/application.rb, line 98 def put; req.put?; end
puts(*args)
click to toggle source
# File lib/satriani/application.rb, line 116 def puts(*args) args.each do |s| res.write s res.write "\n" end end
run(app)
click to toggle source
# File lib/satriani/application.rb, line 112 def run(app) throw :satriani_run_next_app, app end
segment()
click to toggle source
# File lib/satriani/application.rb, line 68 def segment path("[^\\/]+") end