Class: RosettAi::Migration::NnccConfigMigrator

Inherits:
Object
  • Object
show all
Defined in:
lib/rosett_ai/migration/nncc_config_migrator.rb

Overview

Migrates legacy ~/.config/nncc/ to ~/.config/rosett-ai/.

Steps:

  1. Detect ~/.config/nncc/ existence
  2. Copy contents to ~/.config/rosett-ai/
  3. Rename source to ~/.config/nncc.migrated-/
  4. Verify the copy succeeded

Author:

  • hugo

  • claude

Constant Summary collapse

DEFAULT_SOURCE =
'~/.config/nncc'
DEFAULT_TARGET =
'~/.config/rosett-ai'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source: DEFAULT_SOURCE, target: DEFAULT_TARGET) ⇒ NnccConfigMigrator

Returns a new instance of NnccConfigMigrator.



26
27
28
29
30
# File 'lib/rosett_ai/migration/nncc_config_migrator.rb', line 26

def initialize(source: DEFAULT_SOURCE, target: DEFAULT_TARGET)
  @source = Pathname.new(File.expand_path(source))
  @target = Pathname.new(File.expand_path(target))
  @migrated = []
end

Instance Attribute Details

#migratedObject (readonly)

Returns the value of attribute migrated.



24
25
26
# File 'lib/rosett_ai/migration/nncc_config_migrator.rb', line 24

def migrated
  @migrated
end

#sourceObject (readonly)

Returns the value of attribute source.



24
25
26
# File 'lib/rosett_ai/migration/nncc_config_migrator.rb', line 24

def source
  @source
end

#targetObject (readonly)

Returns the value of attribute target.



24
25
26
# File 'lib/rosett_ai/migration/nncc_config_migrator.rb', line 24

def target
  @target
end

Instance Method Details

#migrate!Array<String>

Performs the migration.

Returns:

  • (Array<String>)

    list of migrated relative paths



40
41
42
43
44
45
46
47
48
# File 'lib/rosett_ai/migration/nncc_config_migrator.rb', line 40

def migrate!
  @migrated = []
  return @migrated unless migration_needed?

  FileUtils.mkdir_p(target)
  copy_tree(source, target)
  mark_source_migrated
  @migrated
end

#migration_needed?Boolean

Returns true if legacy config directory exists.

Returns:

  • (Boolean)

    true if legacy config directory exists



33
34
35
# File 'lib/rosett_ai/migration/nncc_config_migrator.rb', line 33

def migration_needed?
  source.directory? && !source.basename.to_s.include?('.migrated-')
end

#planArray<Hash>

Returns a plan of what will be migrated.

Returns:

  • (Array<Hash>)

    list of files with :path and :size keys



53
54
55
56
57
58
59
60
# File 'lib/rosett_ai/migration/nncc_config_migrator.rb', line 53

def plan
  return [] unless migration_needed?

  source.glob('**/*').select(&:file?).map do |file|
    rel = file.relative_path_from(source).to_s
    { path: rel, size: file.size }
  end
end