Class: XcodeInstall::InstalledXcode

Inherits:
Object
  • Object
show all
Defined in:
lib/xcode/install.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ InstalledXcode

Returns a new instance of InstalledXcode.



272
273
274
275
# File 'lib/xcode/install.rb', line 272

def initialize(path)
  @path = Pathname.new(path)
  @version = get_version(path)
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



269
270
271
# File 'lib/xcode/install.rb', line 269

def path
  @path
end

#versionObject (readonly)

Returns the value of attribute version.



270
271
272
# File 'lib/xcode/install.rb', line 270

def version
  @version
end

Instance Method Details

#approve_licenseObject



277
278
279
280
281
282
283
284
# File 'lib/xcode/install.rb', line 277

def approve_license
  license_path = "#{@path}/Contents/Resources/English.lproj/License.rtf"
  license_id = IO.read(license_path).match(/^EA\d{4}/)
  license_plist_path = '/Library/Preferences/com.apple.dt.Xcode.plist'
  `sudo rm -rf #{license_plist_path}`
  `sudo /usr/libexec/PlistBuddy -c "add :IDELastGMLicenseAgreedTo string #{license_id}" #{license_plist_path}`
  `sudo /usr/libexec/PlistBuddy -c "add :IDEXcodeVersionForAgreedToGMLicense string #{@version}" #{license_plist_path}`
end

#get_version(xcode_path) ⇒ Object



288
289
290
291
292
# File 'lib/xcode/install.rb', line 288

def get_version(xcode_path)
  output = `DEVELOPER_DIR='' "#{xcode_path}/Contents/Developer/usr/bin/xcodebuild" -version`
  return '0.0' if output.nil? # ¯\_(ツ)_/¯
  output.split("\n").first.split(' ')[1]
end