class RailInspector::Configuring::Check::GeneralConfiguration

Attributes

Public Class Methods

# File tools/rail_inspector/lib/rail_inspector/configuring/check/general_configuration.rb, line 30
def initialize(checker, expected_accessors: AccessorParser.new(checker).call)
  @checker = checker
  @expected_accessors = expected_accessors
end

Public Instance Methods

# File tools/rail_inspector/lib/rail_inspector/configuring/check/general_configuration.rb, line 35
def check
  header, *config_sections = documented_general_config

  non_nested_accessors =
    expected_accessors.reject do |a|
      config_sections.any? { |section| /\.#{a}\./.match?(section[0]) }
    end

  non_nested_accessors.each do |accessor|
    config_header = "#### `config.#{accessor}`"

    unless config_sections.any? { |section| section[0] == config_header }
      checker.errors << "Missing configuration: #{config_header}"
      config_sections << [config_header, "", "FIXME", ""]
    end
  end

  new_config = header + config_sections.sort_by { |section| section[0].split("`")[1] }.flatten

  return if new_config == checker.doc.general_config

  checker.errors << "General Configuration is not alphabetical"

  checker.doc.general_config = new_config
end