Class: FluentCommandBuilder::PathValidator

Inherits:
Object
  • Object
show all
Defined in:
lib/fluent_command_builder/internal/path_validator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(command_builder_config) ⇒ PathValidator

Returns a new instance of PathValidator.



9
10
11
12
13
# File 'lib/fluent_command_builder/internal/path_validator.rb', line 9

def initialize(command_builder_config)
  @c = command_builder_config
  @printer = Printer.new
  @should_abort_on_fatal = true
end

Instance Attribute Details

#printerObject

Returns the value of attribute printer.



7
8
9
# File 'lib/fluent_command_builder/internal/path_validator.rb', line 7

def printer
  @printer
end

#should_abort_on_fatalObject

Returns the value of attribute should_abort_on_fatal.



7
8
9
# File 'lib/fluent_command_builder/internal/path_validator.rb', line 7

def should_abort_on_fatal
  @should_abort_on_fatal
end

Instance Method Details

#validateObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/fluent_command_builder/internal/path_validator.rb', line 15

def validate
  validate_validation_level
  return if validation_level == :off

  if @c.path
    p = Path.new @c.path
    evaluated_path = p.evaluated_path
    return if File.exist? evaluated_path
    message = %Q[Path for command "#{@c.command_name}", version "#{@c.version}" does not exist. Path: #{evaluated_path}]
  else
    return if WickedWitch[@c.command_name]
    message = %Q[Command "#{@c.command_name}" was not found on the PATH.]
  end

  case validation_level
    when :warn
      @printer.print_warning message
    when :fatal
      @printer.print_error message
      abort if @should_abort_on_fatal
    else
      # do nothing
  end
end