Class: AppMap::ClassMap

Inherits:
Object show all
Defined in:
lib/appmap/class_map.rb

Defined Under Namespace

Modules: HasChildren, Types

Class Method Summary collapse

Class Method Details

.build_from_methods(methods) ⇒ Object

rubocop:enable Metrics/MethodLength



93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/appmap/class_map.rb', line 93

def build_from_methods(methods)
  root = Types::Root.new
  methods.each do |method|
    add_function root, method
  end

  collapse_package = lambda do |package|
    next unless package.type == "package"

    while package.children.length == 1 && package.children.all? { |child| child.type == "package" }
      child = package.children[0]
      package.children.clear
      child.children.each { |child| package.children << child }
      package.name = [package.name, child.name].join("/")
    end
    package.tap do
      package.children.map(&collapse_package)
    end
  end

  root.children.map(&collapse_package).map(&:to_h)
end

.parse_labels(comment) ⇒ Object

Labels can be embedded in the function comment. Label format is similar to YARD and JavaDoc. The keyword is @labels or @label. The keyword is followed by space-separated labels. For example: rubocop:disable Metrics/MethodLength



77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/appmap/class_map.rb', line 77

def parse_labels(comment)
  return [] unless comment

  comment
    .split("\n")
    .map { |line| line.match(/^\s*#\s*@labels?\s+(.*)/) }
    .compact
    .map { |match| match[1] }
    .inject([]) { |accum, labels|
    accum += labels.split(/\s+/)
    accum
  }
    .sort
end