appmap 0.93.4 → 0.94.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 61b703d48969c96f7967495b9719c47c2a391d8cbe612581480152614ff60cc5
4
- data.tar.gz: 5fb1da8f5574f3d96db8216fdcc4710e83c2d1a72a66f9b942be9eeba7b2ea95
3
+ metadata.gz: f15bcc9505431c7f47af59305eb18a7c8472f119396ab4cd2441114cbf95a0ca
4
+ data.tar.gz: affc5aaad8304d3a0e6b4f372934a1d38b9b6372ce2280d22a157d62c6156d8d
5
5
  SHA512:
6
- metadata.gz: d040f5fda6f71885a66090e1f14e7d1c0bc815ae4bc59b2c99ef47cbe982b4143ba8af8f4eeb2d6ad032c324b66ee4a61731723b9a27b33a712f55cac7e66d37
7
- data.tar.gz: e915ca689cece094856ad434241c5107dc78914967ab0b355586c512c36397a1055634e411145b604b9581b19a89afa8e7cea63e68741c35e03afe20ba1c627b
6
+ metadata.gz: fe56e37f042cac25f53612f4489762e42cb02ce231270fac02dda746abf73ed3e79febfc60a30829b25e7c7d395bb14f01398c62226e28a0bf795af751e33aae
7
+ data.tar.gz: f045b85390e4a335f9d1b62cdcefb2f45466e2d24f9009b3a31b990cfed5ffafdd475166b93a73889209f8959d60d51dcf91f80a7835bcdcc2a01dfe659f1752
data/.rubocop.yml CHANGED
@@ -14,6 +14,9 @@ Layout/CaseIndentation:
14
14
  Layout/FirstArgumentIndentation:
15
15
  EnforcedStyle: consistent
16
16
 
17
+ Layout/FirstArrayElementIndentation:
18
+ EnforcedStyle: consistent
19
+
17
20
  Layout/SpaceInsideArrayLiteralBrackets:
18
21
  Enabled: false
19
22
 
data/CHANGELOG.md CHANGED
@@ -1,3 +1,17 @@
1
+ # [0.94.0](https://github.com/getappmap/appmap-ruby/compare/v0.93.5...v0.94.0) (2022-11-22)
2
+
3
+
4
+ ### Features
5
+
6
+ * Emit nested return_value.properties ([2c74c68](https://github.com/getappmap/appmap-ruby/commit/2c74c68f9e2a5bcb3f095850c9d520422b63e25f))
7
+
8
+ ## [0.93.5](https://github.com/getappmap/appmap-ruby/compare/v0.93.4...v0.93.5) (2022-11-08)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * Only show a warning in non-Rails projects ([4ed86c7](https://github.com/getappmap/appmap-ruby/commit/4ed86c705ea0183940714af47bdda81917ad3f92)), closes [#292](https://github.com/getappmap/appmap-ruby/issues/292)
14
+
1
15
  ## [0.93.4](https://github.com/getappmap/appmap-ruby/compare/v0.93.3...v0.93.4) (2022-11-04)
2
16
 
3
17
 
@@ -14,7 +14,7 @@ module AppMap
14
14
  schema = YAML.safe_load(File.read(schema_path))
15
15
  result = {
16
16
  version: 2,
17
- errors: config_validator.valid? ? [] : config_validator.violations.map(&:to_h),
17
+ errors: config_validator.violations.map(&:to_h),
18
18
  schema: schema
19
19
  }
20
20
  puts JSON.pretty_generate(result)
data/lib/appmap/event.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'weakref'
4
+ require_relative './value_inspector'
4
5
 
5
6
  module AppMap
6
7
  module Event
@@ -20,6 +21,8 @@ module AppMap
20
21
  MethodEventStruct = Struct.new(:id, :event, :thread_id)
21
22
 
22
23
  class MethodEvent < MethodEventStruct
24
+ extend ValueInspector
25
+
23
26
  MAX_ARRAY_ENUMERATION = 10
24
27
  MAX_HASH_ENUMERATION = 10
25
28
  MAX_STRING_LENGTH = 100
@@ -61,33 +64,12 @@ module AppMap
61
64
  end
62
65
 
63
66
  def add_size(param, value)
64
- # Don't risk calling #size on things like data-access objects, which can and will issue queries for this information.
65
- if value.is_a?(Array) || value.is_a?(Hash)
66
- param[:size] = value.size
67
- end
67
+ size = ValueInspector.detect_size(value)
68
+ param[:size] = size if size
68
69
  end
69
70
 
70
71
  def add_schema(param, value)
71
- begin
72
- if value.respond_to?(:keys)
73
- param[:properties] = value.keys.map { |key| { name: key, class: best_class_name(value[key]) } }
74
- elsif value.respond_to?(:first) && value.first
75
- if value.first != value
76
- add_schema param, value.first
77
- end
78
- end
79
- rescue
80
- warn "Error in add_schema(#{value.class})", $!
81
- end
82
- end
83
-
84
- # Heuristic for dynamically defined class whose name can be nil
85
- def best_class_name(value)
86
- value_cls = value.class
87
- while value_cls && value_cls.name.nil?
88
- value_cls = value_cls.superclass
89
- end
90
- value_cls&.name || 'unknown'
72
+ ValueInspector.detect_schema(value, type_info: param)
91
73
  end
92
74
 
93
75
  def encode_display_string(value)
@@ -25,7 +25,11 @@ module AppMap
25
25
 
26
26
  def errors
27
27
  valid?
28
- config_validator.violations.map(&:message)
28
+ config_validator.violations.filter(&:error?).map(&:message)
29
+ end
30
+
31
+ def warnings
32
+ config_validator.violations.filter(&:warning?).map(&:message)
29
33
  end
30
34
 
31
35
  private
@@ -7,8 +7,6 @@ module AppMap
7
7
  module Service
8
8
  module Validator
9
9
  class ConfigValidator
10
- attr_reader :violations
11
-
12
10
  def initialize(config_file)
13
11
  @config_file = config_file
14
12
  @violations = []
@@ -19,17 +17,29 @@ module AppMap
19
17
  end
20
18
 
21
19
  def valid?
20
+ validate
21
+ @violations.none?(&:error?)
22
+ end
23
+
24
+ def violations
25
+ validate
26
+ @violations
27
+ end
28
+
29
+ private
30
+
31
+ def validate
32
+ return if @validated
33
+
22
34
  @violations = []
23
35
  validate_ruby_version
24
36
  validate_rails_presence
25
37
  validate_config_presence
26
38
  parse_config
27
39
  validate_config_load
28
- @violations.empty?
40
+ @validated = true
29
41
  end
30
42
 
31
- private
32
-
33
43
  def present?
34
44
  File.exist?(@config_file)
35
45
  end
@@ -71,8 +81,10 @@ module AppMap
71
81
 
72
82
  def validate_rails_presence
73
83
  unless Gem.loaded_specs.has_key?('rails')
74
- @violations << Violation.error(
75
- message: 'AppMap auto-configuration is currently not available for non Rails projects'
84
+ @violations << Violation.warning(
85
+ message: "This is not a Rails project. AppMap won't be automatically loaded.",
86
+ detailed_message: "Please ensure you `require 'appmap'` in your test environment.",
87
+ help_urls: [ 'https://appmap.io/docs/reference/appmap-ruby#tests-recording' ]
76
88
  )
77
89
  end
78
90
  end
@@ -44,6 +44,14 @@ module AppMap
44
44
  hash[var.to_s.delete("@")] = self.instance_variable_get(var)
45
45
  end.compact
46
46
  end
47
+
48
+ def error?
49
+ @level == :error
50
+ end
51
+
52
+ def warning?
53
+ @level == :warning
54
+ end
47
55
  end
48
56
  end
49
57
  end
@@ -0,0 +1,49 @@
1
+ module AppMap
2
+ module ValueInspector
3
+ extend self
4
+
5
+ MAX_DEPTH = 3
6
+
7
+ def detect_size(value)
8
+ # Don't risk calling #size on things like data-access objects, which can and will issue queries for this information.
9
+ if value.is_a?(Array) || value.is_a?(Hash)
10
+ value.size
11
+ end
12
+ end
13
+
14
+ def detect_schema(value, max_depth: MAX_DEPTH, type_info: {}, observed_values: Set.new(), depth: 0)
15
+ return type_info if depth == max_depth
16
+
17
+ begin
18
+ if value.respond_to?(:keys)
19
+ properties = value.keys.select { |key| key != '' && !key.nil? }.map do |key|
20
+ next_value = value[key]
21
+ next if observed_values.include?(next_value)
22
+
23
+ observed_values << next_value
24
+ { name: key, class: best_class_name(next_value) }.tap do |schema|
25
+ detect_schema(next_value, **{ max_depth: max_depth, type_info: schema, observed_values: observed_values, depth: depth + 1 })
26
+ end
27
+ end.compact
28
+ type_info[:properties] = properties unless properties.empty?
29
+ elsif value.respond_to?(:first) && !observed_values.include?(value.first)
30
+ observed_values << value.first
31
+ detect_schema(value.first, **{ max_depth: max_depth, type_info: type_info, observed_values: observed_values, depth: depth + 1 })
32
+ end
33
+ rescue
34
+ warn "Error in add_schema(#{value.class})", $!
35
+ raise
36
+ end
37
+ type_info
38
+ end
39
+
40
+ # Heuristic for dynamically defined class whose name can be nil
41
+ def best_class_name(value)
42
+ value_cls = value.class
43
+ while value_cls && value_cls.name.nil?
44
+ value_cls = value_cls.superclass
45
+ end
46
+ value_cls&.name || 'unknown'
47
+ end
48
+ end
49
+ end
@@ -3,9 +3,9 @@
3
3
  module AppMap
4
4
  URL = 'https://github.com/applandinc/appmap-ruby'
5
5
 
6
- VERSION = '0.93.4'
6
+ VERSION = '0.94.0'
7
7
 
8
- APPMAP_FORMAT_VERSION = '1.9.0'
8
+ APPMAP_FORMAT_VERSION = '1.10.0'
9
9
 
10
10
  SUPPORTED_RUBY_VERSIONS = %w[2.5 2.6 2.7 3.0 3.1].freeze
11
11
 
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.93.4
4
+ version: 0.94.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: 2022-11-04 00:00:00.000000000 Z
11
+ date: 2022-11-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: method_source
@@ -432,6 +432,7 @@ files:
432
432
  - lib/appmap/swagger/stable.rb
433
433
  - lib/appmap/trace.rb
434
434
  - lib/appmap/util.rb
435
+ - lib/appmap/value_inspector.rb
435
436
  - lib/appmap/version.rb
436
437
  - package.json
437
438
  - release.sh