Class | RecursiveHTTPFetcher |
In: |
vendor/rails/railties/lib/commands/plugin.rb
|
Parent: | Object |
quiet | [RW] |
# File vendor/rails/railties/lib/commands/plugin.rb, line 885 885: def initialize(urls_to_fetch, level = 1, cwd = ".") 886: @level = level 887: @cwd = cwd 888: @urls_to_fetch = urls_to_fetch.to_a 889: @quiet = false 890: end
# File vendor/rails/railties/lib/commands/plugin.rb, line 924 924: def download(link) 925: puts "+ #{File.join(@cwd, File.basename(link))}" unless @quiet 926: open(link) do |stream| 927: File.open(File.join(@cwd, File.basename(link)), "wb") do |file| 928: file.write(stream.read) 929: end 930: end 931: end
# File vendor/rails/railties/lib/commands/plugin.rb, line 933 933: def fetch(links = @urls_to_fetch) 934: links.each do |l| 935: (l =~ /\/$/ || links == @urls_to_fetch) ? fetch_dir(l) : download(l) 936: end 937: end
# File vendor/rails/railties/lib/commands/plugin.rb, line 939 939: def fetch_dir(url) 940: @level += 1 941: push_d(File.basename(url)) if @level > 0 942: open(url) do |stream| 943: contents = stream.read 944: fetch(links(url, contents)) 945: end 946: pop_d if @level > 0 947: @level -= 1 948: end
# File vendor/rails/railties/lib/commands/plugin.rb, line 913 913: def links(base_url, contents) 914: links = [] 915: contents.scan(/href\s*=\s*\"*[^\">]*/i) do |link| 916: link = link.sub(/href="/i, "") 917: next if link =~ /svnindex.xsl$/ 918: next if link =~ /^(\w*:|)\/\// || link =~ /^\./ 919: links << File.join(base_url, link) 920: end 921: links 922: end
# File vendor/rails/railties/lib/commands/plugin.rb, line 892 892: def ls 893: @urls_to_fetch.collect do |url| 894: if url =~ /^svn:\/\/.*/ 895: `svn ls #{url}`.split("\n").map {|entry| "/#{entry}"} rescue nil 896: else 897: open(url) do |stream| 898: links("", stream.read) 899: end rescue nil 900: end 901: end.flatten 902: end
# File vendor/rails/railties/lib/commands/plugin.rb, line 909 909: def pop_d 910: @cwd = File.dirname(@cwd) 911: end