| Class | RecursiveHTTPFetcher |
| In: |
vendor/rails/railties/lib/commands/plugin.rb
|
| Parent: | Object |
| quiet | [RW] |
# File vendor/rails/railties/lib/commands/plugin.rb, line 858
858: def initialize(urls_to_fetch, level = 1, cwd = ".")
859: @level = level
860: @cwd = cwd
861: @urls_to_fetch = urls_to_fetch.to_a
862: @quiet = false
863: end
# File vendor/rails/railties/lib/commands/plugin.rb, line 897
897: def download(link)
898: puts "+ #{File.join(@cwd, File.basename(link))}" unless @quiet
899: open(link) do |stream|
900: File.open(File.join(@cwd, File.basename(link)), "wb") do |file|
901: file.write(stream.read)
902: end
903: end
904: end
# File vendor/rails/railties/lib/commands/plugin.rb, line 906
906: def fetch(links = @urls_to_fetch)
907: links.each do |l|
908: (l =~ /\/$/ || links == @urls_to_fetch) ? fetch_dir(l) : download(l)
909: end
910: end
# File vendor/rails/railties/lib/commands/plugin.rb, line 912
912: def fetch_dir(url)
913: @level += 1
914: push_d(File.basename(url)) if @level > 0
915: open(url) do |stream|
916: contents = stream.read
917: fetch(links(url, contents))
918: end
919: pop_d if @level > 0
920: @level -= 1
921: end
# File vendor/rails/railties/lib/commands/plugin.rb, line 886
886: def links(base_url, contents)
887: links = []
888: contents.scan(/href\s*=\s*\"*[^\">]*/i) do |link|
889: link = link.sub(/href="/i, "")
890: next if link =~ /svnindex.xsl$/
891: next if link =~ /^(\w*:|)\/\// || link =~ /^\./
892: links << File.join(base_url, link)
893: end
894: links
895: end
# File vendor/rails/railties/lib/commands/plugin.rb, line 865
865: def ls
866: @urls_to_fetch.collect do |url|
867: if url =~ /^svn:\/\/.*/
868: `svn ls #{url}`.split("\n").map {|entry| "/#{entry}"} rescue nil
869: else
870: open(url) do |stream|
871: links("", stream.read)
872: end rescue nil
873: end
874: end.flatten
875: end
# File vendor/rails/railties/lib/commands/plugin.rb, line 882
882: def pop_d
883: @cwd = File.dirname(@cwd)
884: end