Class: AppMap::Open

Inherits:
OpenStruct show all
Defined in:
lib/appmap/open.rb

Instance Attribute Summary collapse

Attributes inherited from OpenStruct

#appmap

Instance Method Summary collapse

Instance Attribute Details

#portObject (readonly)

Returns the value of attribute port.



7
8
9
# File 'lib/appmap/open.rb', line 7

def port
  @port
end

Instance Method Details

#open_browserObject



52
53
54
55
# File 'lib/appmap/open.rb', line 52

def open_browser
  system 'open', "http://localhost:#{@port}"
  sleep 5.0
end

#pageObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/appmap/open.rb', line 15

def page
  require 'rack/utils'
  "  <!DOCTYPE html>\n  <html>\n  <head>\n    <title>&hellip;</title>\n    <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">\n    <script type=\"text/javascript\">\n    function dosubmit() { document.forms[0].submit(); }\n    </script>\n  </head>\n  <body onload=\"dosubmit();\">\n    <form action=\"https://app.land/scenario_uploads\" method=\"POST\" accept-charset=\"utf-8\">\n    <input type=\"hidden\" name=\"data\" value='\#{Rack::Utils.escape_html appmap.to_json}'>\n    </form>\n  </body>\n  </html>\n  PAGE\nend\n"

#performObject



9
10
11
12
13
# File 'lib/appmap/open.rb', line 9

def perform
  server = run_server
  open_browser
  server.kill
end

#run_serverObject



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/appmap/open.rb', line 36

def run_server
  require 'rack'
  Thread.new do
    Rack::Handler::WEBrick.run(
      lambda do |env|
        [200, { 'Content-Type' => 'text/html' }, [page]]
      end,
      :Port => 0
    ) do |server|
      @port = server.config[:Port]
    end
  end.tap do
    sleep 1.0
  end
end