Class: Cyclid::Linter::Verifier

Inherits:
Object
  • Object
show all
Defined in:
lib/cyclid/linter.rb

Overview

Verify (lint) a Job for obvious errors and potential problems

Defined Under Namespace

Modules: Bertrand

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*_args) ⇒ Verifier

Returns a new instance of Verifier.



59
60
61
# File 'lib/cyclid/linter.rb', line 59

def initialize(*_args)
  @status = StatusLogger.new
end

Instance Attribute Details

#statusObject (readonly)

Returns the value of attribute status.



57
58
59
# File 'lib/cyclid/linter.rb', line 57

def status
  @status
end

Instance Method Details

#verify(definition) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/cyclid/linter.rb', line 63

def verify(definition)
  job = definition.deep_symbolize_keys

  # Does the data even look like a job?
  @status.error 'Job is not a hash?' \
    unless job.is_a? Hash

  @status.error 'Job is empty?' \
    if job.empty?

  # Lint all of the obvious, top-level stuff that makes up a basic job
  @status.error 'The Job does not have a name.' \
    unless job.key? :name

  @status.warning 'No version is defined for the Job. The default of 1.0.0 will be used.' \
    unless job.key? :version

  @status.warning 'No environment is defined. Defaults will apply.' \
    unless job.key? :environment

  @status.error 'No sequence is defined.' \
    unless job.key? :sequence

  # If any Stages are defined, check that each one looks valid
  verify_stages(job[:stages]) if job.key? :stages

  # Verify that the Sequence is valid, as much as possible
  verify_sequence(job[:sequence]) if job.key? :sequence
rescue StandardError => ex
  @status.error "An unexpected error occured during the verification: #{ex}"
end