Class: XcodeSnippets::Migrator

Inherits:
Object
  • Object
show all
Defined in:
lib/xcode_snippets/migrator.rb

Instance Method Summary collapse

Constructor Details

#initialize(snippet_manager) ⇒ Migrator

Returns a new instance of Migrator.



3
4
5
# File 'lib/xcode_snippets/migrator.rb', line 3

def initialize(snippet_manager)
  @snippet_manager = snippet_manager
end

Instance Method Details

#clean_upObject



28
29
30
31
# File 'lib/xcode_snippets/migrator.rb', line 28

def clean_up
  FileUtils.rm_rf(@tmp_dir) if @tmp_dir
  @tmp_dir = nil
end

#migrate_snippets_from(path, confirmation_delegate = nil) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/xcode_snippets/migrator.rb', line 7

def migrate_snippets_from(path, confirmation_delegate = nil)
  make_temp_dir(path)
  snippet_files = Dir[File.join(path, "*.codesnippet")]
  
  snippets = snippet_files.map do |snippet_path|
    XcodeSnippets::Snippet.new(snippet_path)
  end
  
  if confirmation_delegate && confirmation_delegate.respond_to?(:migrator_should_proceed_with_migration?)
    return unless confirmation_delegate.migrator_should_proceed_with_migration?(self, snippets)
  end
  
  temp_paths = snippets.map do |snippet|
    File.join(@tmp_dir, "#{snippet..title}.codesnippet").tap do |temp_path|
      FileUtils.mv(snippet.path, temp_path)
    end
  end
  
  @snippet_manager.install_snippets_from_paths(temp_paths)
end