Class: CodeQualia::Config

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data = {}) ⇒ Config

Returns a new instance of Config.



9
10
11
12
13
14
15
# File 'lib/code_qualia/config.rb', line 9

def initialize(data = {})
  @quality_weights = data['quality_weights'] || default_quality_weights
  @importance_weights = data['importance_weights'] || default_importance_weights
  @architectural_weights = expand_architectural_weights(data['architectural_weights'] || default_architectural_weights)
  @exclude_patterns = data['exclude'] || default_exclude_patterns
  @git_history_days = data['git_history_days'] || 90
end

Instance Attribute Details

#architectural_weightsObject (readonly)

Returns the value of attribute architectural_weights.



7
8
9
# File 'lib/code_qualia/config.rb', line 7

def architectural_weights
  @architectural_weights
end

#exclude_patternsObject (readonly)

Returns the value of attribute exclude_patterns.



7
8
9
# File 'lib/code_qualia/config.rb', line 7

def exclude_patterns
  @exclude_patterns
end

#git_history_daysObject (readonly)

Returns the value of attribute git_history_days.



7
8
9
# File 'lib/code_qualia/config.rb', line 7

def git_history_days
  @git_history_days
end

#importance_weightsObject (readonly)

Returns the value of attribute importance_weights.



7
8
9
# File 'lib/code_qualia/config.rb', line 7

def importance_weights
  @importance_weights
end

#quality_weightsObject (readonly)

Returns the value of attribute quality_weights.



7
8
9
# File 'lib/code_qualia/config.rb', line 7

def quality_weights
  @quality_weights
end

Class Method Details

.load(file_path) ⇒ Object



17
18
19
20
21
22
23
24
# File 'lib/code_qualia/config.rb', line 17

def self.load(file_path)
  return new unless File.exist?(file_path)

  data = YAML.load_file(file_path)
  new(data)
rescue StandardError => e
  raise Error, "Failed to load config file: #{e.message}"
end

Instance Method Details

#architectural_weight_for(file_path) ⇒ Object



26
27
28
29
30
31
# File 'lib/code_qualia/config.rb', line 26

def architectural_weight_for(file_path)
  @architectural_weights.each do |entry|
    return entry['weight'] if File.fnmatch(entry['path'], file_path, File::FNM_PATHNAME)
  end
  1.0
end

#excluded?(file_path) ⇒ Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/code_qualia/config.rb', line 33

def excluded?(file_path)
  @exclude_patterns.any? { |pattern| File.fnmatch(pattern, file_path, File::FNM_PATHNAME) }
end