Class: Roast::Workflow::Validator

Inherits:
Object
  • Object
show all
Defined in:
lib/roast/workflow/validator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(yaml_content) ⇒ Validator

Returns a new instance of Validator.



12
13
14
15
16
17
# File 'lib/roast/workflow/validator.rb', line 12

def initialize(yaml_content)
  @yaml_content = yaml_content&.strip || ""
  @errors = []

  @parsed_yaml = @yaml_content.empty? ? {} : YAML.safe_load(@yaml_content)
end

Instance Attribute Details

#errorsObject (readonly)

Returns the value of attribute errors.



10
11
12
# File 'lib/roast/workflow/validator.rb', line 10

def errors
  @errors
end

Instance Method Details

#valid?Boolean

Returns:

  • (Boolean)


19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/roast/workflow/validator.rb', line 19

def valid?
  return false if @parsed_yaml.empty?

  schema_path = File.join(Roast::ROOT, "schema/workflow.json")
  schema = JSON.parse(File.read(schema_path))

  begin
    @errors = JSON::Validator.fully_validate(
      schema,
      @parsed_yaml,
      validate_schema: false,
    )

    @errors.empty?
  end
end