Class: CleoQualityReview::Configuration

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

Overview

Configuration for file include/exclude patterns and runtime defaults

Defined Under Namespace

Classes: Loader

Constant Summary collapse

DEFAULT_CONFIG_PATH =
File.expand_path("../../config/default.yml", __dir__)
LOCAL_CONFIG_PATH =
".cleo_quality_review.yaml"
ALL_TOOLS =
"AllTools"
INCLUDE =
"Include"
EXCLUDE =
"Exclude"
INHERIT_FROM =
"inherit_from"
GEM_DEFAULT_ALIASES =
["default", "gem:default"].freeze
MATCH_FLAGS =
File::FNM_PATHNAME | File::FNM_EXTGLOB

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Configuration

Returns a new instance of Configuration.

Parameters:

  • data (Hash)

    parsed configuration data



60
61
62
# File 'lib/cleo_quality_review/configuration.rb', line 60

def initialize(data)
  @data = data
end

Class Method Details

.default_max_concurrencyInteger

Returns host processor count used as the default worker cap.

Returns:

  • (Integer)

    host processor count used as the default worker cap



54
55
56
# File 'lib/cleo_quality_review/configuration.rb', line 54

def self.default_max_concurrency
  Etc.nprocessors
end

.env_max_concurrencyInteger?

Read the max worker count from the environment, if configured.

Returns:

  • (Integer, nil)

    the configured count, or nil when unset/blank

Raises:

  • (ArgumentError)

    if the environment value is not an integer



47
48
49
50
# File 'lib/cleo_quality_review/configuration.rb', line 47

def self.env_max_concurrency
  value = ENV["CLEO_QUALITY_REVIEW_MAX_CONCURRENCY"]
  value && !value.strip.empty? ? Integer(value) : nil
end

.load(root: Dir.pwd) ⇒ Configuration

Load configuration from default and local config files

Parameters:

  • root (String) (defaults to: Dir.pwd)

    root directory for local config lookup

Returns:



24
25
26
# File 'lib/cleo_quality_review/configuration.rb', line 24

def self.load(root: Dir.pwd)
  Loader.new(root: root).load
end

.max_concurrencyInteger

Resolve the configured worker count for concurrent checks.

Returns:

  • (Integer)

    resolved worker count (at least 1)



31
32
33
# File 'lib/cleo_quality_review/configuration.rb', line 31

def self.max_concurrency
  max_concurrency_limit(env_max_concurrency || default_max_concurrency)
end

.max_concurrency_limit(value) ⇒ Integer

Clamp a worker count to a usable lower bound.

Parameters:

  • value (Integer)

    worker count to clamp

Returns:

  • (Integer)

    clamped worker count



39
40
41
# File 'lib/cleo_quality_review/configuration.rb', line 39

def self.max_concurrency_limit(value)
  [value.to_i, 1].max
end

Instance Method Details

#exclude_patternsArray<String>

Returns glob patterns for files to exclude.

Returns:

  • (Array<String>)

    glob patterns for files to exclude



72
73
74
# File 'lib/cleo_quality_review/configuration.rb', line 72

def exclude_patterns
  patterns_for(EXCLUDE)
end

#include_patternsArray<String>

Returns glob patterns for files to include.

Returns:

  • (Array<String>)

    glob patterns for files to include



66
67
68
# File 'lib/cleo_quality_review/configuration.rb', line 66

def include_patterns
  patterns_for(INCLUDE)
end

#target_file?(path) ⇒ Boolean

Check if a file should be included based on configuration patterns

Parameters:

  • path (String)

    file path to check

Returns:

  • (Boolean)


80
81
82
83
84
# File 'lib/cleo_quality_review/configuration.rb', line 80

def target_file?(path)
  normalized_path = normalize_path(path)

  matches_any?(include_patterns, normalized_path) && !matches_any?(exclude_patterns, normalized_path)
end