Class: XcodeInstall::Installer
- Inherits:
-
Object
- Object
- XcodeInstall::Installer
- Defined in:
- lib/xcode/install.rb
Instance Attribute Summary collapse
-
#xcodes ⇒ Object
readonly
Returns the value of attribute xcodes.
Instance Method Summary collapse
- #cache_dir ⇒ Object
- #current_symlink ⇒ Object
- #download(version) ⇒ Object
- #exist?(version) ⇒ Boolean
-
#initialize ⇒ Installer
constructor
A new instance of Installer.
- #install_dmg(dmgPath, suffix = '', switch = true, clean = true) ⇒ Object
- #install_version(version, switch = true, clean = true) ⇒ Object
- #installed?(version) ⇒ Boolean
- #installed_versions ⇒ Object
- #list ⇒ Object
- #list_current ⇒ Object
- #rm_list_cache ⇒ Object
- #symlink(version) ⇒ Object
- #symlinks_to ⇒ Object
Constructor Details
#initialize ⇒ Installer
Returns a new instance of Installer.
74 75 76 |
# File 'lib/xcode/install.rb', line 74 def initialize FileUtils.mkdir_p(CACHE_DIR) end |
Instance Attribute Details
#xcodes ⇒ Object (readonly)
Returns the value of attribute xcodes.
72 73 74 |
# File 'lib/xcode/install.rb', line 72 def xcodes @xcodes end |
Instance Method Details
#cache_dir ⇒ Object
78 79 80 |
# File 'lib/xcode/install.rb', line 78 def cache_dir CACHE_DIR end |
#current_symlink ⇒ Object
82 83 84 |
# File 'lib/xcode/install.rb', line 82 def current_symlink File.symlink?(SYMLINK_PATH) ? SYMLINK_PATH : nil end |
#download(version) ⇒ Object
86 87 88 89 90 91 92 93 |
# File 'lib/xcode/install.rb', line 86 def download(version) return unless exist?(version) xcode = seedlist.find { |x| x.name == version } dmg_file = Pathname.new(File.basename(xcode.path)) result = Curl.new.fetch(xcode.url, CACHE_DIR, devcenter., dmg_file) result ? CACHE_DIR + dmg_file : nil end |
#exist?(version) ⇒ Boolean
95 96 97 |
# File 'lib/xcode/install.rb', line 95 def exist?(version) list_versions.include?(version) end |
#install_dmg(dmgPath, suffix = '', switch = true, clean = true) ⇒ Object
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/xcode/install.rb', line 109 def install_dmg(dmgPath, suffix = '', switch = true, clean = true) xcode_path = "/Applications/Xcode#{suffix}.app" `hdiutil mount -nobrowse -noverify #{dmgPath}` puts 'Please authenticate for Xcode installation...' source = Dir.glob('/Volumes/Xcode/Xcode*.app').first if source.nil? puts 'No `Xcode.app` found in DMG.' return end `sudo ditto "#{source}" "#{xcode_path}"` `umount "/Volumes/Xcode"` enable_developer_mode `sudo xcodebuild -license` unless xcode_license_approved? if switch `sudo rm -f #{SYMLINK_PATH}` unless current_symlink.nil? `sudo ln -sf #{xcode_path} #{SYMLINK_PATH}` unless SYMLINK_PATH.exist? `sudo xcode-select --switch #{xcode_path}` puts `xcodebuild -version` end FileUtils.rm_f(dmgPath) if clean end |
#install_version(version, switch = true, clean = true) ⇒ Object
138 139 140 141 142 143 144 |
# File 'lib/xcode/install.rb', line 138 def install_version(version, switch = true, clean = true) return if version.nil? dmg_path = get_dmg(version) fail Informative, "Failed to download Xcode #{version}." if dmg_path.nil? install_dmg(dmg_path, "-#{version.split(' ')[0]}", switch, clean) end |
#installed?(version) ⇒ Boolean
99 100 101 |
# File 'lib/xcode/install.rb', line 99 def installed?(version) installed_versions.map(&:version).include?(version) end |
#installed_versions ⇒ Object
103 104 105 106 107 |
# File 'lib/xcode/install.rb', line 103 def installed_versions @installed ||= installed.map { |x| InstalledXcode.new(x) }.sort do |a, b| Gem::Version.new(a.version) <=> Gem::Version.new(b.version) end end |
#list ⇒ Object
152 153 154 |
# File 'lib/xcode/install.rb', line 152 def list list_versions.join("\n") end |
#list_current ⇒ Object
146 147 148 149 150 |
# File 'lib/xcode/install.rb', line 146 def list_current stable_majors = list_versions.reject { |v| /beta/i =~ v }.map { |v| v.split('.')[0] }.map { |v| v.split(' ')[0] } latest_stable_major = stable_majors.select { |v| v.length == 1 }.uniq.sort.last.to_i list_versions.select { |v| v.split('.')[0].to_i >= latest_stable_major }.sort.join("\n") end |
#rm_list_cache ⇒ Object
156 157 158 |
# File 'lib/xcode/install.rb', line 156 def rm_list_cache FileUtils.rm_f(LIST_FILE) end |
#symlink(version) ⇒ Object
160 161 162 163 164 |
# File 'lib/xcode/install.rb', line 160 def symlink(version) xcode = installed_versions.find { |x| x.version == version } `sudo rm -f #{SYMLINK_PATH}` unless current_symlink.nil? `sudo ln -sf #{xcode.path} #{SYMLINK_PATH}` unless xcode.nil? || SYMLINK_PATH.exist? end |
#symlinks_to ⇒ Object
166 167 168 |
# File 'lib/xcode/install.rb', line 166 def symlinks_to File.absolute_path(File.readlink(current_symlink), SYMLINK_PATH.dirname) if current_symlink end |