Class: SnapshotUI::Web::Application

Inherits:
Object
  • Object
show all
Defined in:
lib/snapshot_ui/web/application.rb

Instance Method Summary collapse

Instance Method Details

#call(env) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/snapshot_ui/web/application.rb', line 11

def call(env)
  @request = Rack::Request.new(env)

  if parse_root_path(@request.path_info)
    @grouped_by_test_class = SnapshotUI::Snapshot.grouped_by_test_case
    if @request.get_header("HTTP_ACCEPT") != "text/event-stream"
      render("snapshots/index", status: 200)
    else
      [200, {"content-type" => "text/event-stream", "cache-control" => "no-cache", "connection" => "keep-alive"}, file_event_stream(SnapshotUI.configuration.storage_directory)]
    end
  elsif (slug = parse_raw_snapshot_path(@request.path_info))
    @snapshot = Snapshot.find(slug)
    render_raw_response_body(@snapshot.body)
  elsif (slug = parse_snapshot_path(@request.path_info))
    @snapshot = Snapshot.find(slug)
    render("snapshots/show", status: 200)
  else
    render("snapshots/not_found", status: 200)
  end
rescue SnapshotUI::Snapshot::NotFound
  render("snapshots/not_found", status: 200)
end