Class: A11y::Lint::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/a11y/lint/configuration.rb

Overview

Loads and stores rule configuration from a YAML file.

Constant Summary collapse

DEFAULT_FILE =
".a11y-lint.yml"

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config_hash = {}) ⇒ Configuration

Returns a new instance of Configuration.



11
12
13
# File 'lib/a11y/lint/configuration.rb', line 11

def initialize(config_hash = {})
  @config = config_hash
end

Class Method Details

.load(path = nil, search_path: Dir.pwd) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/a11y/lint/configuration.rb', line 15

def self.load(path = nil, search_path: Dir.pwd)
  path ||= find_config_file(search_path)
  return new unless path && File.exist?(path)

  config_hash = YAML.safe_load_file(path) || {}
  new(config_hash)
end

Instance Method Details

#enabled?(rule_name) ⇒ Boolean

Returns:

  • (Boolean)


39
40
41
42
43
# File 'lib/a11y/lint/configuration.rb', line 39

def enabled?(rule_name)
  return true unless @config.key?(rule_name)

  @config.dig(rule_name, "Enabled") != false
end