appmap 0.32.0 → 0.33.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f6becd9530caf01e14b8a7db69e74b40297d41e4724f25315cd7b44ea6ad3e02
4
- data.tar.gz: 2863e714f0651d73fc9f2f87d0ea2c5f9fb7f9f553d1f109d9d8f10fff35f5be
3
+ metadata.gz: ae23c62b9a3f01cc3b7680706746d2f51c94c3a776978a8ee2d4e0e8501fca01
4
+ data.tar.gz: 4aa33af19ed0c31b826f8cffa75e147e2781fe93ed39353ace29cede8a7882b9
5
5
  SHA512:
6
- metadata.gz: a5574478fee68b2531449df2b9ec135a60110950cdcd518cf5b85d10e6d0d756b3e22740a4ce0905d7fccb2e6e7d684ee38ac61fd11ad6fdfcff4355a7ae7b36
7
- data.tar.gz: d15827a809ffde6b6ff98bfb62057f759cdc03e7e24452c1a8273801f94e37d61bab265ddb863ce8f60d83c639875fcf2d247f27abe9b27164817f0739b7c699
6
+ metadata.gz: 04a3c1bee70c02c96c1b71d5153a6ed44d668d6fc69d6da77cd6201364ede609bee93604f4ace391ddb38f8259841d6b334fdbe9051f1667d41cf3383281fe58
7
+ data.tar.gz: c60d868b2c1fa9c1e8742856dd7f946f5bf1284cab01a4478708c1582add5ca8fd16002e150d8a2cd897819edb661a9082cb01ec3e9879686d85d49b341d4ba8
@@ -1,3 +1,7 @@
1
+ # v0.33.0
2
+
3
+ * Added command `AppMap.open` to open an AppMap in the browser.
4
+
1
5
  # v0.32.0
2
6
 
3
7
  * Removes un-necessary fields from `return` events.
@@ -26,6 +26,7 @@ Gem::Specification.new do |spec|
26
26
  spec.add_dependency 'faraday'
27
27
  spec.add_dependency 'gli'
28
28
  spec.add_dependency 'parser'
29
+ spec.add_dependency 'rack'
29
30
 
30
31
  spec.add_development_dependency 'bundler', '~> 1.16'
31
32
  spec.add_development_dependency 'minitest', '~> 5.0'
@@ -14,19 +14,20 @@ require 'appmap/trace'
14
14
  require 'appmap/class_map'
15
15
  require 'appmap/metadata'
16
16
  require 'appmap/util'
17
+ require 'appmap/open'
17
18
 
18
19
  module AppMap
19
20
  class << self
20
21
  @configuration = nil
21
22
  @configuration_file_path = nil
22
23
 
23
- # configuration gets the configuration. If there is no configuration, the default
24
+ # Gets the configuration. If there is no configuration, the default
24
25
  # configuration is initialized.
25
26
  def configuration
26
- @configuration ||= configure
27
+ @configuration ||= initialize
27
28
  end
28
29
 
29
- # configuration= sets the configuration. This is only expected to happen once per
30
+ # Sets the configuration. This is only expected to happen once per
30
31
  # Ruby process.
31
32
  def configuration=(config)
32
33
  warn 'AppMap is already configured' if @configuration && config
@@ -34,22 +35,24 @@ module AppMap
34
35
  @configuration = config
35
36
  end
36
37
 
37
- # initialize configures AppMap for recording. Default behavior is to configure from "appmap.yml".
38
+ # Configures AppMap for recording. Default behavior is to configure from "appmap.yml".
38
39
  # This method also activates the code hooks which record function calls as trace events.
39
40
  # Call this function before the program code is loaded by the Ruby VM, otherwise
40
41
  # the load events won't be seen and the hooks won't activate.
41
42
  def initialize(config_file_path = 'appmap.yml')
42
43
  warn "Configuring AppMap from path #{config_file_path}"
43
- self.configuration = Config.load_from_file(config_file_path)
44
- Hook.new(configuration).enable
44
+ Config.load_from_file(config_file_path).tap do |configuration|
45
+ self.configuration = configuration
46
+ Hook.new(configuration).enable
47
+ end
45
48
  end
46
49
 
47
- # tracing can be used to start tracing, stop tracing, and record events.
50
+ # Used to start tracing, stop tracing, and record events.
48
51
  def tracing
49
52
  @tracing ||= Trace::Tracing.new
50
53
  end
51
54
 
52
- # record records the events which occur while processing a block,
55
+ # Records the events which occur while processing a block,
53
56
  # and returns an AppMap as a Hash.
54
57
  def record
55
58
  tracer = tracing.trace
@@ -70,12 +73,18 @@ module AppMap
70
73
  }
71
74
  end
72
75
 
73
- # class_map builds a class map from a config and a list of Ruby methods.
76
+ # Uploads an AppMap to the AppLand website and displays it.
77
+ def open(appmap = nil, &block)
78
+ appmap ||= AppMap.record(&block)
79
+ AppMap::Open.new(appmap).perform
80
+ end
81
+
82
+ # Builds a class map from a config and a list of Ruby methods.
74
83
  def class_map(methods)
75
84
  ClassMap.build_from_methods(configuration, methods)
76
85
  end
77
86
 
78
- # detect_metadata returns default metadata detected from the Ruby system and from the
87
+ # Returns default metadata detected from the Ruby system and from the
79
88
  # filesystem.
80
89
  def detect_metadata
81
90
  @metadata ||= Metadata.detect.freeze
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AppMap
4
+ OpenStruct = Struct.new(:appmap)
5
+
6
+ class Open < OpenStruct
7
+ attr_reader :port
8
+
9
+ def perform
10
+ server = run_server
11
+ open_browser
12
+ server.kill
13
+ end
14
+
15
+ def page
16
+ require 'rack/utils'
17
+ <<~PAGE
18
+ <!DOCTYPE html>
19
+ <html>
20
+ <head>
21
+ <title>&hellip;</title>
22
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
23
+ <script type="text/javascript">
24
+ function dosubmit() { document.forms[0].submit(); }
25
+ </script>
26
+ </head>
27
+ <body onload="dosubmit();">
28
+ <form action="https://app.land/scenario_uploads" method="POST" accept-charset="utf-8">
29
+ <input type="hidden" name="data" value='#{Rack::Utils.escape_html appmap.to_json}'>
30
+ </form>
31
+ </body>
32
+ </html>
33
+ PAGE
34
+ end
35
+
36
+ def run_server
37
+ require 'rack'
38
+ Thread.new do
39
+ Rack::Handler::WEBrick.run(
40
+ lambda do |env|
41
+ return [200, { 'Content-Type' => 'text/html' }, [page]]
42
+ end,
43
+ :Port => 0
44
+ ) do |server|
45
+ @port = server.config[:Port]
46
+ end
47
+ end.tap do
48
+ sleep 1.0
49
+ end
50
+ end
51
+
52
+ def open_browser
53
+ system 'open', "http://localhost:#{@port}"
54
+ sleep 5.0
55
+ end
56
+ end
57
+ end
@@ -3,7 +3,7 @@
3
3
  module AppMap
4
4
  URL = 'https://github.com/applandinc/appmap-ruby'
5
5
 
6
- VERSION = '0.32.0'
6
+ VERSION = '0.33.0'
7
7
 
8
8
  APPMAP_FORMAT_VERSION = '1.2'
9
9
  end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe AppMap::Open do
6
+ context 'a block of Ruby code' do
7
+ it 'opens in the browser' do
8
+ appmap = AppMap.record do
9
+ File.read __FILE__
10
+ end
11
+
12
+ open = AppMap::Open.new(appmap)
13
+ server = open.run_server
14
+ page = Net::HTTP.get URI.parse("http://localhost:#{open.port}")
15
+ expect(page).to include(%(name="data" value='{&quot;version))
16
+ server.kill
17
+ end
18
+ end
19
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: appmap
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.32.0
4
+ version: 0.33.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin Gilpin
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-08-05 00:00:00.000000000 Z
11
+ date: 2020-08-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rack
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: bundler
71
85
  requirement: !ruby/object:Gem::Requirement
@@ -277,6 +291,7 @@ files:
277
291
  - lib/appmap/metadata.rb
278
292
  - lib/appmap/middleware/remote_recording.rb
279
293
  - lib/appmap/minitest.rb
294
+ - lib/appmap/open.rb
280
295
  - lib/appmap/rails/action_handler.rb
281
296
  - lib/appmap/rails/sql_handler.rb
282
297
  - lib/appmap/railtie.rb
@@ -457,6 +472,7 @@ files:
457
472
  - spec/fixtures/rails_users_app/spec/spec_helper.rb
458
473
  - spec/fixtures/rails_users_app/users_app/.gitignore
459
474
  - spec/hook_spec.rb
475
+ - spec/open_spec.rb
460
476
  - spec/rails_spec_helper.rb
461
477
  - spec/railtie_spec.rb
462
478
  - spec/record_sql_rails4_pg_spec.rb