Class: Workbush::FileCopier
- Inherits:
-
Object
- Object
- Workbush::FileCopier
- Defined in:
- lib/workbush/file_copier.rb
Overview
Handles copying files from source worktree to destination worktree
Instance Attribute Summary collapse
-
#dest_path ⇒ Object
readonly
Returns the value of attribute dest_path.
-
#source_path ⇒ Object
readonly
Returns the value of attribute source_path.
-
#verbose ⇒ Object
readonly
Returns the value of attribute verbose.
Instance Method Summary collapse
-
#copy_directories(directories) ⇒ Object
Copy entire directories.
-
#copy_exact_files(files) ⇒ Object
Copy specific files by exact path.
-
#copy_from_config(config) ⇒ Hash
Copy files based on configuration.
-
#copy_matching_patterns(patterns) ⇒ Object
Copy files matching glob patterns.
-
#initialize(source_path:, dest_path:, verbose: false) ⇒ FileCopier
constructor
Initialize a new FileCopier instance.
Constructor Details
#initialize(source_path:, dest_path:, verbose: false) ⇒ FileCopier
Initialize a new FileCopier instance
16 17 18 19 20 21 22 23 |
# File 'lib/workbush/file_copier.rb', line 16 def initialize(source_path:, dest_path:, verbose: false) @source_path = File.(source_path) @dest_path = File.(dest_path) @verbose = verbose @copied_count = 0 @skipped_count = 0 @failed_count = 0 end |
Instance Attribute Details
#dest_path ⇒ Object (readonly)
Returns the value of attribute dest_path.
9 10 11 |
# File 'lib/workbush/file_copier.rb', line 9 def dest_path @dest_path end |
#source_path ⇒ Object (readonly)
Returns the value of attribute source_path.
9 10 11 |
# File 'lib/workbush/file_copier.rb', line 9 def source_path @source_path end |
#verbose ⇒ Object (readonly)
Returns the value of attribute verbose.
9 10 11 |
# File 'lib/workbush/file_copier.rb', line 9 def verbose @verbose end |
Instance Method Details
#copy_directories(directories) ⇒ Object
Copy entire directories
88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/workbush/file_copier.rb', line 88 def copy_directories(directories) return if directories.empty? log "Copying directories..." directories.each do |dir| source = File.join(@source_path, dir) dest = File.join(@dest_path, dir) copy_single_item(source, dest, dir) end end |
#copy_exact_files(files) ⇒ Object
Copy specific files by exact path
48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/workbush/file_copier.rb', line 48 def copy_exact_files(files) return if files.empty? log "Copying exact files..." files.each do |file| source = File.join(@source_path, file) dest = File.join(@dest_path, file) copy_single_item(source, dest, file) end end |
#copy_from_config(config) ⇒ Hash
Copy files based on configuration
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/workbush/file_copier.rb', line 29 def copy_from_config(config) log "Starting file copy operations..." copy_exact_files(config.copy_files) copy_matching_patterns(config.copy_patterns) copy_directories(config.copy_directories) log_summary { copied: @copied_count, skipped: @skipped_count, failed: @failed_count } end |
#copy_matching_patterns(patterns) ⇒ Object
Copy files matching glob patterns
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/workbush/file_copier.rb', line 63 def copy_matching_patterns(patterns) return if patterns.empty? log "Copying files matching patterns..." patterns.each do |pattern| matches = Dir.glob(File.join(@source_path, pattern)) if matches.empty? log " No files matched pattern: #{pattern}", :skip @skipped_count += 1 next end matches.each do |source| relative_path = source.sub("#{@source_path}/", "") dest = File.join(@dest_path, relative_path) copy_single_item(source, dest, relative_path) end end end |