Class: FeatureMap::Private::Validations::FeaturesUpToDate

Inherits:
Object
  • Object
show all
Includes:
Validator
Defined in:
lib/feature_map/private/validations/features_up_to_date.rb

Instance Method Summary collapse

Methods included from Validator

all, included

Instance Method Details

#validation_errors(files:, autocorrect: true, stage_changes: true) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/feature_map/private/validations/features_up_to_date.rb', line 7

def validation_errors(files:, autocorrect: true, stage_changes: true)
  return [] if Private.configuration.skip_features_validation

  actual_content_lines = AssignmentsFile.actual_contents_lines
  expected_content_lines = AssignmentsFile.expected_contents_lines

  features_file_up_to_date = actual_content_lines == expected_content_lines
  errors = []

  if !features_file_up_to_date
    if autocorrect
      AssignmentsFile.write!
      if stage_changes
        `git add #{AssignmentsFile.path}`
      end
    # If there is no current file or its empty, display a shorter message.
    elsif actual_content_lines == ['']
      errors << "        .feature_map/assignments.yml out of date. Run `bin/featuremap validate` to update the .feature_map/assignments.yml file\n      FEATURES_FILE_ERROR\n    else\n      missing_lines = expected_content_lines - actual_content_lines\n      extra_lines = actual_content_lines - expected_content_lines\n\n      missing_lines_text = if missing_lines.any?\n                             <<~COMMENT\n                               .feature_map/assignments.yml should contain the following lines, but does not:\n                               \#{missing_lines.map { |line| \"- \\\"\#{line}\\\"\" }.join(\"\\n\")}\n                             COMMENT\n                           end\n\n      extra_lines_text = if extra_lines.any?\n                           <<~COMMENT\n                             .feature_map/assignments.yml should not contain the following lines, but it does:\n                             \#{extra_lines.map { |line| \"- \\\"\#{line}\\\"\" }.join(\"\\n\")}\n                           COMMENT\n                         end\n\n      diff_text = if missing_lines_text && extra_lines_text\n                    \"\#{missing_lines_text}\\n\#{extra_lines_text}\".chomp\n                  elsif missing_lines_text\n                    missing_lines_text\n                  elsif extra_lines_text\n                    extra_lines_text\n                  else\n                    <<~TEXT\n                      There may be extra lines, or lines are out of order.\n                      You can try to regenerate the .feature_map/assignments.yml file from scratch:\n                      1) `rm .feature_map/assignments.yml`\n                      2) `bin/featuremap validate`\n                    TEXT\n                  end\n\n      errors << <<~FEATURES_FILE_ERROR\n        .feature_map/assignments.yml out of date. Run `bin/featuremap validate` to update the .feature_map/assignments.yml file\n\n        \#{diff_text.chomp}\n      FEATURES_FILE_ERROR\n    end\n  end\n\n  errors\nend\n"