Class: LocalPac::Actions::ValidatePacFile

Inherits:
Object
  • Object
show all
Defined in:
lib/local_pac/actions/validate_pac_file.rb

Instance Method Summary collapse

Constructor Details

#initialize(path, creator = File, validator = PacFileValidator.new) ⇒ ValidatePacFile

Returns a new instance of ValidatePacFile.



12
13
14
15
16
# File 'lib/local_pac/actions/validate_pac_file.rb', line 12

def initialize(path, creator = File, validator = PacFileValidator.new)
  @path      = path
  @validator = validator
  @creator   = creator
end

Instance Method Details

#runObject



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/local_pac/actions/validate_pac_file.rb', line 18

def run
  file = creator.new(path, ::File.read(path))

  if validator.valid?(file)
    puts "File \"#{file.path}\" is a valid pac file."
  else
    puts "File \"#{file.path}\" is not a valid pac file:"
    puts validator.errors(file)
  end
rescue Errno::EISDIR => e
  raise Exceptions::PacFileInvalid, e.message
end