Class: Audition::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/audition/config.rb

Overview

Project configuration from .audition.yml at the target root:

fail_on: warning
timeout: 60
exclude:
- legacy/**
- db/schema.rb
checks:
disable:
  - at-exit

CLI flags always win over config values.

Constant Summary collapse

FILE =
".audition.yml"
EMPTY =
Ractor.make_shareable(
  {fail_on: nil, timeout: nil, exclude: [],
   disabled_checks: []}
)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(fail_on:, timeout:, exclude:, disabled_checks:) ⇒ Config

Returns a new instance of Config.



47
48
49
50
51
52
# File 'lib/audition/config.rb', line 47

def initialize(fail_on:, timeout:, exclude:, disabled_checks:)
  @fail_on = fail_on
  @timeout = timeout
  @exclude = exclude
  @disabled_checks = disabled_checks
end

Instance Attribute Details

#disabled_checksObject (readonly)

Returns the value of attribute disabled_checks.



26
27
28
# File 'lib/audition/config.rb', line 26

def disabled_checks
  @disabled_checks
end

#excludeObject (readonly)

Returns the value of attribute exclude.



26
27
28
# File 'lib/audition/config.rb', line 26

def exclude
  @exclude
end

#fail_onObject (readonly)

Returns the value of attribute fail_on.



26
27
28
# File 'lib/audition/config.rb', line 26

def fail_on
  @fail_on
end

#timeoutObject (readonly)

Returns the value of attribute timeout.



26
27
28
# File 'lib/audition/config.rb', line 26

def timeout
  @timeout
end

Class Method Details

.load(root) ⇒ Config

Returns empty config when the file is absent.

Parameters:

  • root (String)

    directory that may contain .audition.yml

Returns:

  • (Config)

    empty config when the file is absent

Raises:



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/audition/config.rb', line 31

def self.load(root)
  path = File.join(root.to_s, FILE)
  return new(**EMPTY) unless File.file?(path)

  data = YAML.safe_load_file(path) || {}
  new(
    fail_on: data["fail_on"]&.to_sym,
    timeout: data["timeout"],
    exclude: Array(data["exclude"]).map(&:to_s),
    disabled_checks:
      Array(data.dig("checks", "disable")).map(&:to_s)
  )
rescue Psych::Exception => e
  raise Error, "#{path}: #{e.message}"
end

Instance Method Details

#check_disabled?(check) ⇒ Boolean

Returns:

  • (Boolean)


63
64
65
# File 'lib/audition/config.rb', line 63

def check_disabled?(check)
  disabled_checks.include?(check)
end

#excluded?(relative_path) ⇒ Boolean

Returns:

  • (Boolean)


54
55
56
57
58
59
60
61
# File 'lib/audition/config.rb', line 54

def excluded?(relative_path)
  exclude.any? do |pattern|
    next true if File.fnmatch?(pattern, relative_path)

    prefix = pattern[%r{\A(.+?)/\*\*(?:/\*+)?\z}, 1]
    prefix && relative_path.start_with?("#{prefix}/")
  end
end