Class: DoctorService

Inherits:
Object
  • Object
show all
Defined in:
lib/core/doctor_service.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ DoctorService

Returns a new instance of DoctorService.



8
9
10
# File 'lib/core/doctor_service.rb', line 8

def initialize(config)
  @config = config
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



6
7
8
# File 'lib/core/doctor_service.rb', line 6

def config
  @config
end

Instance Method Details

#run_validations(validations, silent_if_passing: false) ⇒ Object

rubocop:disable Metrics/MethodLength



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/core/doctor_service.rb', line 12

def run_validations(validations, silent_if_passing: false) # rubocop:disable Metrics/MethodLength
  @any_failed_validation = false

  validations.each do |validation|
    case validation
    when "config"
      validate_config
    when "templates"
      validate_templates
    else
      raise ValidationError, Shell.color("ERROR: Invalid validation '#{validation}'.", :red)
    end

    progress.puts("#{Shell.color('[PASS]', :green)} #{validation}") unless silent_if_passing
  rescue ValidationError => e
    @any_failed_validation = true

    progress.puts("#{Shell.color('[FAIL]', :red)} #{validation}\n\n#{e.message}\n\n")
  end

  exit(ExitCode::ERROR_DEFAULT) if @any_failed_validation
end

#validate_configObject



35
36
37
# File 'lib/core/doctor_service.rb', line 35

def validate_config
  check_for_app_names_contained_in_others
end

#validate_templatesObject



39
40
41
42
43
44
45
46
# File 'lib/core/doctor_service.rb', line 39

def validate_templates
  @template_parser = TemplateParser.new(config)
  filenames = Dir.glob("#{@template_parser.template_dir}/*.yml")
  templates = @template_parser.parse(filenames)

  check_for_duplicate_templates(templates)
  warn_deprecated_template_variables
end