Class: XcodeInstall::Simulator
- Inherits:
-
Object
- Object
- XcodeInstall::Simulator
- Defined in:
- lib/xcode/install.rb
Instance Attribute Summary collapse
-
#identifier ⇒ Object
readonly
Returns the value of attribute identifier.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
-
#xcode ⇒ Object
readonly
Returns the value of attribute xcode.
Instance Method Summary collapse
- #apply_variables(template) ⇒ Object
- #dmg_path ⇒ Object
- #download ⇒ Object
-
#initialize(downloadable) ⇒ Simulator
constructor
A new instance of Simulator.
- #install ⇒ Object
- #installed? ⇒ Boolean
- #installed_string ⇒ Object
- #pkg_path ⇒ Object
- #prepare_package ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(downloadable) ⇒ Simulator
Returns a new instance of Simulator.
296 297 298 299 300 301 302 |
# File 'lib/xcode/install.rb', line 296 def initialize(downloadable) @version = Gem::Version.new(downloadable['version']) @install_prefix = apply_variables(downloadable['userInfo']['InstallPrefix']) @name = apply_variables(downloadable['name']) @identifier = apply_variables(downloadable['identifier']) @source = apply_variables(downloadable['source']) end |
Instance Attribute Details
#identifier ⇒ Object (readonly)
Returns the value of attribute identifier.
292 293 294 |
# File 'lib/xcode/install.rb', line 292 def identifier @identifier end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
291 292 293 |
# File 'lib/xcode/install.rb', line 291 def name @name end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
293 294 295 |
# File 'lib/xcode/install.rb', line 293 def source @source end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
290 291 292 |
# File 'lib/xcode/install.rb', line 290 def version @version end |
#xcode ⇒ Object (readonly)
Returns the value of attribute xcode.
294 295 296 |
# File 'lib/xcode/install.rb', line 294 def xcode @xcode end |
Instance Method Details
#apply_variables(template) ⇒ Object
375 376 377 378 379 380 381 382 383 384 385 386 387 |
# File 'lib/xcode/install.rb', line 375 def apply_variables(template) variable_map = { '$(DOWNLOADABLE_VERSION_MAJOR)' => version.to_s.split('.')[0], '$(DOWNLOADABLE_VERSION_MINOR)' => version.to_s.split('.')[1], '$(DOWNLOADABLE_IDENTIFIER)' => identifier, '$(DOWNLOADABLE_VERSION)' => version.to_s }.freeze variable_map.each do |key, value| next unless template.include?(key) template.sub!(key, value) end template end |
#dmg_path ⇒ Object
367 368 369 |
# File 'lib/xcode/install.rb', line 367 def dmg_path CACHE_DIR + Pathname.new(source).basename end |
#download ⇒ Object
325 326 327 328 |
# File 'lib/xcode/install.rb', line 325 def download result = Curl.new.fetch(source, CACHE_DIR) result ? dmg_path : nil end |
#install ⇒ Object
330 331 332 333 334 335 336 337 338 339 340 341 342 |
# File 'lib/xcode/install.rb', line 330 def install download unless dmg_path.exist? prepare_package unless pkg_path.exist? puts "Please authenticate to install #{name}..." `sudo installer -pkg #{pkg_path} -target /` fail Informative, "Could not install #{name}, please try again" unless installed? source_receipts_dir = '/private/var/db/receipts' target_receipts_dir = "#{@install_prefix}/System/Library/Receipts" FileUtils.mkdir_p(target_receipts_dir) FileUtils.cp("#{source_receipts_dir}/#{@identifier}.bom", target_receipts_dir) FileUtils.cp("#{source_receipts_dir}/#{@identifier}.plist", target_receipts_dir) puts "Successfully installed #{name}" end |
#installed? ⇒ Boolean
304 305 306 307 |
# File 'lib/xcode/install.rb', line 304 def installed? # FIXME: use downloadables' `InstalledIfAllReceiptsArePresentOrNewer` key File.directory?(@install_prefix) end |
#installed_string ⇒ Object
309 310 311 |
# File 'lib/xcode/install.rb', line 309 def installed_string installed? ? 'installed' : 'not installed' end |
#pkg_path ⇒ Object
371 372 373 |
# File 'lib/xcode/install.rb', line 371 def pkg_path CACHE_DIR + "#{identifier}.pkg" end |
#prepare_package ⇒ Object
346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 |
# File 'lib/xcode/install.rb', line 346 def prepare_package puts 'Mounting DMG' mount_location = Installer.new.mount(dmg_path) puts 'Expanding pkg' = CACHE_DIR + identifier FileUtils.rm_rf() `pkgutil --expand #{mount_location}/*.pkg #{}` puts "Expanded pkg into #{}" puts 'Unmounting DMG' `umount #{mount_location}` puts 'Setting package installation location' package_info_path = + 'PackageInfo' package_info_contents = File.read(package_info_path) File.open(package_info_path, 'w') do |f| f << package_info_contents.sub('pkg-info', %(pkg-info install-location="#{@install_prefix}")) end puts 'Rebuilding package' `pkgutil --flatten #{} #{pkg_path}` FileUtils.rm_rf() end |
#to_s ⇒ Object
313 314 315 |
# File 'lib/xcode/install.rb', line 313 def to_s "#{name} (#{installed_string})" end |