Class: Ace::Core::Molecules::FileAggregator
- Inherits:
-
Object
- Object
- Ace::Core::Molecules::FileAggregator
- Defined in:
- lib/ace/core/molecules/file_aggregator.rb
Overview
Aggregates file contents from multiple sources using atoms
Instance Method Summary collapse
-
#aggregate(patterns) ⇒ Hash
Aggregate files from patterns.
-
#aggregate_files(file_paths) ⇒ Hash
Aggregate specific files (no pattern expansion).
-
#find_and_aggregate(pattern, max_depth: nil) ⇒ Hash
Find and aggregate files by name pattern.
-
#initialize(options = {}) ⇒ FileAggregator
constructor
A new instance of FileAggregator.
Constructor Details
#initialize(options = {}) ⇒ FileAggregator
Returns a new instance of FileAggregator.
12 13 14 15 16 |
# File 'lib/ace/core/molecules/file_aggregator.rb', line 12 def initialize( = {}) @max_size = [:max_size] || Atoms::FileReader::MAX_FILE_SIZE @base_dir = [:base_dir] || Ace::Support::Fs::Molecules::ProjectRootFinder.find_or_current @exclude_patterns = [:exclude] || [] end |
Instance Method Details
#aggregate(patterns) ⇒ Hash
Aggregate files from patterns
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 49 50 51 52 |
# File 'lib/ace/core/molecules/file_aggregator.rb', line 21 def aggregate(patterns) result = { files: [], errors: [], stats: { total_size: 0, file_count: 0, error_count: 0, skipped_count: 0 } } patterns = Array(patterns).compact return result if patterns.empty? # Expand all patterns all_files = (patterns) # Apply exclusions filtered_files = filter_exclusions(all_files) # Track skipped files skipped_count = all_files.size - filtered_files.size result[:stats][:skipped_count] = skipped_count # Read each file filtered_files.each do |file_path| process_file(file_path, result) end result end |
#aggregate_files(file_paths) ⇒ Hash
Aggregate specific files (no pattern expansion)
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/ace/core/molecules/file_aggregator.rb', line 57 def aggregate_files(file_paths) result = { files: [], errors: [], stats: { total_size: 0, file_count: 0, error_count: 0, skipped_count: 0 } } file_paths = Array(file_paths).compact return result if file_paths.empty? file_paths.each do |file_path| # Apply exclusions even to direct paths if excluded?(file_path) result[:stats][:skipped_count] += 1 next end process_file(file_path, result) end result end |
#find_and_aggregate(pattern, max_depth: nil) ⇒ Hash
Find and aggregate files by name pattern
89 90 91 92 93 94 95 96 97 |
# File 'lib/ace/core/molecules/file_aggregator.rb', line 89 def find_and_aggregate(pattern, max_depth: nil) files = Atoms::GlobExpander.find_files( pattern, base_dir: @base_dir, max_depth: max_depth ) aggregate_files(files) end |