Class: CovLoupe::AppConfig

Inherits:
Struct
  • Object
show all
Defined in:
lib/cov_loupe/config/app_config.rb

Overview

Configuration container for application options.

Populated by ConfigParser from CLI arguments or constructed directly for MCP mode. Provides convenience methods (model_options, formatter_options) that extract the relevant subset of config for initializing CoverageModel and SourceFormatter.

Mutable by design: callers may adjust fields during setup before handing the config object off to CLI or MCP entry points.

All enum values are stored as symbols (:table, :json, :descending, etc.) for consistent comparison throughout the codebase.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root: '.', resultset: nil, format: :table, sort_order: :descending, source_mode: nil, source_context: 2, color: $stdout.tty?, error_mode: :log, raise_on_stale: false, tracked_globs: nil, log_file: nil, mode: :cli, output_chars: :default) ⇒ AppConfig

Set sensible defaults - ALL SYMBOLS FOR ENUMS



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/cov_loupe/config/app_config.rb', line 33

def initialize(
  root: '.',
  resultset: nil,
  format: :table,
  sort_order: :descending,
  source_mode: nil,
  source_context: 2,
  color: $stdout.tty?,
  error_mode: :log,
  raise_on_stale: false,
  tracked_globs: nil,
  log_file: nil,
  mode: :cli,
  output_chars: :default
)
  # Default to empty array (show all files in resultset and don't look for files lacking coverage data)
  # Users should set COV_LOUPE_OPTS to match SimpleCov track_files patterns
  tracked_globs = [] if tracked_globs.nil?
  super
end

Instance Attribute Details

#colorObject

Returns the value of attribute color

Returns:

  • (Object)

    the current value of color



17
18
19
# File 'lib/cov_loupe/config/app_config.rb', line 17

def color
  @color
end

#error_modeObject

Returns the value of attribute error_mode

Returns:

  • (Object)

    the current value of error_mode



17
18
19
# File 'lib/cov_loupe/config/app_config.rb', line 17

def error_mode
  @error_mode
end

#formatObject

Returns the value of attribute format

Returns:

  • (Object)

    the current value of format



17
18
19
# File 'lib/cov_loupe/config/app_config.rb', line 17

def format
  @format
end

#log_fileObject

Returns the value of attribute log_file

Returns:

  • (Object)

    the current value of log_file



17
18
19
# File 'lib/cov_loupe/config/app_config.rb', line 17

def log_file
  @log_file
end

#modeObject

Returns the value of attribute mode

Returns:

  • (Object)

    the current value of mode



17
18
19
# File 'lib/cov_loupe/config/app_config.rb', line 17

def mode
  @mode
end

#output_charsObject

Returns the value of attribute output_chars

Returns:

  • (Object)

    the current value of output_chars



17
18
19
# File 'lib/cov_loupe/config/app_config.rb', line 17

def output_chars
  @output_chars
end

#raise_on_staleObject

Returns the value of attribute raise_on_stale

Returns:

  • (Object)

    the current value of raise_on_stale



17
18
19
# File 'lib/cov_loupe/config/app_config.rb', line 17

def raise_on_stale
  @raise_on_stale
end

#resultsetObject

Returns the value of attribute resultset

Returns:

  • (Object)

    the current value of resultset



17
18
19
# File 'lib/cov_loupe/config/app_config.rb', line 17

def resultset
  @resultset
end

#rootObject

Returns the value of attribute root

Returns:

  • (Object)

    the current value of root



17
18
19
# File 'lib/cov_loupe/config/app_config.rb', line 17

def root
  @root
end

#sort_orderObject

Returns the value of attribute sort_order

Returns:

  • (Object)

    the current value of sort_order



17
18
19
# File 'lib/cov_loupe/config/app_config.rb', line 17

def sort_order
  @sort_order
end

#source_contextObject

Returns the value of attribute source_context

Returns:

  • (Object)

    the current value of source_context



17
18
19
# File 'lib/cov_loupe/config/app_config.rb', line 17

def source_context
  @source_context
end

#source_modeObject

Returns the value of attribute source_mode

Returns:

  • (Object)

    the current value of source_mode



17
18
19
# File 'lib/cov_loupe/config/app_config.rb', line 17

def source_mode
  @source_mode
end

#tracked_globsObject

Returns the value of attribute tracked_globs

Returns:

  • (Object)

    the current value of tracked_globs



17
18
19
# File 'lib/cov_loupe/config/app_config.rb', line 17

def tracked_globs
  @tracked_globs
end

Class Method Details

.validate_log_file!(value) ⇒ Object

Shared validation for any log target value.

Raises:



80
81
82
83
84
85
86
# File 'lib/cov_loupe/config/app_config.rb', line 80

def self.validate_log_file!(value)
  return unless value.to_s.strip.downcase == 'stdout'

  raise ConfigurationError,
    'Logging to stdout is not permitted because it corrupts command output. ' \
    "Use 'stderr', a file path, or ':off' to disable logging."
end

Instance Method Details

#formatter_optionsObject

Convenience method for SourceFormatter initialization



65
66
67
68
69
70
# File 'lib/cov_loupe/config/app_config.rb', line 65

def formatter_options
  {
    color_enabled: color,
    output_chars:  output_chars,
  }
end

#model_optionsObject

Convenience method for CoverageModel initialization



55
56
57
58
59
60
61
62
# File 'lib/cov_loupe/config/app_config.rb', line 55

def model_options
  {
    root:           root,
    resultset:      resultset,
    raise_on_stale: raise_on_stale,
    tracked_globs:  tracked_globs,
  }
end

#validate!Object

Validate configuration after all options have been merged. Raises ConfigurationError for values that are unconditionally invalid.



74
75
76
77
# File 'lib/cov_loupe/config/app_config.rb', line 74

def validate!
  self.class.validate_log_file!(log_file)
  self
end