11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/pack_stats/private/metrics/public_usage.rb', line 11
def self.get_public_usage_metrics(prefix, packages, package_tags)
packages_except_for_root = packages.reject { |package| package.name == ParsePackwerk::ROOT_PACKAGE_NAME }
all_files = packages_except_for_root.flat_map do |package|
package.directory.glob('**/**.rb')
end
all_public_files = T.let([], T::Array[Pathname])
is_using_public_directory = 0
packages_except_for_root.each do |package|
public_files = package.directory.glob('app/public/**/**.rb')
all_public_files += public_files
is_using_public_directory += 1 if public_files.any?
end
[
GaugeMetric.for("#{prefix}.all_files.count", all_files.count, package_tags),
GaugeMetric.for("#{prefix}.public_files.count", all_public_files.count, package_tags),
GaugeMetric.for("#{prefix}.using_public_directory.count", is_using_public_directory, package_tags),
]
end
|