Class: Xcodeproj::Workspace
- Inherits:
-
Object
- Object
- Xcodeproj::Workspace
- Defined in:
- lib/xcodeproj/workspace.rb,
lib/xcodeproj/workspace/file_reference.rb
Overview
Provides support for generating, reading and serializing Xcode Workspace documents.
Defined Under Namespace
Classes: FileReference
Instance Attribute Summary collapse
- #file_references ⇒ Array<String>, Array<FileReference> readonly
-
#schemes ⇒ Object
readonly
Returns the value of attribute schemes.
Class Method Summary collapse
-
.from_s(xml, workspace_path = '') ⇒ Workspace
Returns a workspace generated by reading the contents of the given XML representation.
-
.new_from_xcworkspace(path) ⇒ Workspace
Returns a workspace generated by reading the contents of the given path.
Instance Method Summary collapse
-
#<<(projpath) ⇒ void
Adds a new path to the list of the of projects contained in the workspace.
-
#include?(file_reference) ⇒ Boolean
Checks if the workspace contains the project with the given file reference.
-
#initialize(*file_references) ⇒ Workspace
constructor
A new instance of Workspace.
-
#load_schemes(workspace_dir_path) ⇒ void
Load all schemes from all projects in workspace.
-
#save_as(path) ⇒ void
Saves the workspace at the given ‘xcworkspace` path.
-
#to_s ⇒ String
The XML representation of the workspace.
Constructor Details
#initialize(*file_references) ⇒ Workspace
Returns a new instance of Workspace.
19 20 21 22 |
# File 'lib/xcodeproj/workspace.rb', line 19 def initialize(*file_references) @file_references = file_references.flatten @schemes = {} end |
Instance Attribute Details
#file_references ⇒ Array<String>, Array<FileReference> (readonly)
14 15 16 |
# File 'lib/xcodeproj/workspace.rb', line 14 def file_references @file_references end |
#schemes ⇒ Object (readonly)
Returns the value of attribute schemes.
15 16 17 |
# File 'lib/xcodeproj/workspace.rb', line 15 def schemes @schemes end |
Class Method Details
.from_s(xml, workspace_path = '') ⇒ Workspace
Returns a workspace generated by reading the contents of the given XML representation.
49 50 51 52 53 54 55 56 57 |
# File 'lib/xcodeproj/workspace.rb', line 49 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 |
.new_from_xcworkspace(path) ⇒ Workspace
Returns a workspace generated by reading the contents of the given path.
33 34 35 36 37 |
# File 'lib/xcodeproj/workspace.rb', line 33 def self.new_from_xcworkspace(path) from_s(File.read(File.join(path, 'contents.xcworkspacedata')), File.(File.dirname(path))) rescue Errno::ENOENT new end |
Instance Method Details
#<<(projpath) ⇒ void
This method returns an undefined value.
Adds a new path to the list of the of projects contained in the workspace.
69 70 71 72 73 |
# File 'lib/xcodeproj/workspace.rb', line 69 def <<(projpath) project_file_reference = Xcodeproj::Workspace::FileReference.new(projpath) @file_references << project_file_reference load_schemes_from_project File.(projpath) end |
#include?(file_reference) ⇒ Boolean
Checks if the workspace contains the project with the given file reference.
83 84 85 |
# File 'lib/xcodeproj/workspace.rb', line 83 def include?(file_reference) @file_references.include?(file_reference) end |
#load_schemes(workspace_dir_path) ⇒ void
This method returns an undefined value.
Load all schemes from all projects in workspace
117 118 119 120 121 122 |
# File 'lib/xcodeproj/workspace.rb', line 117 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 |
#save_as(path) ⇒ void
This method returns an undefined value.
Saves the workspace at the given ‘xcworkspace` path.
101 102 103 104 105 106 |
# File 'lib/xcodeproj/workspace.rb', line 101 def save_as(path) FileUtils.mkdir_p(path) File.open(File.join(path, 'contents.xcworkspacedata'), 'w') do |out| out << to_s end end |
#to_s ⇒ String
Returns the XML representation of the workspace.
89 90 91 92 |
# File 'lib/xcodeproj/workspace.rb', line 89 def to_s contents = file_references.map { |reference| file_reference_xml(reference) } root_xml(contents.join('')) end |