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.



778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
# File 'lib/xcode/install.rb', line 778

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.



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

def date_modified
  @date_modified
end

#installedObject Also known as: installed?

Accessor since it’s set by the ‘Installer`



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

def installed
  @installed
end

#nameObject (readonly)

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



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

def name
  @name
end

#pathObject (readonly)

Returns the value of attribute path.



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

def path
  @path
end

#release_notes_urlObject (readonly)

Returns the value of attribute release_notes_url.



771
772
773
# File 'lib/xcode/install.rb', line 771

def release_notes_url
  @release_notes_url
end

#urlObject (readonly)

Returns the value of attribute url.



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

def url
  @url
end

#versionObject (readonly)

Returns the value of attribute version.



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

def version
  @version
end

Class Method Details

.new_prerelease(version, url, release_notes_path) ⇒ Object



810
811
812
813
814
815
# File 'lib/xcode/install.rb', line 810

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



805
806
807
808
# File 'lib/xcode/install.rb', line 805

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

#to_sObject



801
802
803
# File 'lib/xcode/install.rb', line 801

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