class Xcodeproj::Workspace


documents.
The {Workspace} allows to generate, read and serialize Xcode Workspace

def self.from_s(xml)

Returns:
  • (Workspace) - the generated workspace.

Parameters:
  • xml (String) --
def self.from_s(xml)
  document = REXML::Document.new(xml)
  projpaths = document.get_elements("/Workspace/FileRef").map do |node|
    node.attribute("location").to_s.sub(/^group:/, '')
  end
  new(*projpaths)
end

def self.new_from_xcworkspace(path)

Returns:
  • (Workspace) - the generated workspace.

Parameters:
  • path (String) --
def self.new_from_xcworkspace(path)
  begin
    from_s(File.read(File.join(path, 'contents.xcworkspacedata')))
  rescue Errno::ENOENT
    new
  end
end

def <<(projpath)

Returns:
  • (void) -

Parameters:
  • projpath (String) --
def <<(projpath)
  @projpaths << projpath
end

def include?(projpath)

Returns:
  • (Boolean) - whether the project is contained in the workspace.

Parameters:
  • projpath (String) --
def include?(projpath)
  @projpaths.include?(projpath)
end

def initialize(*projpaths)

Parameters:
  • projpaths (String) --
def initialize(*projpaths)
  @projpaths = projpaths
end

def save_as(path)

Returns:
  • (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

Returns:
  • (String) - the XML representation of the workspace.
def to_s
  REXML::Document.new(TEMPLATE).tap do |document|
    @projpaths.each do |projpath|
      document.root << REXML::Element.new("FileRef").tap do |el|
        el.attributes['location'] = "group:#{projpath}"
      end
    end
  end.to_s
end