Class | RecursiveHTTPFetcher |
In: |
vendor/rails/railties/lib/commands/plugin.rb
|
Parent: | Object |
quiet | [RW] |
# File vendor/rails/railties/lib/commands/plugin.rb, line 902 902: def initialize(urls_to_fetch, level = 1, cwd = ".") 903: @level = level 904: @cwd = cwd 905: @urls_to_fetch = RUBY_VERSION >= '1.9' ? urls_to_fetch.lines : urls_to_fetch.to_a 906: @quiet = false 907: end
# File vendor/rails/railties/lib/commands/plugin.rb, line 941 941: def download(link) 942: puts "+ #{File.join(@cwd, File.basename(link))}" unless @quiet 943: open(link) do |stream| 944: File.open(File.join(@cwd, File.basename(link)), "wb") do |file| 945: file.write(stream.read) 946: end 947: end 948: end
# File vendor/rails/railties/lib/commands/plugin.rb, line 950 950: def fetch(links = @urls_to_fetch) 951: links.each do |l| 952: (l =~ /\/$/ || links == @urls_to_fetch) ? fetch_dir(l) : download(l) 953: end 954: end
# File vendor/rails/railties/lib/commands/plugin.rb, line 956 956: def fetch_dir(url) 957: @level += 1 958: push_d(File.basename(url)) if @level > 0 959: open(url) do |stream| 960: contents = stream.read 961: fetch(links(url, contents)) 962: end 963: pop_d if @level > 0 964: @level -= 1 965: end
# File vendor/rails/railties/lib/commands/plugin.rb, line 930 930: def links(base_url, contents) 931: links = [] 932: contents.scan(/href\s*=\s*\"*[^\">]*/i) do |link| 933: link = link.sub(/href="/i, "") 934: next if link =~ /svnindex.xsl$/ 935: next if link =~ /^(\w*:|)\/\// || link =~ /^\./ 936: links << File.join(base_url, link) 937: end 938: links 939: end
# File vendor/rails/railties/lib/commands/plugin.rb, line 909 909: def ls 910: @urls_to_fetch.collect do |url| 911: if url =~ /^svn(\+ssh)?:\/\/.*/ 912: `svn ls #{url}`.split("\n").map {|entry| "/#{entry}"} rescue nil 913: else 914: open(url) do |stream| 915: links("", stream.read) 916: end rescue nil 917: end 918: end.flatten 919: end
# File vendor/rails/railties/lib/commands/plugin.rb, line 926 926: def pop_d 927: @cwd = File.dirname(@cwd) 928: end