Class: MsPac::Pellet
- Inherits:
-
Hash
- Object
- Hash
- MsPac::Pellet
- Defined in:
- lib/mspac/pellet.rb
Constant Summary collapse
- @@cache_dir =
Pathname("~/.mspac/cache").
- @@install_dir =
Pathname("~/.mspac/installed").
Instance Method Summary collapse
- #cached? ⇒ Boolean
- #desc ⇒ Object
- #fetch ⇒ Object
-
#initialize(json, pm) ⇒ Pellet
constructor
A new instance of Pellet.
- #install ⇒ Object
- #installed? ⇒ Boolean
- #link ⇒ Object
- #lock ⇒ Object
- #name ⇒ Object
- #purge ⇒ Object
- #remove(nosave = false) ⇒ Object
- #repo ⇒ Object
- #to_s ⇒ Object
- #unlink ⇒ Object
- #unlock ⇒ Object
- #update(force = false) ⇒ Object
Constructor Details
#initialize(json, pm) ⇒ Pellet
Returns a new instance of Pellet.
110 111 112 113 114 115 116 117 |
# File 'lib/mspac/pellet.rb', line 110 def initialize(json, pm) json.keys.each do |key| self[key] = json[key] end @pm = pm @vcs = MsPac::VersionControl.new(self["vcs"]) end |
Instance Method Details
#cached? ⇒ Boolean
8 9 10 |
# File 'lib/mspac/pellet.rb', line 8 def cached? Pathname.new("#{@@cache_dir}/#{name}")..exist? end |
#desc ⇒ Object
19 20 21 |
# File 'lib/mspac/pellet.rb', line 19 def desc return self["desc"] end |
#fetch ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/mspac/pellet.rb', line 40 def fetch FileUtils.mkdir_p(@@cache_dir) FileUtils.mkdir_p(@@install_dir) get_deps puts hilight_status("Fetching #{name}...") if (Pathname.new("#{@@cache_dir}/#{name}")..exist?) Dir.chdir("#{@@cache_dir}/#{name}") do @vcs.update end else Dir.chdir(@@cache_dir) do @vcs.clone(self["repo"]) @vcs.ignore_file_perms(name) end end end |
#install ⇒ Object
119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/mspac/pellet.rb', line 119 def install if (!cached? && (self["vcs"] != "powerpellet")) raise MsPac::Error::PelletNotInstalled.new(name) end link if (!installed?) compile puts hilight_status("Installing #{name}...") execute("install") end |
#installed? ⇒ Boolean
131 132 133 |
# File 'lib/mspac/pellet.rb', line 131 def installed? Pathname.new("#{@@install_dir}/#{name}")..exist? end |
#link ⇒ Object
135 136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/mspac/pellet.rb', line 135 def link if (!cached? && (self["vcs"] != "powerpellet")) raise MsPac::Error::PelletNotInstalled.new(name) end return if (self["vcs"] == "powerpellet") puts hilight_status("Linking #{name}...") FileUtils.ln_sf( "#{@@cache_dir}/#{name}", "#{@@install_dir}/#{name}" ) end |
#lock ⇒ Object
149 150 151 152 153 154 155 156 |
# File 'lib/mspac/pellet.rb', line 149 def lock if (!installed?) raise MsPac::Error::PelletNotInstalled.new(name) end puts hilight_status("Locking #{name}...") FileUtils.touch("#{@@install_dir}/#{name}/.mspac_lock") end |
#name ⇒ Object
158 159 160 |
# File 'lib/mspac/pellet.rb', line 158 def name return self["name"] end |
#purge ⇒ Object
162 163 164 165 166 167 168 169 170 171 |
# File 'lib/mspac/pellet.rb', line 162 def purge if (!cached? && (self["vcs"] != "powerpellet")) raise MsPac::Error::PelletNotInstalled.new(name) end return if (self["vcs"] == "powerpellet") puts hilight_status("Purging #{name}...") FileUtils.rm_rf("#{@@cache_dir}/#{name}") end |
#remove(nosave = false) ⇒ Object
173 174 175 176 177 178 179 180 181 182 |
# File 'lib/mspac/pellet.rb', line 173 def remove(nosave = false) if (!installed?) raise MsPac::Error::PelletNotInstalled.new(name) end puts hilight_status("Removing #{name}...") execute("remove") unlink purge if (nosave) end |
#repo ⇒ Object
184 185 186 |
# File 'lib/mspac/pellet.rb', line 184 def repo return self["repo"] end |
#to_s ⇒ Object
188 189 190 191 192 193 194 195 196 197 198 |
# File 'lib/mspac/pellet.rb', line 188 def to_s header = [ hilight_name(name), hilight_installed(installed?) || hilight_cached(cached?) ].join(" ") return [ header, " #{repo}", " #{desc}" ].join("\n") end |
#unlink ⇒ Object
200 201 202 203 204 205 206 207 |
# File 'lib/mspac/pellet.rb', line 200 def unlink if (!installed?) raise MsPac::Error::PelletNotInstalled.new(name) end puts hilight_status("Unlinking #{name}...") FileUtils.rm_f("#{@@install_dir}/#{name}") end |
#unlock ⇒ Object
209 210 211 212 213 214 215 216 |
# File 'lib/mspac/pellet.rb', line 209 def unlock if (!installed?) raise MsPac::Error::PelletNotInstalled.new(name) end puts hilight_status("Unlocking #{name}...") FileUtils.rm_f("#{@@install_dir}/#{name}/.mspac_lock") end |
#update(force = false) ⇒ Object
218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 |
# File 'lib/mspac/pellet.rb', line 218 def update(force = false) if (!installed?) raise MsPac::Error::PelletNotInstalled.new(name) end return if (self["vcs"] == "powerpellet") Dir.chdir("#{@@install_dir}/#{name}") do if (Pathname.new(".mspac_lock")..exist?) puts hilight_error("Locked: #{name}") return end puts hilight_status("Updating #{name}...") tip = @vcs.revision @vcs.update new_tip = @vcs.revision if ((tip != new_tip) || force) install end end end |