Class: RosettAi::Migration::NnccConfigMigrator
- Inherits:
-
Object
- Object
- RosettAi::Migration::NnccConfigMigrator
- Defined in:
- lib/rosett_ai/migration/nncc_config_migrator.rb
Overview
Migrates legacy ~/.config/nncc/ to ~/.config/rosett-ai/.
Steps:
- Detect ~/.config/nncc/ existence
- Copy contents to ~/.config/rosett-ai/
- Rename source to ~/.config/nncc.migrated-
/ - Verify the copy succeeded
Constant Summary collapse
- DEFAULT_SOURCE =
Returns Default source directory for NNCC config migration.
'~/.config/nncc'- DEFAULT_TARGET =
Returns Default target directory for NNCC config migration.
'~/.config/rosett-ai'
Instance Attribute Summary collapse
-
#migrated ⇒ Object
readonly
Returns the value of attribute migrated.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
-
#target ⇒ Object
readonly
Returns the value of attribute target.
Instance Method Summary collapse
-
#initialize(source: DEFAULT_SOURCE, target: DEFAULT_TARGET) ⇒ NnccConfigMigrator
constructor
A new instance of NnccConfigMigrator.
-
#migrate! ⇒ Array<String>
Performs the migration.
-
#migration_needed? ⇒ Boolean
True if legacy config directory exists.
-
#plan ⇒ Array<Hash>
Returns a plan of what will be migrated.
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.(source)) @target = Pathname.new(File.(target)) @migrated = [] end |
Instance Attribute Details
#migrated ⇒ Object (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 |
#source ⇒ Object (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 |
#target ⇒ Object (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.
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.
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 |
#plan ⇒ Array<Hash>
Returns a plan of what will be migrated.
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 |