Class: Audition::Config
- Inherits:
-
Object
- Object
- Audition::Config
- 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
test_dirs:
- qa
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: [], test_dirs: nil} )
- FAIL_ON_LEVELS =
%w[error warning info never].freeze
Instance Attribute Summary collapse
-
#disabled_checks ⇒ Object
readonly
Returns the value of attribute disabled_checks.
-
#exclude ⇒ Object
readonly
Returns the value of attribute exclude.
-
#fail_on ⇒ Object
readonly
Returns the value of attribute fail_on.
-
#timeout ⇒ Object
readonly
Returns the value of attribute timeout.
Class Method Summary collapse
-
.load(root) ⇒ Config
Empty config when the file is absent.
Instance Method Summary collapse
- #check_disabled?(check) ⇒ Boolean
-
#excluded?(relative_path) ⇒ Boolean
Globs follow .gitignore-style expectations:
*stays within one directory level,dir/**covers the whole subtree, and a leading./is tolerated. -
#initialize(fail_on:, timeout:, exclude:, disabled_checks:, test_dirs: nil) ⇒ Config
constructor
A new instance of Config.
-
#test_dirs ⇒ Array<String>
Directories whose findings are tagged as test code rather than code a production boot loads.
Constructor Details
#initialize(fail_on:, timeout:, exclude:, disabled_checks:, test_dirs: nil) ⇒ Config
Returns a new instance of Config.
82 83 84 85 86 87 88 89 |
# File 'lib/audition/config.rb', line 82 def initialize(fail_on:, timeout:, exclude:, disabled_checks:, test_dirs: nil) @fail_on = fail_on @timeout = timeout @exclude = exclude @disabled_checks = disabled_checks @test_dirs = test_dirs end |
Instance Attribute Details
#disabled_checks ⇒ Object (readonly)
Returns the value of attribute disabled_checks.
30 31 32 |
# File 'lib/audition/config.rb', line 30 def disabled_checks @disabled_checks end |
#exclude ⇒ Object (readonly)
Returns the value of attribute exclude.
30 31 32 |
# File 'lib/audition/config.rb', line 30 def exclude @exclude end |
#fail_on ⇒ Object (readonly)
Returns the value of attribute fail_on.
30 31 32 |
# File 'lib/audition/config.rb', line 30 def fail_on @fail_on end |
#timeout ⇒ Object (readonly)
Returns the value of attribute timeout.
30 31 32 |
# File 'lib/audition/config.rb', line 30 def timeout @timeout end |
Class Method Details
.load(root) ⇒ Config
Returns empty config when the file is absent.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/audition/config.rb', line 36 def self.load(root) path = File.join(root.to_s, FILE) return new(**EMPTY) unless File.file?(path) data = YAML.safe_load_file(path) || {} validate!(path, data) 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), test_dirs: data["test_dirs"]&.map(&:to_s) ) rescue Psych::Exception => e raise Error, "#{path}: #{e.}" end |
Instance Method Details
#check_disabled?(check) ⇒ Boolean
114 115 116 |
# File 'lib/audition/config.rb', line 114 def check_disabled?(check) disabled_checks.include?(check) end |
#excluded?(relative_path) ⇒ Boolean
Globs follow .gitignore-style expectations: * stays within
one directory level, dir/** covers the whole subtree, and a
leading ./ is tolerated.
103 104 105 106 107 108 109 110 111 112 |
# File 'lib/audition/config.rb', line 103 def excluded?(relative_path) exclude.any? do |raw| pattern = raw.delete_prefix("./") next true if File.fnmatch?(pattern, relative_path, File::FNM_PATHNAME | File::FNM_EXTGLOB) prefix = pattern[%r{\A(.+?)/\*\*(?:/\*+)?\z}, 1] prefix && relative_path.start_with?("#{prefix}/") end end |