Class: Ace::Bundle::Atoms::SectionValidator

Inherits:
Object
  • Object
show all
Defined in:
lib/ace/bundle/atoms/section_validator.rb

Overview

Validates section definitions and ensures section integrity

Constant Summary collapse

SectionValidationError =
Ace::Bundle::SectionValidationError
REQUIRED_FIELDS =

Required section fields (none - all fields are optional)

[].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSectionValidator

Returns a new instance of SectionValidator.



13
14
15
# File 'lib/ace/bundle/atoms/section_validator.rb', line 13

def initialize
  @errors = []
end

Instance Attribute Details

#errorsArray<String> (readonly)

Returns validation errors

Returns:

  • (Array<String>)

    list of validation errors



33
34
35
# File 'lib/ace/bundle/atoms/section_validator.rb', line 33

def errors
  @errors
end

Instance Method Details

#validate_section(name, section) ⇒ Boolean

Validates a single section

Parameters:

  • name (String)

    section name

  • section (Hash)

    section definition

Returns:

  • (Boolean)

    true if valid, false otherwise



39
40
41
42
43
44
45
46
47
48
# File 'lib/ace/bundle/atoms/section_validator.rb', line 39

def validate_section(name, section)
  @errors.clear
  return true if section.nil? || section.empty?

  validate_section_name(name)
  validate_required_fields_for_section(name, section)
  validate_content_for_section(name, section)

  @errors.empty?
end

#validate_sections(sections) ⇒ Boolean

Validates section definitions from configuration

Parameters:

  • sections (Hash)

    section definitions hash

Returns:

  • (Boolean)

    true if valid, false otherwise



20
21
22
23
24
25
26
27
28
29
# File 'lib/ace/bundle/atoms/section_validator.rb', line 20

def validate_sections(sections)
  @errors.clear
  return true if sections.nil? || sections.empty?

  validate_section_names(sections)
  validate_required_fields(sections)
  validate_section_content(sections)

  @errors.empty?
end