Class: Machinery::FileValidator

Inherits:
Object
  • Object
show all
Defined in:
lib/file_validator.rb

Overview

Copyright © 2013-2016 SUSE LLC

This program is free software; you can redistribute it and/or modify it under the terms of version 3 of the GNU General Public License as published by the Free Software Foundation.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, contact SUSE LLC.

To contact SUSE about this file by physical or electronic mail, you may find current contact information at www.suse.com

Instance Method Summary collapse

Constructor Details

#initialize(json_hash, base_path) ⇒ FileValidator

Returns a new instance of FileValidator.



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/file_validator.rb', line 19

def initialize(json_hash, base_path)
  @json_hash = json_hash
  @base_path = base_path

  @format_version = @json_hash["meta"]["format_version"] if @json_hash["meta"]

  unless @format_version
    raise Machinery::Errors::SystemDescriptionValidationFailed.new(
      ["Could not determine format version"]
    )
  end
end

Instance Method Details

#validateObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/file_validator.rb', line 32

def validate
  errors = []

  # the deprecated config_files is still needed to be able to validate older descriptions
  [
    "changed_config_files", "config_files", "changed_managed_files", "unmanaged_files"
  ].each do |scope|
    next unless scope_extracted?(scope)

    expected_files = expected_files(scope)
    file_errors = validate_scope(
      Machinery::ScopeFileStore.new(@base_path, scope.to_s),
      expected_files
    )

    errors << "Scope '#{scope}':\n" + file_errors.join("\n") unless file_errors.empty?
  end

  errors
end