Class: Packwerk::Visibility::Validator

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Includes:
Packwerk::Validator
Defined in:
lib/packwerk/visibility/validator.rb

Constant Summary collapse

Result =
Packwerk::Validator::Result

Instance Method Summary collapse

Instance Method Details

#call(package_set, configuration) ⇒ Object



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
# File 'lib/packwerk/visibility/validator.rb', line 13

def call(package_set, configuration)
  visible_settings = package_manifests_settings_for(configuration, 'visible_to')
  results = T.let([], T::Array[Result])

  all_package_names = package_set.to_set(&:name)

  package_manifests_settings_for(configuration, 'enforce_visibility').each do |config, setting|
    next if setting.nil?

    next if [TrueClass, FalseClass].include?(setting.class) || setting == 'strict'

    results << Result.new(
      ok: false,
      error_value: "\tInvalid 'enforce_visibility' option: #{setting.inspect} in #{config.inspect}"
    )
  end

  visible_settings.each do |config_file_path, setting|
    next if setting.nil?

    if setting.is_a?(Array)
      packages_not_found = setting.to_set - all_package_names

      if packages_not_found.any?
        results << Result.new(
          ok: false,
          error_value: "'visible_to' option must only contain valid packages in #{config_file_path.inspect}. Invalid packages: #{packages_not_found.to_a.inspect}"
        )
      end
    else
      results << Result.new(
        ok: false,
        error_value: "'visible_to' option must be an array in #{config_file_path.inspect}."
      )
    end
  end

  merge_results(results, separator: "\n---\n")
end

#permitted_keysObject



54
55
56
# File 'lib/packwerk/visibility/validator.rb', line 54

def permitted_keys
  %w[visible_to enforce_visibility]
end