Module: Impression::RackAdapter

Defined in:
lib/impression/rack_app.rb

Class Method Summary collapse

Class Method Details

.env(request) ⇒ Object



38
39
40
# File 'lib/impression/rack_app.rb', line 38

def env(request)
  Qeweney.rack_env_from_request(request)
end

.load(path) ⇒ Object



33
34
35
36
# File 'lib/impression/rack_app.rb', line 33

def load(path)
  src = IO.read(path)
  instance_eval(src, path, 1)
end

.respond(request, status_code, headers, body) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/impression/rack_app.rb', line 42

def respond(request, (status_code, headers, body))
  headers[':status'] = status_code.to_s

  content =
    if body.respond_to?(:to_path)
      File.open(body.to_path, 'rb') { |f| f.read }
    else
      body.first
    end

  request.respond(content, headers)
end

.run(app) ⇒ Object



29
30
31
# File 'lib/impression/rack_app.rb', line 29

def run(app)
  ->(req) { respond(req, app.(env(req))) }
end