class Xcodeproj::Workspace
documents.
Provides support for generating, reading and serializing Xcode Workspace
def self.from_s(xml, workspace_path = '')
-
(Workspace)- the generated workspace.
Parameters:
-
xml(String) --
def self.from_s(xml, workspace_path = '') document = REXML::Document.new(xml) file_references = document.get_elements('/Workspace/FileRef').map do |node| FileReference.from_node(node) end instance = new(file_references) instance.load_schemes(workspace_path) instance end
def self.new_from_xcworkspace(path)
-
(Workspace)- the generated workspace.
Parameters:
-
path(String) --
def self.new_from_xcworkspace(path) from_s(File.read(File.join(path, 'contents.xcworkspacedata')), File.expand_path(File.dirname(path))) rescue Errno::ENOENT new end
def <<(projpath)
-
(void)-
Parameters:
-
projpath(String) --
def <<(projpath) project_file_reference = Xcodeproj::Workspace::FileReference.new(projpath) @file_references << project_file_reference load_schemes_from_project File.expand_path(projpath) end
def file_reference_xml(file_reference)
-
file_reference(FileReference) -- The file reference.
Returns:
-
(String)- The XML representation of a file reference.
def file_reference_xml(file_reference) <<-DOC FileRef location = "#{file_reference.type}:#{file_reference.path}"> /FileRef> DOC end
def include?(file_reference)
-
(Boolean)- whether the project is contained in the workspace.
Parameters:
-
file_reference(FileReference) --
def include?(file_reference) @file_references.include?(file_reference) end
def initialize(*file_references)
-
file_references(Array) -- @see file_references
def initialize(*file_references) @file_references = file_references.flatten @schemes = {} end
def load_schemes(workspace_dir_path)
-
(void)-
Parameters:
-
workspace_dir_path(String) --
def load_schemes(workspace_dir_path) @file_references.each do |file_reference| project_full_path = file_reference.absolute_path(workspace_dir_path) load_schemes_from_project(project_full_path) end end
def load_schemes_from_project(project_full_path)
-
(void)-
Parameters:
-
project_full_path(String) --
def load_schemes_from_project(project_full_path) schemes = Xcodeproj::Project.schemes project_full_path schemes.each do |scheme_name| @schemes[scheme_name] = project_full_path end end
def root_xml(contents)
-
contents(String) -- The XML contents of the workspace.
Returns:
-
(String)- The template of the workspace XML as formated by Xcode.
def root_xml(contents) <<-DOC l version="1.0" encoding="UTF-8"?> kspace ersion = "1.0"> {contents.strip} rkspace> DOC end
def save_as(path)
-
(void)-
Parameters:
-
path(String) --
def save_as(path) FileUtils.mkdir_p(path) File.open(File.join(path, 'contents.xcworkspacedata'), 'w') do |out| out << to_s end end
def to_s
-
(String)- the XML representation of the workspace.
def to_s contents = file_references.map { |reference| file_reference_xml(reference) } root_xml(contents.join('')) end