Class: PDK::Validate::Tasks::Name
- Inherits:
-
BaseValidator
- Object
- BaseValidator
- PDK::Validate::Tasks::Name
- Defined in:
- lib/pdk/validate/tasks/name.rb
Constant Summary collapse
- INVALID_TASK_MSG =
_( 'Invalid task name. Task names must start with a lowercase letter' \ 'and can only contain lowercase letters, numbers, and underscores.', )
Constants inherited from BaseValidator
BaseValidator::ALLOW_EMPTY_TARGETS, BaseValidator::INVOKE_STYLE
Class Method Summary collapse
- .create_spinner(targets = [], options = {}) ⇒ Object
- .invoke(report, options = {}) ⇒ Object
- .name ⇒ Object
- .pattern ⇒ Object
- .spinner_text(_targets = []) ⇒ Object
- .stop_spinner(exit_code) ⇒ Object
Methods inherited from BaseValidator
allow_empty_targets?, cmd_path, ignore_pathspec, parse_options, parse_targets, process_invalid, process_skipped
Class Method Details
.create_spinner(targets = [], options = {}) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/pdk/validate/tasks/name.rb', line 28 def self.create_spinner(targets = [], = {}) return unless PDK::CLI::Util.interactive? = .merge(PDK::CLI::Util.spinner_opts_for_platform) exec_group = [:exec_group] @spinner = if exec_group exec_group.add_spinner(spinner_text(targets), ) else TTY::Spinner.new("[:spinner] #{spinner_text(targets)}", ) end @spinner.auto_spin end |
.invoke(report, options = {}) ⇒ Object
49 50 51 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 83 84 |
# File 'lib/pdk/validate/tasks/name.rb', line 49 def self.invoke(report, = {}) targets, skipped, invalid = parse_targets() process_skipped(report, skipped) process_invalid(report, invalid) return 0 if targets.empty? return_val = 0 create_spinner(targets, ) targets.each do |target| task_name = File.basename(target, File.extname(target)) if PDK::CLI::Util::OptionValidator.valid_task_name?(task_name) report.add_event( file: target, source: name, state: :passed, severity: 'ok', ) else report.add_event( file: target, source: name, state: :failure, severity: 'error', message: INVALID_TASK_MSG, ) return_val = 1 end end stop_spinner(return_val) return_val end |
.name ⇒ Object
14 15 16 |
# File 'lib/pdk/validate/tasks/name.rb', line 14 def self.name 'task-name' end |
.pattern ⇒ Object
18 19 20 |
# File 'lib/pdk/validate/tasks/name.rb', line 18 def self.pattern 'tasks/**/*' end |
.spinner_text(_targets = []) ⇒ Object
22 23 24 25 26 |
# File 'lib/pdk/validate/tasks/name.rb', line 22 def self.spinner_text(_targets = []) _('Checking task names (%{targets}).') % { targets: pattern, } end |
.stop_spinner(exit_code) ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/pdk/validate/tasks/name.rb', line 41 def self.stop_spinner(exit_code) if exit_code.zero? && @spinner @spinner.success elsif @spinner @spinner.error end end |