Class: SwiftLibTemplater::RenameFilesCommand

Inherits:
Object
  • Object
show all
Defined in:
lib/swift_lib_templater/rename_files_command.rb

Instance Method Summary collapse

Constructor Details

#initialize(dir, project_name) ⇒ RenameFilesCommand

Returns a new instance of RenameFilesCommand.



4
5
6
7
# File 'lib/swift_lib_templater/rename_files_command.rb', line 4

def initialize(dir, project_name)
  @dir = dir
  @project_name = project_name
end

Instance Method Details

#executeObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/swift_lib_templater/rename_files_command.rb', line 9

def execute()
  # We need to list all the files before renaming the files because
  # Find.find doesn't like that we mess with the files that are being
  # enumerated
  paths = []
  Find.find(@dir) do |path|
    paths << path
  end
  paths.each do |path|
    base = File.basename(path)
    new_path = path.gsub('TEMPLATE', @project_name)
    new_dir, new_base = File.split(new_path)
    next unless base =~ /(TEMPLATE|TP)/
    File.rename(File.join(new_dir, base), new_path)
  end
  Find.find(@dir) do |path|
    next unless File.file?(path)
    next if File.extname(path) == ".png"
    next if File.extname(path) == ".mobileprovision"
    command = "sed -i \"\" \"s/TEMPLATE/#{@project_name}/g\" \"#{path}\""
    systemWithoutOutput(command)
  end
end