Class: FeatureMap::Private::MetricsFile
- Inherits:
-
Object
- Object
- FeatureMap::Private::MetricsFile
show all
- Defined in:
- lib/feature_map/private/metrics_file.rb
Overview
This class is responsible for turning FeatureMap directives (e.g. annotations, directory assignments, etc) into a metrics.yml file, that can be used as an input to a variety of engineering team utilities (e.g. PR/release announcements, documentation generation, etc).
Defined Under Namespace
Classes: FileContentError
Constant Summary
collapse
- FEATURES_KEY =
'features'
Class Method Summary
collapse
Class Method Details
.generate_content ⇒ Object
40
41
42
43
44
45
46
47
48
|
# File 'lib/feature_map/private/metrics_file.rb', line 40
def self.generate_content
feature_metrics = {}
Private.feature_file_assignments.each do |feature_name, files|
feature_metrics[feature_name] = FeatureMetricsCalculator.calculate_for_feature(files)
end
{ FEATURES_KEY => feature_metrics }
end
|
26
27
28
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/feature_map/private/metrics_file.rb', line 26
def self.
<<~HEADER
# STOP! - DO NOT EDIT THIS FILE MANUALLY
# This file was automatically generated by "bin/featuremap validate". The next time this file
# is generated any changes will be lost. For more details:
# https://github.com/Beyond-Finance/feature_map
#
# It is NOT recommended to commit this file into your source control. It will change as a
# result of nearly all other source code changes. This file should be ignored by your source
# control but can be used for other feature analysis operations (e.g. documentation
# generation, etc).
HEADER
end
|
.load_features! ⇒ Object
50
51
52
53
54
55
56
57
58
59
60
|
# File 'lib/feature_map/private/metrics_file.rb', line 50
def self.load_features!
metrics_content = YAML.load_file(path)
return metrics_content[FEATURES_KEY] if metrics_content.is_a?(Hash) && metrics_content[FEATURES_KEY]
raise FileContentError, "Unexpected content found in #{path}. Use `bin/featuremap validate` to regenerate it and try again."
rescue Psych::SyntaxError => e
raise FileContentError, "Invalid YAML content found at #{path}. Error: #{e.message} Use `bin/featuremap validate` to generate it and try again."
rescue Errno::ENOENT
raise FileContentError, "No feature metrics file found at #{path}. Use `bin/featuremap validate` to generate it and try again."
end
|
.path ⇒ Object
22
23
24
|
# File 'lib/feature_map/private/metrics_file.rb', line 22
def self.path
Pathname.pwd.join('.feature_map/metrics.yml')
end
|
.write! ⇒ Object
16
17
18
19
20
|
# File 'lib/feature_map/private/metrics_file.rb', line 16
def self.write!
FileUtils.mkdir_p(path.dirname) if !path.dirname.exist?
path.write([, "\n", generate_content.to_yaml].join)
end
|