Class: RecursiveHTTPFetcher
- Inherits:
-
Object
- Object
- RecursiveHTTPFetcher
- Defined in:
- railties/lib/rails/commands/plugin.rb
Instance Attribute Summary (collapse)
-
- (Object) quiet
Returns the value of attribute quiet.
Instance Method Summary (collapse)
- - (Object) download(link)
- - (Object) fetch(links = @urls_to_fetch)
- - (Object) fetch_dir(url)
-
- (RecursiveHTTPFetcher) initialize(urls_to_fetch, level = 1, cwd = ".")
constructor
A new instance of RecursiveHTTPFetcher.
- - (Object) links(base_url, contents)
- - (Object) ls
- - (Object) pop_d
- - (Object) push_d(dir)
Constructor Details
- (RecursiveHTTPFetcher) initialize(urls_to_fetch, level = 1, cwd = ".")
A new instance of RecursiveHTTPFetcher
478 479 480 481 482 483 |
# File 'railties/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 |
Instance Attribute Details
- (Object) quiet
Returns the value of attribute quiet
477 478 479 |
# File 'railties/lib/rails/commands/plugin.rb', line 477 def quiet @quiet end |
Instance Method Details
- (Object) download(link)
517 518 519 520 521 522 523 524 |
# File 'railties/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 |
- (Object) fetch(links = @urls_to_fetch)
526 527 528 529 530 |
# File 'railties/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 |
- (Object) fetch_dir(url)
532 533 534 535 536 537 538 539 540 541 |
# File 'railties/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 |
- (Object) links(base_url, contents)
506 507 508 509 510 511 512 513 514 515 |
# File 'railties/lib/rails/commands/plugin.rb', line 506 def links(base_url, contents) links = [] contents.scan(/href\s*=\s*\"*[^\">]*/i) do |link| link = link.sub(/href="/i, "") next if link =~ /svnindex.xsl$/ next if link =~ /^(\w*:|)\/\// || link =~ /^\./ links << File.join(base_url, link) end links end |
- (Object) ls
485 486 487 488 489 490 491 492 493 494 495 |
# File 'railties/lib/rails/commands/plugin.rb', line 485 def ls @urls_to_fetch.collect do |url| if url =~ /^svn(\+ssh)?:\/\/.*/ `svn ls #{url}`.split("\n").map {|entry| "/#{entry}"} rescue nil else open(url) do |stream| links("", stream.read) end rescue nil end end.flatten end |
- (Object) pop_d
502 503 504 |
# File 'railties/lib/rails/commands/plugin.rb', line 502 def pop_d @cwd = File.dirname(@cwd) end |
- (Object) push_d(dir)
497 498 499 500 |
# File 'railties/lib/rails/commands/plugin.rb', line 497 def push_d(dir) @cwd = File.join(@cwd, dir) FileUtils.mkdir_p(@cwd) end |