Module: RosettAi::Init::FileCopier
- Defined in:
- lib/rosett_ai/init/file_copier.rb
Overview
Helper module for copying files during initialization
Class Method Summary collapse
-
.copy_conf_assets(source_root, conf_base, copied) ⇒ void
Copy configuration assets (behaviours, schemas) to the target.
-
.copy_directory(source, target, copied, name) ⇒ void
Recursively copy a directory tree to the target.
-
.copy_executable(source, target, copied, name) ⇒ void
Copy an executable file preserving permissions.
-
.copy_glob_files(source_dir, target_dir, pattern, prefix, copied) ⇒ void
Copy files matching a glob pattern to the target directory.
-
.copy_global_assets(base_dir) ⇒ Array<String>
Copy global assets to the ~/.claude/ directory.
-
.copy_if_new(source, target, copied, name) ⇒ void
Copy a file only if the target does not already exist.
-
.copy_local_assets(base_dir) ⇒ Array<String>
Copy local assets to the project .claude/ directory.
-
.copy_single_file(source, target, copied, name) ⇒ void
Copy a single file to the target path.
Class Method Details
.copy_conf_assets(source_root, conf_base, copied) ⇒ void
This method returns an undefined value.
Copy configuration assets (behaviours, schemas) to the target.
50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/rosett_ai/init/file_copier.rb', line 50 def copy_conf_assets(source_root, conf_base, copied) FileUtils.mkdir_p(File.join(conf_base, 'behaviour')) FileUtils.mkdir_p(File.join(conf_base, 'schemas')) # Copy template behaviours (not internal conf/behaviour/ files) copy_glob_files(source_root.join('share', 'templates', 'behaviour'), File.join(conf_base, 'behaviour'), '*.yml', 'conf/behaviour', copied) copy_glob_files(source_root.join('conf', 'schemas'), File.join(conf_base, 'schemas'), '*.json', 'conf/schemas', copied) copy_if_new(source_root.join('conf', 'adopt_redactions.yml'), File.join(conf_base, 'adopt_redactions.yml'), copied, 'conf/adopt_redactions.yml') end |
.copy_directory(source, target, copied, name) ⇒ void
This method returns an undefined value.
Recursively copy a directory tree to the target.
99 100 101 102 103 104 |
# File 'lib/rosett_ai/init/file_copier.rb', line 99 def copy_directory(source, target, copied, name) return unless Dir.exist?(source) FileUtils.cp_r("#{source}/.", target) copied << name end |
.copy_executable(source, target, copied, name) ⇒ void
This method returns an undefined value.
Copy an executable file preserving permissions.
84 85 86 87 88 89 90 |
# File 'lib/rosett_ai/init/file_copier.rb', line 84 def copy_executable(source, target, copied, name) return unless File.exist?(source) FileUtils.cp(source, target) FileUtils.chmod(0o755, target) copied << name end |
.copy_glob_files(source_dir, target_dir, pattern, prefix, copied) ⇒ void
This method returns an undefined value.
Copy files matching a glob pattern to the target directory.
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/rosett_ai/init/file_copier.rb', line 114 def copy_glob_files(source_dir, target_dir, pattern, prefix, copied) return unless Dir.exist?(source_dir) Dir.glob(File.join(source_dir, pattern)).each do |file| basename = File.basename(file) target = File.join(target_dir, basename) if File.exist?(target) warn " skipped #{prefix}/#{basename} (already exists)" next end FileUtils.cp(file, target) copied << "#{prefix}/#{basename}" end end |
.copy_global_assets(base_dir) ⇒ Array<String>
Copy global assets to the ~/.claude/ directory.
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/rosett_ai/init/file_copier.rb', line 19 def copy_global_assets(base_dir) root = RosettAi.root copied = [] copy_single_file(root.join('settings.json'), File.join(base_dir, 'settings.json'), copied, 'settings.json') copy_executable(root.join('bin', 'rai'), File.join(base_dir, 'bin', 'rai'), copied, 'bin/raictl') copy_directory(root.join('lib', 'rosett_ai'), File.join(base_dir, 'lib', 'rosett_ai'), copied, 'lib/rosett_ai/') # Conf assets (behaviours, schemas) go to XDG-compliant ~/.config/rosett-ai/conf/ xdg_conf = RosettAi.paths.rai_conf_dir.to_s copy_conf_assets(root, xdg_conf, copied) copy_glob_files(root.join('doc'), File.join(base_dir, 'doc'), '*.md', 'doc', copied) copied end |
.copy_if_new(source, target, copied, name) ⇒ void
This method returns an undefined value.
Copy a file only if the target does not already exist.
138 139 140 141 142 143 |
# File 'lib/rosett_ai/init/file_copier.rb', line 138 def copy_if_new(source, target, copied, name) return unless File.exist?(source) && !File.exist?(target) FileUtils.cp(source, target) copied << name end |
.copy_local_assets(base_dir) ⇒ Array<String>
Copy local assets to the project .claude/ directory.
37 38 39 40 41 42 |
# File 'lib/rosett_ai/init/file_copier.rb', line 37 def copy_local_assets(base_dir) copied = [] # Local scope copies to .claude/conf/ (not XDG) copy_conf_assets(RosettAi.root, File.join(base_dir, 'conf'), copied) copied end |
.copy_single_file(source, target, copied, name) ⇒ void
This method returns an undefined value.
Copy a single file to the target path.
70 71 72 73 74 75 |
# File 'lib/rosett_ai/init/file_copier.rb', line 70 def copy_single_file(source, target, copied, name) return if File.exist?(target) || !File.exist?(source) FileUtils.cp(source, target) copied << name end |