Class: Qyu::Concerns::WorkflowDescriptorValidator

Inherits:
Object
  • Object
show all
Defined in:
lib/qyu/models/concerns/workflow_descriptor_validator.rb

Overview

Qyu::Concerns::WorkflowDescriptorValidator

Constant Summary collapse

ALLOWED_KEYS =
%w(queue waits_for starts starts_manually starts_with_params).freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(descriptor) ⇒ WorkflowDescriptorValidator

Returns a new instance of WorkflowDescriptorValidator.



10
11
12
13
# File 'lib/qyu/models/concerns/workflow_descriptor_validator.rb', line 10

def initialize(descriptor)
  @descriptor = descriptor
  @errors = []
end

Instance Attribute Details

#errorsObject (readonly)

Returns the value of attribute errors.



8
9
10
# File 'lib/qyu/models/concerns/workflow_descriptor_validator.rb', line 8

def errors
  @errors
end

Instance Method Details

#valid?Boolean

Returns:

  • (Boolean)


15
16
17
18
# File 'lib/qyu/models/concerns/workflow_descriptor_validator.rb', line 15

def valid?
  validate
  @errors.empty?
end

#validateObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/qyu/models/concerns/workflow_descriptor_validator.rb', line 20

def validate
  @errors << 'Descriptor type must be a Hash.' unless validate_descriptor_type
  @errors << 'Entry points (starts) must be an Array.' unless validate_entry_points_type
  @errors << 'Tasks must be a Hash.' unless validate_tasks_type
  unless validate_entry_points_presence
    @errors << 'There must be at least 1 entry point, and all entry points must exist in the tasks Hash.'
  end
  @errors << 'There must be at least 1 task in the tasks Hash.' unless validate_tasks_presence

  tasks.keys.each do |task_name|
    unless validate_queue_presence(task_name)
      @errors << "#{task_name} must have a valid queue."
    end
    unless validate_task_keys(task_name)
      @errors << "#{task_name} must only contain the following keys: #{ALLOWED_KEYS}."
    end
    unless validate_task_reference_formats(task_name)
      @errors << "#{task_name} must follow the reference declaration format."
    end
    unless validate_task_references(task_name)
      @errors << "#{task_name} must list existing tasks in its references."
    end
    unless validate_sync_condition_params(task_name)
      @errors << "#{task_name} must pass the correct parameters to the sync task."
    end
  end
rescue => ex
  Qyu.logger.error "Error while validation: #{ex.class}: #{ex.message}"
  Qyu.logger.error "Backtrace: #{ex.backtrace.join("\n")}"
  @errors << "#{ex.class}: #{ex.message}"
end