Class: CodeQualia::ConfigHelper
- Inherits:
-
Object
- Object
- CodeQualia::ConfigHelper
- Defined in:
- lib/code_qualia/config_helper.rb
Class Method Summary collapse
-
.get_target_patterns ⇒ Array<String>
Gets target file patterns from configuration and expands them to glob patterns.
-
.load_config ⇒ CodeQualia::Config
Loads the Code Qualia configuration from file or returns default configuration.
-
.normalize_file_path(file_path) ⇒ String
Normalizes a file path to a relative path from the current working directory.
-
.should_include_file?(file_path, target_patterns) ⇒ Boolean
Checks if a file should be included based on target patterns.
Class Method Details
.get_target_patterns ⇒ Array<String>
Gets target file patterns from configuration and expands them to glob patterns.
This method reads the architectural_weights configuration, expands any brace patterns (e.g., ‘app/models,controllers/*/.rb’), and converts directory patterns to file patterns by appending ‘*/.rb’ when necessary.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/code_qualia/config_helper.rb', line 20 def get_target_patterns config = load_config patterns = config.architectural_weights.map { |entry| entry['path'] } # Expand brace patterns and convert to file patterns if they're directory patterns = [] patterns.each do |pattern| if pattern.include?('{') && pattern.include?('}') = PatternExpander.(pattern) .concat() else << pattern end end # Convert directory patterns to file patterns .map do |pattern| if pattern.end_with?('/') "#{pattern}**/*.rb" elsif pattern.end_with?('/**/*') "#{pattern}.rb" elsif !pattern.include?('*') # Assume it's a directory "#{pattern}/**/*.rb" else pattern end end end |
.load_config ⇒ CodeQualia::Config
Loads the Code Qualia configuration from file or returns default configuration.
This method attempts to load the configuration from the default config file (qualia.yml). If the file doesn’t exist, it returns a new Config instance with default values.
111 112 113 114 115 116 117 |
# File 'lib/code_qualia/config_helper.rb', line 111 def load_config if File.exist?(DEFAULT_CONFIG_FILE) Config.load(DEFAULT_CONFIG_FILE) else Config.new end end |
.normalize_file_path(file_path) ⇒ String
Normalizes a file path to a relative path from the current working directory.
This method takes an absolute file path and converts it to a relative path from the current working directory. This preserves the full directory structure including any intermediate directories like ‘packs/users/’.
85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/code_qualia/config_helper.rb', line 85 def normalize_file_path(file_path) # If already a relative path, return as-is return file_path unless Pathname.new(file_path).absolute? # Convert absolute path to relative path from current working directory current_dir = Dir.pwd if file_path.start_with?(current_dir) relative_path = file_path[(current_dir.length + 1)..-1] return relative_path || file_path end # If it doesn't start with current directory, return as-is file_path end |
.should_include_file?(file_path, target_patterns) ⇒ Boolean
Checks if a file should be included based on target patterns.
This method determines whether a given file path matches any of the provided target patterns. Only Ruby files (.rb extension) are considered for inclusion.
64 65 66 67 68 69 70 |
# File 'lib/code_qualia/config_helper.rb', line 64 def should_include_file?(file_path, target_patterns) return false unless file_path.end_with?('.rb') target_patterns.any? do |pattern| File.fnmatch(pattern, file_path, File::FNM_PATHNAME) end end |