class RecursiveHTTPFetcher

Attributes

quiet[RW]

Public Class Methods

new(urls_to_fetch, level = 1, cwd = ".") click to toggle source
# File lib/rails/commands/plugin.rb, line 478
def initialize(urls_to_fetch, level = 1, cwd = ".")
  @level = level
  @cwd = cwd
  @urls_to_fetch = RUBY_VERSION >= '1.9' ? urls_to_fetch.lines : urls_to_fetch.to_a
  @quiet = false
end

Public Instance Methods

download(link) click to toggle source
# File lib/rails/commands/plugin.rb, line 517
def download(link)
  puts "+ #{File.join(@cwd, File.basename(link))}" unless @quiet
  open(link) do |stream|
    File.open(File.join(@cwd, File.basename(link)), "wb") do |file|
      file.write(stream.read)
    end
  end
end
fetch(links = @urls_to_fetch) click to toggle source
# File lib/rails/commands/plugin.rb, line 526
def fetch(links = @urls_to_fetch)
  links.each do |l|
    (l =~ /\/$/ || links == @urls_to_fetch) ? fetch_dir(l) : download(l)
  end
end
fetch_dir(url) click to toggle source
# File lib/rails/commands/plugin.rb, line 532
def fetch_dir(url)
  @level += 1
  push_d(File.basename(url)) if @level > 0
  open(url) do |stream|
    contents =  stream.read
    fetch(links(url, contents))
  end
  pop_d if @level > 0
  @level -= 1
end
ls() click to toggle source
# File lib/rails/commands/plugin.rb, line 485
def ls
  @urls_to_fetch.collect do |url|
    if url =~ /^svn(\+ssh)?:\/\/.*/
      %xsvn ls #{url}`.split("\n").map {|entry| "/#{entry}"} rescue nil
    else
      open(url) do |stream|
        links("", stream.read)
      end rescue nil
    end
  end.flatten
end
pop_d() click to toggle source
# File lib/rails/commands/plugin.rb, line 502
def pop_d
  @cwd = File.dirname(@cwd)
end
push_d(dir) click to toggle source
# File lib/rails/commands/plugin.rb, line 497
def push_d(dir)
  @cwd = File.join(@cwd, dir)
  FileUtils.mkdir_p(@cwd)
end