Class: FluentCommandBuilder::VersionValidator
- Inherits:
-
Object
- Object
- FluentCommandBuilder::VersionValidator
- Defined in:
- lib/fluent_command_builder/version_validator.rb
Instance Attribute Summary collapse
-
#printer ⇒ Object
Returns the value of attribute printer.
-
#should_abort_on_fatal ⇒ Object
Returns the value of attribute should_abort_on_fatal.
-
#validation_level ⇒ Object
writeonly
Sets the attribute validation_level.
Instance Method Summary collapse
-
#initialize(target_name, version_detector) ⇒ VersionValidator
constructor
A new instance of VersionValidator.
- #validate(expected_version_string, path = nil) ⇒ Object
Constructor Details
#initialize(target_name, version_detector) ⇒ VersionValidator
Returns a new instance of VersionValidator.
9 10 11 12 13 14 15 |
# File 'lib/fluent_command_builder/version_validator.rb', line 9 def initialize(target_name, version_detector) @target_name = target_name @version_detector = version_detector @validation_level = :fatal @should_abort_on_fatal = true @printer = FluentCommandBuilder::Printer.new end |
Instance Attribute Details
#printer ⇒ Object
Returns the value of attribute printer.
7 8 9 |
# File 'lib/fluent_command_builder/version_validator.rb', line 7 def printer @printer end |
#should_abort_on_fatal ⇒ Object
Returns the value of attribute should_abort_on_fatal.
7 8 9 |
# File 'lib/fluent_command_builder/version_validator.rb', line 7 def should_abort_on_fatal @should_abort_on_fatal end |
#validation_level=(value) ⇒ Object
Sets the attribute validation_level
7 8 9 |
# File 'lib/fluent_command_builder/version_validator.rb', line 7 def validation_level=(value) @validation_level = value end |
Instance Method Details
#validate(expected_version_string, path = nil) ⇒ Object
17 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 |
# File 'lib/fluent_command_builder/version_validator.rb', line 17 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 = @version_detector.version p.evaluated_path unless actual_version @printer.print_warning ('unable to determine actual version') return end unless is_valid? = actual_version.first(expected_version.to_a.length) case validation_level when :warn @printer.print_warning when :fatal @printer.print_error abort if @should_abort_on_fatal else # do nothing end end end |