Class: Xcselect::Xcode

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/xcselect/xcode.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(fld) ⇒ Xcode

Returns a new instance of Xcode.



8
9
10
11
12
13
# File 'lib/xcselect/xcode.rb', line 8

def initialize(fld)
  @folder = fld
  ver_output = `#{xcodebuild_path} -version`
  @version = ver_output.match(/Xcode (.*)$/)[1]
  @build = ver_output.match(/Build version (.*)$/)[1]
end

Instance Attribute Details

#buildObject

Returns the value of attribute build.



7
8
9
# File 'lib/xcselect/xcode.rb', line 7

def build
  @build
end

#folderObject

Returns the value of attribute folder.



7
8
9
# File 'lib/xcselect/xcode.rb', line 7

def folder
  @folder
end

#versionObject

Returns the value of attribute version.



7
8
9
# File 'lib/xcselect/xcode.rb', line 7

def version
  @version
end

Class Method Details

.current_xcodeObject



33
34
35
# File 'lib/xcselect/xcode.rb', line 33

def self.current_xcode
  `xcode-select -print-path`.chomp
end

.current_xcode_pathObject



37
38
39
40
41
42
43
44
45
# File 'lib/xcselect/xcode.rb', line 37

def self.current_xcode_path
  path = self.current_xcode
  if path =~ /(.*Xcode(.*DP.*)?.app)/
    path = $1
  else
    path += "/Applications/Xcode.app"
  end
  return path
end

.find_allObject

Get an array of all self contained .app style xcode objects



24
25
26
27
28
29
30
31
# File 'lib/xcselect/xcode.rb', line 24

def self.find_all
  # Xcode is now in a single application, look for that and use that as a candidate
  newXcodes = `mdfind 'kMDItemCFBundleIdentifier = com.apple.dt.Xcode'`.chomp.split
  newXcodes = newXcodes.select do |x| 
    File.exists? x + "/Contents/Developer/usr/bin/xcodebuild"
  end
  newXcodes.map {|x| Xcode.new(x + "/Contents/Developer") }.sort
end

Instance Method Details

#<=>(o) ⇒ Object

sort by version number and fallback to build number after



57
58
59
60
# File 'lib/xcselect/xcode.rb', line 57

def <=>(o)
  res = version.to_f <=> o.version.to_f
  return res == 0 ?  o.build <=> build : res;
end

#eql?(o) ⇒ Boolean

Returns:

  • (Boolean)


47
48
49
50
# File 'lib/xcselect/xcode.rb', line 47

def eql?(o)
  return false if o.nil? 
  return (o.folder == folder && o.version == version && o.build == build)
end

#sdksObject



52
53
54
# File 'lib/xcselect/xcode.rb', line 52

def sdks
  `#{xcodebuild_path} -showsdks`
end

#to_sObject



19
20
21
# File 'lib/xcselect/xcode.rb', line 19

def to_s
  "Xcode: #{folder} - #{version} (#{build})"
end

#xcodebuild_pathObject



15
16
17
# File 'lib/xcselect/xcode.rb', line 15

def xcodebuild_path
  "#{folder}/usr/bin/xcodebuild"
end