Module: Packwerk::Validator

Extended by:
ActiveSupport::Autoload, T::Helpers, T::Sig
Included in:
Packwerk::Validators::DependencyValidator
Defined in:
lib/packwerk/validator.rb,
lib/packwerk/validator/result.rb

Defined Under Namespace

Classes: Result

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.allObject



27
28
29
30
# File 'lib/packwerk/validator.rb', line 27

def all
  load_defaults
  T.cast(validators.map(&:new), T::Array[Validator])
end

.included(base) ⇒ Object



22
23
24
# File 'lib/packwerk/validator.rb', line 22

def included(base)
  validators << base
end

Instance Method Details

#call(package_set, configuration) ⇒ Object



50
51
# File 'lib/packwerk/validator.rb', line 50

def call(package_set, configuration)
end

#merge_results(results, separator: "\n", before_errors: "", after_errors: "") ⇒ Object



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/packwerk/validator.rb', line 81

def merge_results(results, separator: "\n", before_errors: "", after_errors: "")
  results.reject!(&:ok?)

  if results.empty?
    Validator::Result.new(ok: true)
  else
    Validator::Result.new(
      ok: false,
      error_value: [
        before_errors,
        separator.lstrip,
        results.map(&:error_value).join(separator),
        after_errors,
      ].join,
    )
  end
end

#package_glob(configuration) ⇒ Object



69
70
71
# File 'lib/packwerk/validator.rb', line 69

def package_glob(configuration)
  configuration.package_paths
end

#package_manifests(configuration, glob_pattern = nil) ⇒ Object



62
63
64
65
66
# File 'lib/packwerk/validator.rb', line 62

def package_manifests(configuration, glob_pattern = nil)
  glob_pattern ||= package_glob(configuration)
  PackageSet.package_paths(configuration.root_path, glob_pattern, configuration.exclude)
    .map { |f| File.realpath(f) }
end

#package_manifests_settings_for(configuration, setting) ⇒ Object



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

def package_manifests_settings_for(configuration, setting)
  package_manifests(configuration).map { |f| [f, (YAML.load_file(File.join(f)) || {})[setting]] }
end

#permitted_keysObject



46
47
# File 'lib/packwerk/validator.rb', line 46

def permitted_keys
end

#relative_path(configuration, path) ⇒ Object



100
101
102
# File 'lib/packwerk/validator.rb', line 100

def relative_path(configuration, path)
  Pathname.new(path).relative_path_from(configuration.root_path)
end