Class: FluentCommandBuilder::VersionValidator

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(target_name, &get_version) ⇒ VersionValidator

Returns a new instance of VersionValidator.



10
11
12
13
14
15
16
# File 'lib/fluent_command_builder/version_validator.rb', line 10

def initialize(target_name, &get_version)
  @target_name = target_name
  @validation_level = :fatal
  @should_abort_on_fatal = true
  @printer = FluentCommandBuilder::Printer.new
  @get_version = get_version
end

Instance Attribute Details

#get_version=(value) ⇒ Object

Sets the attribute get_version

Parameters:

  • value

    the value to set the attribute get_version to.



8
9
10
# File 'lib/fluent_command_builder/version_validator.rb', line 8

def get_version=(value)
  @get_version = value
end

#printerObject

Returns the value of attribute printer.



8
9
10
# File 'lib/fluent_command_builder/version_validator.rb', line 8

def printer
  @printer
end

#should_abort_on_fatalObject

Returns the value of attribute should_abort_on_fatal.



8
9
10
# File 'lib/fluent_command_builder/version_validator.rb', line 8

def should_abort_on_fatal
  @should_abort_on_fatal
end

#validation_level=(value) ⇒ Object

Sets the attribute validation_level

Parameters:

  • value

    the value to set the attribute validation_level to.



8
9
10
# File 'lib/fluent_command_builder/version_validator.rb', line 8

def validation_level=(value)
  @validation_level = value
end

Instance Method Details

#validate(expected_version_string, path = nil) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/fluent_command_builder/version_validator.rb', line 18

def validate(expected_version_string, path=nil)
  validate_validation_level
  return if @validation_level == :off

  p = Path.new path
  @expected_version_string = expected_version_string
  @actual_version_string = get_version File.join(p.evaluated_path, @target_name)

  unless actual_version
    @printer.print_warning error_message('unable to determine actual version')
    return
  end

  unless is_valid?
    message = error_message actual_version.first(expected_version.to_a.length)

    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
end