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 =

Returns Default source directory for NNCC config migration.

Returns:

  • (String)

    Default source directory for NNCC config migration.

'~/.config/nncc'
DEFAULT_TARGET =

Returns Default target directory for NNCC config migration.

Returns:

  • (String)

    Default target directory for NNCC config migration.

'~/.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.



28
29
30
31
32
# File 'lib/rosett_ai/migration/nncc_config_migrator.rb', line 28

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.



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

def migrated
  @migrated
end

#sourceObject (readonly)

Returns the value of attribute source.



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

def source
  @source
end

#targetObject (readonly)

Returns the value of attribute target.



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

def target
  @target
end

Instance Method Details

#migrate!Array<String>

Performs the migration.

Returns:

  • (Array<String>)

    list of migrated relative paths



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

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



35
36
37
# File 'lib/rosett_ai/migration/nncc_config_migrator.rb', line 35

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



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

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