class Pod::ProjectRenamer

Attributes

newname[R]
oldname[R]
processedPaths[W]

Public Class Methods

new(oldname, newname) click to toggle source
# File lib/cocoapods-vemars/services/renamer.rb, line 8
def initialize(oldname, newname)
  @oldname = oldname
  @newname = newname
  @processedPaths = []
end

Public Instance Methods

execute() click to toggle source
# File lib/cocoapods-vemars/services/renamer.rb, line 14
def execute
  path = Dir.pwd
  puts "#{path}"
  if validatePath(path)
    enumeratePath(path)
  else
    help! "Xcode project or workspace with name: #{@oldname} is not found in current path."
  end
end

Private Instance Methods

enumeratePath(path) click to toggle source
# File lib/cocoapods-vemars/services/renamer.rb, line 31
        def enumeratePath(path)
  Dir.each_child(path) do |child|
    childPath = path + "/#{child}"
    if !@processedPaths.include?(childPath) && !shouldSkip(childPath)
      processPath(childPath)
    end
  end
end
processPath(path) click to toggle source
# File lib/cocoapods-vemars/services/renamer.rb, line 40
        def processPath(path)
  # puts "Processing: #{path}"
  if File.directory?(path)
    enumeratePath(path)
  elsif File.exist?(path)
    updateContentsOfFile(path)
  end

  renameItem(path)
  @processedPaths.push(path)
end
renameItem(path) click to toggle source
# File lib/cocoapods-vemars/services/renamer.rb, line 77
        def renameItem(path)
  oldItemName = File.basename(path)
  if oldItemName.include?(oldname)
    newItemName = oldItemName.gsub(oldname, newname)
    directoryPath = File.dirname(path)
    newPath = directoryPath + "/#{newItemName}"
    File.rename(path, newPath)
    # puts "--- Renamed: #{oldItemName} -> #{newItemName}"
  end
end
shouldSkip(element) click to toggle source
# File lib/cocoapods-vemars/services/renamer.rb, line 52
        def shouldSkip(element)
  if element.include?(".DS_Store") ||
    element.include?("Carthage") ||
    element.include?("Pods") ||
    element.include?("fastlane") ||
    element.include?("build")
    return true
  end

  extension = File.extname(element)
  if extension.include?("appiconset") ||
    extension.include?("json") ||
    extension.include?("png") ||
    extension.include?("xcuserstate")
    return true
  end
  return  false
end
updateContentsOfFile(path) click to toggle source
# File lib/cocoapods-vemars/services/renamer.rb, line 71
        def updateContentsOfFile(path)
  text = File.read(path)
  text = text.gsub(oldname, newname)
  File.open(path, "w") { |file| file.puts text }
end
validatePath(path) click to toggle source
# File lib/cocoapods-vemars/services/renamer.rb, line 24
        def validatePath(path)
  projectPath = path + "/#{oldname}.xcodeproj"
  workspace = path + "/#{oldname}.xcworkspace"
  isValid = File.exist?(projectPath) || File.exist?(workspace)
  return isValid
end