Class: XcodeInstall::Xcode

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

Overview

A version of Xcode we fetched from the Apple Developer Portal we can download & install.

Sample object: <XcodeInstall::Xcode:0x007fa1d451c390

@date_modified=1573661580,
@name="6.4",
@path="/Developer_Tools/Xcode_6.4/Xcode_6.4.dmg",
@url=
 "https://developer.apple.com/devcenter/download.action?path=/Developer_Tools/Xcode_6.4/Xcode_6.4.dmg",
@version=Gem::Version.new("6.4")>,

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(json, url = nil, release_notes_url = nil) ⇒ Xcode

Returns a new instance of Xcode.



741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
# File 'lib/xcode/install.rb', line 741

def initialize(json, url = nil, release_notes_url = nil)
  if url.nil?
    @date_modified = DateTime.strptime(json['dateModified'], '%m/%d/%y %H:%M').strftime('%s').to_i
    @name = json['name'].gsub(/^Xcode /, '')
    @path = json['files'].first['remotePath']
    url_prefix = 'https://developer.apple.com/devcenter/download.action?path='
    @url = "#{url_prefix}#{@path}"
    @release_notes_url = "#{url_prefix}#{json['release_notes_path']}" if json['release_notes_path']
  else
    @name = json
    @path = url.split('/').last
    url_prefix = 'https://developer.apple.com/'
    @url = "#{url_prefix}#{url}"
    @release_notes_url = "#{url_prefix}#{release_notes_url}"
  end

  begin
    @version = Gem::Version.new(@name.split(' ')[0])
  rescue
    @version = Installer::MINIMUM_VERSION
  end
end

Instance Attribute Details

#date_modifiedObject (readonly)

Returns the value of attribute date_modified.



727
728
729
# File 'lib/xcode/install.rb', line 727

def date_modified
  @date_modified
end

#installedObject Also known as: installed?

Accessor since it’s set by the ‘Installer`



737
738
739
# File 'lib/xcode/install.rb', line 737

def installed
  @installed
end

#nameObject (readonly)

The name might include extra information like “for Lion” or “beta 2”



730
731
732
# File 'lib/xcode/install.rb', line 730

def name
  @name
end

#pathObject (readonly)

Returns the value of attribute path.



731
732
733
# File 'lib/xcode/install.rb', line 731

def path
  @path
end

#release_notes_urlObject (readonly)

Returns the value of attribute release_notes_url.



734
735
736
# File 'lib/xcode/install.rb', line 734

def release_notes_url
  @release_notes_url
end

#urlObject (readonly)

Returns the value of attribute url.



732
733
734
# File 'lib/xcode/install.rb', line 732

def url
  @url
end

#versionObject (readonly)

Returns the value of attribute version.



733
734
735
# File 'lib/xcode/install.rb', line 733

def version
  @version
end

Class Method Details

.new_prerelease(version, url, release_notes_path) ⇒ Object



773
774
775
776
777
778
# File 'lib/xcode/install.rb', line 773

def self.new_prerelease(version, url, release_notes_path)
  new('name' => version,
      'dateModified' => '01/01/70 00:00',
      'files' => [{ 'remotePath' => url.split('=').last }],
      'release_notes_path' => release_notes_path)
end

Instance Method Details

#==(other) ⇒ Object



768
769
770
771
# File 'lib/xcode/install.rb', line 768

def ==(other)
  date_modified == other.date_modified && name == other.name && path == other.path && \
    url == other.url && version == other.version
end

#to_sObject



764
765
766
# File 'lib/xcode/install.rb', line 764

def to_s
  "Xcode #{version} -- #{url}"
end