class XcodeArchiveCache::Injection::Storage

Attributes

container_dir_path[R]

@return [String]

headers_storage_dir_paths[R]

@return [Hash{XcodeArchiveCache::BuildGraph::Node => String}]

Public Class Methods

new(path) click to toggle source

@param [String] path

# File lib/injection/storage.rb, line 15
def initialize(path)
  @container_dir_path = path
  @headers_storage_dir_paths = Hash.new

  prepare_container_dir
end

Public Instance Methods

get_all_headers_storage_paths() click to toggle source
# File lib/injection/storage.rb, line 103
def get_all_headers_storage_paths
  headers_storage_dir_paths
      .map { |_, path| path }
      .flatten
      .uniq
end
get_default_headers_storage_path(node) click to toggle source

@param [XcodeArchiveCache::BuildGraph::Node] node

@return [String]

# File lib/injection/storage.rb, line 114
def get_default_headers_storage_path(node)
  "include/#{node.name}"
end
get_headers_storage_paths(node) click to toggle source

@param [XcodeArchiveCache::BuildGraph::Node] node

@return [String]

# File lib/injection/storage.rb, line 99
def get_headers_storage_paths(node)
  headers_storage_dir_paths[node.name]
end
get_modulemap_path(node) click to toggle source

@param [XcodeArchiveCache::BuildGraph::Node] node

@return [String]

# File lib/injection/storage.rb, line 55
def get_modulemap_path(node)
  modulemap_file_name = node.resulting_modulemap_file_name
  return if modulemap_file_name == nil

  storage_path = get_storage_path(node)
  stored_modulemap_file_path = get_stored_file_path(storage_path, modulemap_file_name)
  File.exist?(stored_modulemap_file_path) ? stored_modulemap_file_path : nil
end
get_storage_path(node) click to toggle source

@param [XcodeArchiveCache::BuildGraph::Node] node

@return [String]

# File lib/injection/storage.rb, line 91
def get_storage_path(node)
  File.join(container_dir_path, node.name)
end
prepare_storage(node) click to toggle source

@param [XcodeArchiveCache::BuildGraph::Node] node

# File lib/injection/storage.rb, line 77
def prepare_storage(node)
  path = get_storage_path(node)
  if File.exist?(path)
    raise StandardError.new, "Injection storage path is already busy"
  end

  FileUtils.mkdir_p(path)
  path
end
store_default_headers(node, file_paths) click to toggle source

@param [XcodeArchiveCache::BuildGraph::Node] node @param [Array<String>] file_paths

# File lib/injection/storage.rb, line 43
def store_default_headers(node, file_paths)
  store_headers(node, get_default_headers_storage_path(node), file_paths)
end
store_headers(node, path, file_paths, save_path = true) click to toggle source

@param [XcodeArchiveCache::BuildGraph::Node] node @param [String] path @param [Array<String>] file_paths

# File lib/injection/storage.rb, line 26
def store_headers(node, path, file_paths, save_path = true)
  storage_path = Pathname.new(path).absolute? ? path : get_full_header_storage_path(path)

  unless File.exist?(storage_path)
    FileUtils.mkdir_p(storage_path)
  end

  file_paths.each do |file_path|
    FileUtils.cp(file_path, get_stored_file_path(storage_path, file_path))
  end

  save_header_storage_path(storage_path, node) if save_path
end
store_modulemap_headers(node, file_paths) click to toggle source
# File lib/injection/storage.rb, line 47
def store_modulemap_headers(node, file_paths)
  store_headers(node, get_storage_path(node), file_paths, false)
end
store_products(node, file_paths) click to toggle source

@param [XcodeArchiveCache::BuildGraph::Node] node @param [Array<String>] file_paths

# File lib/injection/storage.rb, line 67
def store_products(node, file_paths)
  storage_path = prepare_storage(node)

  file_paths.each do |path|
    FileUtils.cp_r(path, storage_path)
  end
end

Private Instance Methods

get_full_header_storage_path(path) click to toggle source

@param [String] path

@return [String]

# File lib/injection/storage.rb, line 130
def get_full_header_storage_path(path)
  File.absolute_path(path, container_dir_path)
end
get_stored_file_path(storage_path, file_path) click to toggle source

@param [String] storage_path @param [String] file_path

@return [String]

# File lib/injection/storage.rb, line 139
def get_stored_file_path(storage_path, file_path)
  File.join(storage_path, File.basename(file_path))
end
prepare_container_dir() click to toggle source
# File lib/injection/storage.rb, line 120
def prepare_container_dir
  if File.exist?(container_dir_path)
    FileUtils.rm_rf(container_dir_path)
  end
end
save_header_storage_path(path, node) click to toggle source

@param [String] path @param [XcodeArchiveCache::BuildGraph::Node] node

# File lib/injection/storage.rb, line 146
def save_header_storage_path(path, node)
  paths = get_headers_storage_paths(node) || []
  containing_directory = File.dirname(path)
  unless paths.include?(containing_directory)
    paths.push(containing_directory)
    set_all_headers_storage_paths(paths, node)
  end
end
set_all_headers_storage_paths(paths, node) click to toggle source

@param [String] paths @param [XcodeArchiveCache::BuildGraph::Node] node

# File lib/injection/storage.rb, line 158
def set_all_headers_storage_paths(paths, node)
  headers_storage_dir_paths[node.name] = paths
end