Class: PDK::Validate::Tasks::TasksNameValidator

Inherits:
InternalRubyValidator show all
Defined in:
lib/pdk/validate/tasks/tasks_name_validator.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.'.freeze

Instance Attribute Summary

Attributes inherited from Validator

#context, #options, #prepared

Instance Method Summary collapse

Methods inherited from InternalRubyValidator

#before_validation, #invoke, #prepare_invoke!

Methods inherited from InvokableValidator

#allow_empty_targets?, #fnmatch?, #ignore_dotfiles?, #invoke_style, #parse_targets, #pattern_ignore, #prepare_invoke!, #process_invalid, #process_skipped, #spinner, #valid_in_context?

Methods inherited from Validator

#initialize, #invoke, #prepare_invoke!, #spinner, #spinners_enabled?, #start_spinner, #stop_spinner, #valid_in_context?

Constructor Details

This class inherits a constructor from PDK::Validate::Validator

Instance Method Details

#nameObject



9
10
11
# File 'lib/pdk/validate/tasks/tasks_name_validator.rb', line 9

def name
  'task-name'
end

#patternObject



13
14
15
# File 'lib/pdk/validate/tasks/tasks_name_validator.rb', line 13

def pattern
  contextual_pattern('tasks/**/*')
end

#spinner_textObject



17
18
19
# File 'lib/pdk/validate/tasks/tasks_name_validator.rb', line 17

def spinner_text
  format('Checking task names (%{pattern}).', pattern: pattern.join(' '))
end

#validate_target(report, target) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/pdk/validate/tasks/tasks_name_validator.rb', line 21

def validate_target(report, 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'
    )
    0
  else
    report.add_event(
      file: target,
      source: name,
      state: :failure,
      severity: 'error',
      message: INVALID_TASK_MSG
    )
    1
  end
end