Module: Necropsy::Analyzers::Dynamic::RuntimeReference
- Defined in:
- lib/necropsy/analyzers/dynamic/runtime_reference.rb
Class Method Summary collapse
- .build(symbol_id:, file: nil, line: nil, definition_id: nil) ⇒ Object
- .key(reference) ⇒ Object
- .malformed?(reference) ⇒ Boolean
- .normalize(value) ⇒ Object
- .preferred(structured:, legacy:) ⇒ Object
- .relative_file(root, path) ⇒ Object
- .sort_key(reference) ⇒ Object
Class Method Details
.build(symbol_id:, file: nil, line: nil, definition_id: nil) ⇒ Object
9 10 11 12 13 14 15 16 |
# File 'lib/necropsy/analyzers/dynamic/runtime_reference.rb', line 9 def build(symbol_id:, file: nil, line: nil, definition_id: nil) { 'definition_id' => definition_id, 'symbol_id' => symbol_id, 'file' => file, 'line' => line }.compact end |
.key(reference) ⇒ Object
50 51 52 |
# File 'lib/necropsy/analyzers/dynamic/runtime_reference.rb', line 50 def key(reference) sort_key(reference) end |
.malformed?(reference) ⇒ Boolean
64 65 66 |
# File 'lib/necropsy/analyzers/dynamic/runtime_reference.rb', line 64 def malformed?(reference) !reference.is_a?(String) && normalize(reference).nil? end |
.normalize(value) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/necropsy/analyzers/dynamic/runtime_reference.rb', line 18 def normalize(value) return value if value.is_a?(String) return unless value.is_a?(Hash) data = value.to_h { |key, item| [key.to_s, item] } symbol_id = data['symbol_id'] return unless symbol_id.is_a?(String) && !symbol_id.empty? return unless valid_optional_string?(data, 'definition_id') && valid_optional_string?(data, 'file') line = normalize_line(data['line']) return if data.key?('line') && !data['line'].nil? && line.nil? build( definition_id: optional_string(data['definition_id']), symbol_id: symbol_id, file: optional_string(data['file']), line: line ) end |
.preferred(structured:, legacy:) ⇒ Object
54 55 56 57 58 59 60 61 62 |
# File 'lib/necropsy/analyzers/dynamic/runtime_reference.rb', line 54 def preferred(structured:, legacy:) return Array(legacy) if structured.nil? structured_values = Array(structured) structured_symbols = structured_values.filter_map do |reference| normalize(reference).then { |normalized| normalized['symbol_id'] if normalized.is_a?(Hash) } end.to_set structured_values + Array(legacy).reject { |symbol_id| structured_symbols.include?(symbol_id) } end |
.relative_file(root, path) ⇒ Object
68 69 70 71 72 73 74 |
# File 'lib/necropsy/analyzers/dynamic/runtime_reference.rb', line 68 def relative_file(root, path) = File.(path) prefix = "#{File.(root)}/" return unless .start_with?(prefix) .delete_prefix(prefix) end |
.sort_key(reference) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/necropsy/analyzers/dynamic/runtime_reference.rb', line 38 def sort_key(reference) normalized = normalize(reference) return ['', reference.to_s, '', 0] unless normalized.is_a?(Hash) [ normalized.fetch('definition_id', ''), normalized.fetch('symbol_id'), normalized.fetch('file', ''), normalized.fetch('line', 0) ] end |