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 =
'~/.config/nncc'- DEFAULT_TARGET =
'~/.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.
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.(source)) @target = Pathname.new(File.(target)) @migrated = [] end |
Instance Attribute Details
#migrated ⇒ Object (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 |
#source ⇒ Object (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 |
#target ⇒ Object (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.
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.
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 |
#plan ⇒ Array<Hash>
Returns a plan of what will be migrated.
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 |