Class: FileValidator

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

Overview

Copyright © 2013-2015 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"]

  if !@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
# File 'lib/file_validator.rb', line 32

def validate
  errors = []

  ["config_files", "changed_managed_files", "unmanaged_files"].each do |scope|
    next if !scope_extracted?(scope)

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

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

  errors
end