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
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
-
#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
-
#initialize(fail_on:, timeout:, exclude:, disabled_checks:) ⇒ Config
constructor
A new instance of Config.
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_checks ⇒ Object (readonly)
Returns the value of attribute disabled_checks.
26 27 28 |
# File 'lib/audition/config.rb', line 26 def disabled_checks @disabled_checks end |
#exclude ⇒ Object (readonly)
Returns the value of attribute exclude.
26 27 28 |
# File 'lib/audition/config.rb', line 26 def exclude @exclude end |
#fail_on ⇒ Object (readonly)
Returns the value of attribute fail_on.
26 27 28 |
# File 'lib/audition/config.rb', line 26 def fail_on @fail_on end |
#timeout ⇒ Object (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.
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.}" end |
Instance Method Details
#check_disabled?(check) ⇒ Boolean
63 64 65 |
# File 'lib/audition/config.rb', line 63 def check_disabled?(check) disabled_checks.include?(check) end |
#excluded?(relative_path) ⇒ 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 |