Class: Repositories
- Includes:
- Enumerable
- Defined in:
- lib/commands/plugin.rb
Class Method Summary collapse
Instance Method Summary collapse
- #add(uri) ⇒ Object
- #all ⇒ Object
- #defaults ⇒ Object
- #each(&block) ⇒ Object
- #exist?(uri) ⇒ Boolean
- #find_home ⇒ Object
- #find_plugin(name) ⇒ Object
-
#initialize(cache_file = File.join(find_home, ".rails-plugin-sources")) ⇒ Repositories
constructor
A new instance of Repositories.
- #load! ⇒ Object
- #remove(uri) ⇒ Object
- #save ⇒ Object
Constructor Details
#initialize(cache_file = File.join(find_home, ".rails-plugin-sources")) ⇒ Repositories
Returns a new instance of Repositories.
276 277 278 279 |
# File 'lib/commands/plugin.rb', line 276 def initialize(cache_file = File.join(find_home, ".rails-plugin-sources")) @cache_file = File.(cache_file) load! end |
Class Method Details
.each(&block) ⇒ Object
357 358 359 |
# File 'lib/commands/plugin.rb', line 357 def self.each(&block) self.instance.each(&block) end |
.instance ⇒ Object
353 354 355 |
# File 'lib/commands/plugin.rb', line 353 def self.instance @instance ||= Repositories.new end |
Instance Method Details
#add(uri) ⇒ Object
285 286 287 288 289 |
# File 'lib/commands/plugin.rb', line 285 def add(uri) unless find{|repo| repo.uri == uri } @repositories.push(Repository.new(uri)).last end end |
#all ⇒ Object
299 300 301 |
# File 'lib/commands/plugin.rb', line 299 def all @repositories end |
#defaults ⇒ Object
329 330 331 332 333 |
# File 'lib/commands/plugin.rb', line 329 def defaults <<-DEFAULTS http://dev.rubyonrails.com/svn/rails/plugins/ DEFAULTS end |
#each(&block) ⇒ Object
281 282 283 |
# File 'lib/commands/plugin.rb', line 281 def each(&block) @repositories.each(&block) end |
#exist?(uri) ⇒ Boolean
295 296 297 |
# File 'lib/commands/plugin.rb', line 295 def exist?(uri) @repositories.detect{|repo| repo.uri == uri } end |
#find_home ⇒ Object
335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 |
# File 'lib/commands/plugin.rb', line 335 def find_home ['HOME', 'USERPROFILE'].each do |homekey| return ENV[homekey] if ENV[homekey] end if ENV['HOMEDRIVE'] && ENV['HOMEPATH'] return "#{ENV['HOMEDRIVE']}:#{ENV['HOMEPATH']}" end begin File.("~") rescue StandardError => ex if File::ALT_SEPARATOR "C:/" else "/" end end end |
#find_plugin(name) ⇒ Object
303 304 305 306 307 308 309 310 |
# File 'lib/commands/plugin.rb', line 303 def find_plugin(name) @repositories.each do |repo| repo.each do |plugin| return plugin if plugin.name == name end end return nil end |
#load! ⇒ Object
312 313 314 315 316 317 318 |
# File 'lib/commands/plugin.rb', line 312 def load! contents = File.exist?(@cache_file) ? File.read(@cache_file) : defaults contents = defaults if contents.empty? @repositories = contents.split(/\n/).reject do |line| line =~ /^\s*#/ or line =~ /^\s*$/ end.map { |source| Repository.new(source.strip) } end |
#remove(uri) ⇒ Object
291 292 293 |
# File 'lib/commands/plugin.rb', line 291 def remove(uri) @repositories.reject!{|repo| repo.uri == uri} end |
#save ⇒ Object
320 321 322 323 324 325 326 327 |
# File 'lib/commands/plugin.rb', line 320 def save File.open(@cache_file, 'w') do |f| each do |repo| f.write(repo.uri) f.write("\n") end end end |