Class: Xcode::Workspace

Inherits:
Object
  • Object
show all
Defined in:
lib/xcode/workspace.rb,
lib/xcode/builder/scheme_builder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Workspace

Returns a new instance of Workspace.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/xcode/workspace.rb', line 7

def initialize(path)
  path      = "#{path}.xcworkspace" unless path=~/\.xcworkspace/
  
  @name     = File.basename(path.gsub(/\.xcworkspace/,''))
  @projects = []
  @schemes  = nil
  @path     = File.expand_path path
  
  doc = Nokogiri::XML(open("#{@path}/contents.xcworkspacedata"))
  doc.search("FileRef").each do |file|
    location = file["location"]
    if (matcher = location.match(/^group:(.+\.xcodeproj)$/i))
      project_path = "#{workspace_root}/#{matcher[1]}"
      begin
        @projects << Xcode::Project.new(project_path)
      rescue => e
        puts "Skipping project file #{project_path} referened by #{self} as it failed to parse"
      end
    end
  end
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/xcode/workspace.rb', line 6

def name
  @name
end

#pathObject (readonly)

Returns the value of attribute path.



6
7
8
# File 'lib/xcode/workspace.rb', line 6

def path
  @path
end

#projectsObject (readonly)

Returns the value of attribute projects.



6
7
8
# File 'lib/xcode/workspace.rb', line 6

def projects
  @projects
end

Instance Method Details

#describeObject



74
75
76
77
78
79
# File 'lib/xcode/workspace.rb', line 74

def describe
  puts "Workspace #{name} contains:"
  projects.each do |p|
    p.describe
  end
end

#project(name) {|project| ... } ⇒ Project

Note:

if two projects match names, the first matching scheme is returned.

Return the names project. Raises an error if no projects match the specified name.

Parameters:

  • name (String)

    of the specific scheme

Yields:

Returns:

  • (Project)

    the specific project that matches the name specified



63
64
65
66
67
68
# File 'lib/xcode/workspace.rb', line 63

def project(name)
  project = @projects.select {|c| c.name == name.to_s}.first
  raise "No such project #{name} in #{self}, available projects are #{@projects.map {|c| c.name}.join(', ')}" if project.nil?
  yield project if block_given?
  project
end

#scheme(name) {|scheme| ... } ⇒ Scheme

Note:

if two schemes match names, the first matching scheme is returned.

Return the scheme with the specified name. Raises an error if no schemes match the specified name.

Parameters:

  • name (String)

    of the specific scheme

Yields:

Returns:

  • (Scheme)

    the specific scheme that matches the name specified



47
48
49
50
51
52
# File 'lib/xcode/workspace.rb', line 47

def scheme(name)
  scheme = schemes.select {|t| t.name == name.to_s and t.parent == self}.first
  raise "No such scheme #{name} in #{self}, available schemes are #{schemes.map {|t| t.to_s}.join(', ')}" if scheme.nil?
  yield scheme if block_given?
  scheme
end

#schemesArray<Xcode::Scheme>

Returns available schemes for the workspace.

Returns:



32
33
34
35
36
# File 'lib/xcode/workspace.rb', line 32

def schemes
  return @schemes unless @schemes.nil?
  @schemes = Xcode::Scheme.find_in_workspace(self)
  @schemes
end

#to_sObject



70
71
72
# File 'lib/xcode/workspace.rb', line 70

def to_s
  "#{name} (Workspace)"
end

#to_xcodebuild_optionObject



4
5
6
# File 'lib/xcode/builder/scheme_builder.rb', line 4

def to_xcodebuild_option
  "-workspace \"#{self.path}\""
end

#workspace_rootObject



81
82
83
# File 'lib/xcode/workspace.rb', line 81

def workspace_root
  File.dirname(@path)
end