Class: PDK::Validate::InternalRubyValidator Abstract
- Inherits:
-
InvokableValidator
- Object
- Validator
- InvokableValidator
- PDK::Validate::InternalRubyValidator
- Defined in:
- lib/pdk/validate/internal_ruby_validator.rb
Overview
An abstract validator that runs ruby code internal to the PDK e.g. JSON and YAML validation, on a single file. The validator code must run within the PDK Ruby environment as opposed to the bundled Ruby environment for a module.
At a a minimum child classes should implment the ‘name`, `pattern` and `validate_target` methods
An example concrete implementation could look like:
module PDK
module Validate
module Tasks
class TasksNameValidator < InternalRubyValidator
def name
'task-name'
end
def pattern
'tasks/**/*'
end
def validate_target(report, target)
task_name = File.basename(target, File.extname(target))
... ruby code ...
success ? 0 : 1
end
end
end
end
end
Direct Known Subclasses
ControlRepo::EnvironmentConfValidator, Metadata::MetadataSyntaxValidator, Tasks::TasksMetadataLintValidator, Tasks::TasksNameValidator, YAML::YAMLSyntaxValidator
Instance Attribute Summary
Attributes inherited from Validator
Instance Method Summary collapse
-
#before_validation ⇒ Object
abstract
private
Tasks to run before validation occurs.
-
#invoke(report) ⇒ Object
Invokes the validator to call ‘validate_target` on each target.
- #prepare_invoke! ⇒ Object
-
#validate_target(report, target) ⇒ Integer
abstract
private
Validates a single target It is the responsibility of this method to populate the report with validation messages.
Methods inherited from InvokableValidator
#allow_empty_targets?, #fnmatch?, #ignore_dotfiles?, #invoke_style, #parse_targets, #pattern, #pattern_ignore, #process_invalid, #process_skipped, #spinner, #spinner_text, #valid_in_context?
Methods inherited from Validator
#initialize, #name, #spinner, #spinner_text, #spinners_enabled?, #start_spinner, #stop_spinner, #valid_in_context?
Constructor Details
This class inherits a constructor from PDK::Validate::Validator
Instance Method Details
#before_validation ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Tasks to run before validation occurs. This is run once every time ‘.invoke` is called
98 |
# File 'lib/pdk/validate/internal_ruby_validator.rb', line 98 def before_validation; end |
#invoke(report) ⇒ Object
Invokes the validator to call ‘validate_target` on each target
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/pdk/validate/internal_ruby_validator.rb', line 52 def invoke(report) prepare_invoke! process_skipped(report, @skipped) process_invalid(report, @invalid) return 0 if @targets.empty? return_val = 0 before_validation start_spinner @targets.each do |target| validation_result = validate_target(report, target) if validation_result.nil? report.add_event( file: target, source: name, state: :failure, severity: 'error', message: "Validation did not return an exit code for #{target}" ) validation_result = 1 end return_val = validation_result if validation_result > return_val end stop_spinner(return_val.zero?) return_val end |
#prepare_invoke! ⇒ Object
39 40 41 42 43 44 45 46 47 48 |
# File 'lib/pdk/validate/internal_ruby_validator.rb', line 39 def prepare_invoke! return if @prepared super # Parse the targets @targets, @skipped, @invalid = parse_targets nil end |
#validate_target(report, target) ⇒ Integer
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Validates a single target It is the responsibility of this method to populate the report with validation messages
93 |
# File 'lib/pdk/validate/internal_ruby_validator.rb', line 93 def validate_target(report, target); end |