Class: PDK::Validate::Validator Abstract
- Inherits:
-
Object
- Object
- PDK::Validate::Validator
- Defined in:
- lib/pdk/validate/validator.rb
Overview
The base Validator class which all other validators should inherit from. Acutal validator implementation should inherit from other child abstract classes e.g. ValidatorGroup or ExternalCommandValdiator
Direct Known Subclasses
Instance Attribute Summary collapse
-
#context ⇒ PDK::Context::AbstractContext
readonly
The PDK context which the validator will be within.
-
#options ⇒ Object
readonly
A hash of options set when the Validator was instantiated.
-
#prepared ⇒ Boolean
readonly
private
Whether the validator is prepared to be invoked.
Instance Method Summary collapse
-
#initialize(context = nil, options = {}) ⇒ Validator
constructor
Creates a new Validator.
-
#invoke(_report) ⇒ Object
abstract
Invokes the validator and returns the exit code.
-
#name ⇒ String
abstract
Name of the Validator.
-
#prepare_invoke! ⇒ Object
abstract
private
Once off tasks to run prior to invoking.
-
#spinner ⇒ TTY::Spinner?
abstract
private
The TTY Spinner for this Validator.
-
#spinner_text ⇒ String
abstract
Returns the text used for the spinner to display to the user while invoking.
-
#spinners_enabled? ⇒ Boolean
private
Whether Spinners should be enabled for this validator.
-
#start_spinner ⇒ Object
private
Start the spinner if it exists.
-
#stop_spinner(success) ⇒ Object
private
Stop the spinner if it exists.
-
#valid_in_context? ⇒ Boolean
abstract
Whether this Validator can be invoked in this context.
Constructor Details
#initialize(context = nil, options = {}) ⇒ Validator
Creates a new Validator
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/pdk/validate/validator.rb', line 32 def initialize(context = nil, = {}) if context.nil? @context = PDK::Context::None.new(nil) else raise ArgumentError, format('Expected PDK::Context::AbstractContext but got \'%{klass}\' for context', klass: context.class) unless context.is_a?(PDK::Context::AbstractContext) @context = context end @options = .dup.freeze @prepared = false end |
Instance Attribute Details
#context ⇒ PDK::Context::AbstractContext (readonly)
The PDK context which the validator will be within.
15 16 17 |
# File 'lib/pdk/validate/validator.rb', line 15 def context @context end |
#options ⇒ Object (readonly)
A hash of options set when the Validator was instantiated
11 12 13 |
# File 'lib/pdk/validate/validator.rb', line 11 def @options end |
#prepared ⇒ Boolean (readonly)
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.
Whether the validator is prepared to be invoked. This should only be used for testing
23 24 25 |
# File 'lib/pdk/validate/validator.rb', line 23 def prepared @prepared end |
Instance Method Details
#invoke(_report) ⇒ Object
Invokes the validator and returns the exit code
114 115 116 117 |
# File 'lib/pdk/validate/validator.rb', line 114 def invoke(_report) prepare_invoke! 0 end |
#name ⇒ String
Name of the Validator
98 |
# File 'lib/pdk/validate/validator.rb', line 98 def name; end |
#prepare_invoke! ⇒ 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.
Once off tasks to run prior to invoking
105 106 107 |
# File 'lib/pdk/validate/validator.rb', line 105 def prepare_invoke! @prepared = true end |
#spinner ⇒ TTY::Spinner?
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.
The TTY Spinner for this Validator. Returns nil if spinners are disabled for this validator
75 |
# File 'lib/pdk/validate/validator.rb', line 75 def spinner; end |
#spinner_text ⇒ String
Returns the text used for the spinner to display to the user while invoking
56 |
# File 'lib/pdk/validate/validator.rb', line 56 def spinner_text; end |
#spinners_enabled? ⇒ Boolean
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.
Whether Spinners should be enabled for this validator
:nocov: .interactive? is tested elsewhere
64 65 66 |
# File 'lib/pdk/validate/validator.rb', line 64 def spinners_enabled? PDK::CLI::Util.interactive? end |
#start_spinner ⇒ 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.
Start the spinner if it exists
79 80 81 82 |
# File 'lib/pdk/validate/validator.rb', line 79 def start_spinner spinner&.auto_spin nil end |
#stop_spinner(success) ⇒ 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.
Stop the spinner if it exists
86 87 88 89 90 91 |
# File 'lib/pdk/validate/validator.rb', line 86 def stop_spinner(success) return if spinner.nil? success ? spinner.success : spinner.error nil end |
#valid_in_context? ⇒ Boolean
Whether this Validator can be invoked in this context. By default any Validator can work in any Context
47 48 49 |
# File 'lib/pdk/validate/validator.rb', line 47 def valid_in_context? true end |