downlow 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- data/downlow.gemspec +32 -34
- data/lib/downlow.rb +6 -6
- data/lib/downlow/ext/pathname.rb +6 -6
- data/lib/downlow/extractor.rb +9 -9
- data/lib/downlow/extractors/dir.rb +4 -4
- data/lib/downlow/extractors/tar_gz.rb +4 -4
- data/lib/downlow/extractors/zip.rb +4 -4
- data/lib/downlow/fetcher.rb +9 -9
- data/lib/downlow/fetchers/http.rb +5 -5
- data/lib/downlow/fetchers/local.rb +3 -4
- data/test/helper.rb +4 -4
- data/test/test_downlow.rb +8 -9
- data/test/test_downlow_extractor.rb +27 -27
- data/test/test_downlow_fetcher.rb +35 -35
- metadata +12 -7
- data/.gitignore +0 -23
data/downlow.gemspec
CHANGED
@@ -1,65 +1,63 @@
|
|
1
1
|
# Generated by jeweler
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{downlow}
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.4"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Aaron Quint"]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-11-21}
|
13
13
|
s.description = %q{Downlow provides an easy way to fetch files or archives and extract them with minimal hassle.}
|
14
14
|
s.email = %q{aaron@quirkey.com}
|
15
15
|
s.extra_rdoc_files = [
|
16
16
|
"LICENSE",
|
17
|
-
|
17
|
+
"README.rdoc"
|
18
18
|
]
|
19
19
|
s.files = [
|
20
20
|
".document",
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
"test/test_downlow_fetcher.rb"
|
21
|
+
"LICENSE",
|
22
|
+
"README.rdoc",
|
23
|
+
"Rakefile",
|
24
|
+
"downlow.gemspec",
|
25
|
+
"lib/downlow.rb",
|
26
|
+
"lib/downlow/ext/pathname.rb",
|
27
|
+
"lib/downlow/extractor.rb",
|
28
|
+
"lib/downlow/extractors/dir.rb",
|
29
|
+
"lib/downlow/extractors/tar_gz.rb",
|
30
|
+
"lib/downlow/extractors/zip.rb",
|
31
|
+
"lib/downlow/fetcher.rb",
|
32
|
+
"lib/downlow/fetchers/git.rb",
|
33
|
+
"lib/downlow/fetchers/github.rb",
|
34
|
+
"lib/downlow/fetchers/http.rb",
|
35
|
+
"lib/downlow/fetchers/local.rb",
|
36
|
+
"test/fixtures/gist_response",
|
37
|
+
"test/fixtures/location_response",
|
38
|
+
"test/fixtures/test.tar.gz",
|
39
|
+
"test/fixtures/test.zip",
|
40
|
+
"test/helper.rb",
|
41
|
+
"test/test_downlow.rb",
|
42
|
+
"test/test_downlow_extractor.rb",
|
43
|
+
"test/test_downlow_fetcher.rb"
|
45
44
|
]
|
46
45
|
s.homepage = %q{http://github.com/quirkey/downlow}
|
47
|
-
s.rdoc_options = ["--charset=UTF-8"]
|
48
46
|
s.require_paths = ["lib"]
|
49
|
-
s.rubygems_version = %q{1.3.
|
47
|
+
s.rubygems_version = %q{1.3.7}
|
50
48
|
s.summary = %q{easy downloading and extracting API}
|
51
49
|
s.test_files = [
|
52
50
|
"test/helper.rb",
|
53
|
-
|
54
|
-
|
55
|
-
|
51
|
+
"test/test_downlow.rb",
|
52
|
+
"test/test_downlow_extractor.rb",
|
53
|
+
"test/test_downlow_fetcher.rb"
|
56
54
|
]
|
57
55
|
|
58
56
|
if s.respond_to? :specification_version then
|
59
57
|
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
60
58
|
s.specification_version = 3
|
61
59
|
|
62
|
-
if Gem::Version.new(Gem::
|
60
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
63
61
|
s.add_runtime_dependency(%q<rubyzip>, [">= 0.9.4"])
|
64
62
|
s.add_runtime_dependency(%q<archive-tar-minitar>, [">= 0.5.2"])
|
65
63
|
s.add_development_dependency(%q<shoulda>, [">= 0"])
|
data/lib/downlow.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
require 'downlow/ext/pathname'
|
2
2
|
|
3
3
|
module Downlow
|
4
|
-
VERSION = '0.1.
|
5
|
-
|
4
|
+
VERSION = '0.1.4'
|
5
|
+
|
6
6
|
def self.get(url, *args)
|
7
7
|
options = {}
|
8
8
|
first = args.shift
|
@@ -23,15 +23,15 @@ module Downlow
|
|
23
23
|
FileUtils.rm_r(path) # delete tmp path
|
24
24
|
final_path
|
25
25
|
end
|
26
|
-
|
26
|
+
|
27
27
|
def self.fetch(*args)
|
28
28
|
Downlow::Fetcher.fetch(*args)
|
29
29
|
end
|
30
|
-
|
30
|
+
|
31
31
|
def self.extract(*args)
|
32
32
|
Downlow::Extractor.extract(*args)
|
33
33
|
end
|
34
|
-
|
34
|
+
|
35
35
|
end
|
36
36
|
|
37
37
|
def DL(*args) Downlow.get(*args); end
|
@@ -45,4 +45,4 @@ require 'downlow/fetchers/local'
|
|
45
45
|
require 'downlow/extractor'
|
46
46
|
require 'downlow/extractors/tar_gz'
|
47
47
|
require 'downlow/extractors/zip'
|
48
|
-
require 'downlow/extractors/dir'
|
48
|
+
require 'downlow/extractors/dir'
|
data/lib/downlow/ext/pathname.rb
CHANGED
@@ -44,7 +44,7 @@ class Pathname
|
|
44
44
|
return self+src.basename
|
45
45
|
end
|
46
46
|
end
|
47
|
-
|
47
|
+
|
48
48
|
# we assume this pathname object is a file obviously
|
49
49
|
def write content
|
50
50
|
raise "Will not overwrite #{to_s}" if exist? and not ARGV.force?
|
@@ -83,7 +83,7 @@ class Pathname
|
|
83
83
|
raise unless e.errno == Errno::ENOTEMPTY::Errno or e.errno == Errno::EACCES::Errno
|
84
84
|
false
|
85
85
|
end
|
86
|
-
|
86
|
+
|
87
87
|
def chmod_R perms
|
88
88
|
require 'fileutils'
|
89
89
|
FileUtils.chmod_R perms, to_s
|
@@ -111,7 +111,7 @@ class Pathname
|
|
111
111
|
# we only support numbered tagged downloads
|
112
112
|
%r[github.com/.*/tarball/((\d\.)+\d)$].match to_s
|
113
113
|
return $1 if $1
|
114
|
-
|
114
|
+
|
115
115
|
# eg. boost_1_39_0
|
116
116
|
/((\d+_)+\d+)$/.match stem
|
117
117
|
return $1.gsub('_', '.') if $1
|
@@ -120,7 +120,7 @@ class Pathname
|
|
120
120
|
# eg. ruby-1.9.1-p243
|
121
121
|
/-((\d+\.)*\d\.\d+-(p|rc)?\d+)$/.match stem
|
122
122
|
return $1 if $1
|
123
|
-
|
123
|
+
|
124
124
|
# eg. lame-398-1
|
125
125
|
/-((\d)+-\d)/.match stem
|
126
126
|
return $1 if $1
|
@@ -140,7 +140,7 @@ class Pathname
|
|
140
140
|
# eg. foobar4.5.1
|
141
141
|
/((\d+\.)*\d+)$/.match stem
|
142
142
|
return $1 if $1
|
143
|
-
|
143
|
+
|
144
144
|
# eg foobar-4.5.0-bin
|
145
145
|
/-((\d+\.)+\d+[abc]?)[-.](bin|src|sources?)$/.match stem
|
146
146
|
return $1 if $1
|
@@ -198,4 +198,4 @@ module ObserverPathnameExtension
|
|
198
198
|
end
|
199
199
|
|
200
200
|
$n=0
|
201
|
-
$d=0
|
201
|
+
$d=0
|
data/lib/downlow/extractor.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
module Downlow
|
2
2
|
class Extractor
|
3
|
-
|
3
|
+
|
4
4
|
def self.handles(which, options = {})
|
5
5
|
@@handlers ||= []
|
6
6
|
@@handlers << [which, options, self]
|
7
7
|
end
|
8
|
-
|
8
|
+
|
9
9
|
def self.extractor_for(path)
|
10
10
|
@@handlers.each do |matcher, options, klass|
|
11
11
|
if options[:file_only] && !File.file?(path)
|
@@ -15,17 +15,17 @@ module Downlow
|
|
15
15
|
end
|
16
16
|
end
|
17
17
|
end
|
18
|
-
|
18
|
+
|
19
19
|
def self.extract(url, options = {})
|
20
20
|
klass = extractor_for(url)
|
21
21
|
extractor = klass.new(url, options)
|
22
22
|
extractor.extract
|
23
23
|
extractor.final_path
|
24
24
|
end
|
25
|
-
|
25
|
+
|
26
26
|
attr_reader :path, :options, :final_path
|
27
27
|
attr_accessor :tmp_dir, :destination
|
28
|
-
|
28
|
+
|
29
29
|
def initialize(path, options = {})
|
30
30
|
@path = Pathname.new(path)
|
31
31
|
@options = options
|
@@ -33,14 +33,14 @@ module Downlow
|
|
33
33
|
@tmp_dir.mkpath
|
34
34
|
@destination = Pathname.new(options[:destination] || tmp_dir + self.path.stem).expand_path
|
35
35
|
end
|
36
|
-
|
36
|
+
|
37
37
|
def extract
|
38
38
|
raise "Should be overridden by subclass"
|
39
39
|
end
|
40
|
-
|
40
|
+
|
41
41
|
def extracted?
|
42
42
|
!!@final_path
|
43
43
|
end
|
44
|
-
|
44
|
+
|
45
45
|
end
|
46
|
-
end
|
46
|
+
end
|
@@ -1,8 +1,8 @@
|
|
1
1
|
module Downlow
|
2
2
|
class Dir < Extractor
|
3
|
-
|
3
|
+
|
4
4
|
handles(/.*$/)
|
5
|
-
|
5
|
+
|
6
6
|
def extract
|
7
7
|
if path.directory?
|
8
8
|
self.destination = destination + path.basename
|
@@ -13,6 +13,6 @@ module Downlow
|
|
13
13
|
path.cp destination
|
14
14
|
@final_path = destination
|
15
15
|
end
|
16
|
-
|
16
|
+
|
17
17
|
end
|
18
|
-
end
|
18
|
+
end
|
@@ -3,15 +3,15 @@ require 'archive/tar/minitar'
|
|
3
3
|
|
4
4
|
module Downlow
|
5
5
|
class TarGz < Extractor
|
6
|
-
|
6
|
+
|
7
7
|
handles(/\.tar\.gz$/, :file_only => true)
|
8
|
-
|
8
|
+
|
9
9
|
def extract
|
10
10
|
destination.mkpath
|
11
11
|
tgz = ::Zlib::GzipReader.new(File.open(path, 'rb'))
|
12
12
|
::Archive::Tar::Minitar.unpack(tgz, destination.to_s)
|
13
13
|
@final_path = destination
|
14
14
|
end
|
15
|
-
|
15
|
+
|
16
16
|
end
|
17
|
-
end
|
17
|
+
end
|
@@ -2,9 +2,9 @@ require 'zip/zip'
|
|
2
2
|
|
3
3
|
module Downlow
|
4
4
|
class Zip < Extractor
|
5
|
-
|
5
|
+
|
6
6
|
handles(/\.zip$/, :file_only => true)
|
7
|
-
|
7
|
+
|
8
8
|
def extract
|
9
9
|
::Zip::ZipFile.foreach(path) do |file|
|
10
10
|
path = destination + file.name
|
@@ -13,6 +13,6 @@ module Downlow
|
|
13
13
|
end
|
14
14
|
@final_path = destination
|
15
15
|
end
|
16
|
-
|
16
|
+
|
17
17
|
end
|
18
|
-
end
|
18
|
+
end
|
data/lib/downlow/fetcher.rb
CHANGED
@@ -1,27 +1,27 @@
|
|
1
1
|
module Downlow
|
2
2
|
class Fetcher
|
3
|
-
|
3
|
+
|
4
4
|
def self.handles(which)
|
5
5
|
@@handlers ||= []
|
6
6
|
@@handlers << [which, self]
|
7
7
|
end
|
8
|
-
|
8
|
+
|
9
9
|
def self.fetcher_for(url)
|
10
10
|
@@handlers.each do |matcher, klass|
|
11
11
|
return klass if matcher.match url
|
12
12
|
end
|
13
13
|
end
|
14
|
-
|
14
|
+
|
15
15
|
def self.fetch(url, options = {})
|
16
16
|
klass = fetcher_for(url)
|
17
17
|
fetcher = klass.new(url, options)
|
18
18
|
fetcher.fetch
|
19
19
|
fetcher.local_path
|
20
20
|
end
|
21
|
-
|
21
|
+
|
22
22
|
attr_reader :url, :options, :local_path
|
23
23
|
attr_accessor :tmp_dir, :destination
|
24
|
-
|
24
|
+
|
25
25
|
def initialize(url, options = {})
|
26
26
|
@url = Pathname.new(url)
|
27
27
|
@options = options
|
@@ -30,14 +30,14 @@ module Downlow
|
|
30
30
|
@destination = Pathname.new(options[:destination] || tmp_dir + self.url.basename ).expand_path
|
31
31
|
@destination.dirname.mkpath
|
32
32
|
end
|
33
|
-
|
33
|
+
|
34
34
|
def fetch
|
35
35
|
raise "Should be overridden by subclass"
|
36
36
|
end
|
37
|
-
|
37
|
+
|
38
38
|
def fetched?
|
39
39
|
!!@local_path
|
40
40
|
end
|
41
|
-
|
41
|
+
|
42
42
|
end
|
43
|
-
end
|
43
|
+
end
|
@@ -2,9 +2,9 @@ require 'open-uri'
|
|
2
2
|
|
3
3
|
module Downlow
|
4
4
|
class Http < Fetcher
|
5
|
-
|
6
|
-
handles(/^
|
7
|
-
|
5
|
+
|
6
|
+
handles(/^https?\:\/\//)
|
7
|
+
|
8
8
|
def fetch
|
9
9
|
data = ""
|
10
10
|
filename = destination.basename
|
@@ -22,6 +22,6 @@ module Downlow
|
|
22
22
|
File.open(destination, 'w') {|f| f << data }
|
23
23
|
@local_path = destination
|
24
24
|
end
|
25
|
-
|
25
|
+
|
26
26
|
end
|
27
|
-
end
|
27
|
+
end
|
data/test/helper.rb
CHANGED
@@ -8,19 +8,19 @@ $LOAD_PATH.unshift(File.dirname(__FILE__))
|
|
8
8
|
require 'downlow'
|
9
9
|
|
10
10
|
class Test::Unit::TestCase
|
11
|
-
|
11
|
+
|
12
12
|
def tmp_dir
|
13
13
|
dir = File.join('/tmp', 'downlow')
|
14
14
|
FileUtils.mkdir_p(dir)
|
15
15
|
dir
|
16
16
|
end
|
17
|
-
|
17
|
+
|
18
18
|
def fixture_path(path)
|
19
19
|
full_path = File.expand_path(File.join(File.dirname(__FILE__), 'fixtures', path))
|
20
20
|
end
|
21
|
-
|
21
|
+
|
22
22
|
def fixture(path)
|
23
23
|
File.read(fixture_path(path))
|
24
24
|
end
|
25
|
-
|
25
|
+
|
26
26
|
end
|
data/test/test_downlow.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
require 'helper'
|
2
2
|
|
3
3
|
class TestDownlow < Test::Unit::TestCase
|
4
|
-
|
4
|
+
|
5
5
|
context "Downlow" do
|
6
6
|
setup do
|
7
7
|
FileUtils.rm_rf(tmp_dir) if File.readable?(tmp_dir)
|
8
8
|
end
|
9
|
-
|
9
|
+
|
10
10
|
context ".get" do
|
11
11
|
should "fetch a gzip then extract it" do
|
12
12
|
url = 'http://example.org/example.tar.gz'
|
@@ -16,16 +16,16 @@ class TestDownlow < Test::Unit::TestCase
|
|
16
16
|
assert_match(/final/, path.to_s)
|
17
17
|
assert (path + 'test/test.jpg').readable?
|
18
18
|
end
|
19
|
-
|
19
|
+
|
20
20
|
should "assume string as second arg is destination" do
|
21
21
|
url = 'http://example.org/example.tar.gz'
|
22
22
|
FakeWeb.register_uri(:get, url, :body => fixture('test.tar.gz'))
|
23
23
|
path = Downlow.get(url, File.join(tmp_dir, 'final'))
|
24
24
|
assert path.is_a?(Pathname)
|
25
25
|
assert_match(/final/, path.to_s)
|
26
|
-
assert (path + 'test/test.jpg').readable?
|
26
|
+
assert (path + 'test/test.jpg').readable?
|
27
27
|
end
|
28
|
-
|
28
|
+
|
29
29
|
should "fetch a single file to a destination" do
|
30
30
|
url = 'http://example.org/example.js'
|
31
31
|
FakeWeb.register_uri(:get, url, :body => fixture('sammy.git/lib/sammy.js'))
|
@@ -34,17 +34,16 @@ class TestDownlow < Test::Unit::TestCase
|
|
34
34
|
assert_match(/final/, path.to_s)
|
35
35
|
assert path.file?
|
36
36
|
end
|
37
|
-
|
37
|
+
|
38
38
|
should "move a single file to a destination" do
|
39
39
|
path = Downlow.get(fixture_path('sammy.git/lib/sammy.js'), File.join(tmp_dir, 'final'))
|
40
40
|
assert path.is_a?(Pathname)
|
41
41
|
assert_match(/final/, path.to_s)
|
42
42
|
assert path.file?
|
43
43
|
end
|
44
|
-
|
44
|
+
|
45
45
|
end
|
46
|
-
|
46
|
+
|
47
47
|
end
|
48
48
|
|
49
49
|
end
|
50
|
-
|
@@ -1,117 +1,117 @@
|
|
1
1
|
require 'helper'
|
2
2
|
|
3
3
|
class TestDownlowExtractor < Test::Unit::TestCase
|
4
|
-
|
4
|
+
|
5
5
|
context "Downlow::Extractor" do
|
6
6
|
setup do
|
7
7
|
FileUtils.rm_rf(tmp_dir) if File.readable?(tmp_dir)
|
8
8
|
end
|
9
|
-
|
9
|
+
|
10
10
|
context ".extract" do
|
11
11
|
setup do
|
12
12
|
@path = fixture_path('test.zip')
|
13
13
|
@final_path = Downlow::Extractor.extract(@path, {:destination => tmp_dir})
|
14
14
|
end
|
15
|
-
|
15
|
+
|
16
16
|
should "extract the files" do
|
17
17
|
assert @final_path.is_a?(Pathname)
|
18
18
|
assert @final_path.directory?
|
19
19
|
assert_match(/tmp/, @final_path.to_s)
|
20
20
|
assert File.readable?(@final_path + 'test/test.jpg')
|
21
21
|
end
|
22
|
-
|
22
|
+
|
23
23
|
end
|
24
|
-
|
24
|
+
|
25
25
|
context ".extractor_for" do
|
26
|
-
|
26
|
+
|
27
27
|
should 'determine the fetcher by path' do
|
28
28
|
assert_equal Downlow::TarGz, Downlow::Extractor.extractor_for(fixture_path('test.tar.gz'))
|
29
29
|
assert_equal Downlow::Zip, Downlow::Extractor.extractor_for(fixture_path('test.zip'))
|
30
30
|
end
|
31
|
-
|
31
|
+
|
32
32
|
end
|
33
|
-
|
33
|
+
|
34
34
|
context "initializing" do
|
35
35
|
setup do
|
36
36
|
@path = fixture_path('test.zip')
|
37
37
|
@extractor = Downlow::Zip.new(@path, {:tmp_dir => tmp_dir})
|
38
38
|
end
|
39
|
-
|
39
|
+
|
40
40
|
should "set the path" do
|
41
41
|
assert_equal @path, @extractor.path.to_s
|
42
42
|
end
|
43
|
-
|
43
|
+
|
44
44
|
should "set the options" do
|
45
45
|
assert_equal tmp_dir, @extractor.options[:tmp_dir]
|
46
46
|
end
|
47
|
-
|
47
|
+
|
48
48
|
end
|
49
|
-
|
49
|
+
|
50
50
|
context "extract" do
|
51
|
-
|
51
|
+
|
52
52
|
context "zip" do
|
53
53
|
setup do
|
54
54
|
@extractor = Downlow::Zip.new(fixture_path('test.zip'), :destination => tmp_dir)
|
55
55
|
@path = @extractor.extract
|
56
56
|
end
|
57
|
-
|
57
|
+
|
58
58
|
should 'extract to the destination' do
|
59
59
|
assert @path.is_a?(Pathname)
|
60
60
|
assert @path.directory?
|
61
61
|
assert_match(/tmp/, @path.to_s)
|
62
62
|
assert (@path + 'test/test.jpg').readable?
|
63
63
|
end
|
64
|
-
|
64
|
+
|
65
65
|
should "set the local path" do
|
66
66
|
assert_equal @path, @extractor.final_path
|
67
67
|
end
|
68
|
-
|
68
|
+
|
69
69
|
end
|
70
|
-
|
71
|
-
|
70
|
+
|
71
|
+
|
72
72
|
context "tar.gz" do
|
73
73
|
setup do
|
74
74
|
@extractor = Downlow::TarGz.new(fixture_path('test.tar.gz'), :destination => tmp_dir)
|
75
75
|
@path = @extractor.extract
|
76
76
|
end
|
77
|
-
|
77
|
+
|
78
78
|
should 'extract to the destination' do
|
79
79
|
assert @path.is_a?(Pathname)
|
80
80
|
assert @path.directory?
|
81
81
|
assert_match(/tmp/, @path.to_s)
|
82
82
|
assert (@path + 'test/test.jpg').readable?
|
83
83
|
end
|
84
|
-
|
84
|
+
|
85
85
|
should "set the final_path" do
|
86
86
|
assert_equal @path, @extractor.final_path
|
87
87
|
end
|
88
88
|
end
|
89
|
-
|
89
|
+
|
90
90
|
context "dir" do
|
91
91
|
setup do
|
92
92
|
@extractor = Downlow::Dir.new(fixture_path(''), :destination => tmp_dir)
|
93
93
|
@path = @extractor.extract
|
94
94
|
end
|
95
|
-
|
95
|
+
|
96
96
|
should 'extract to the destination' do
|
97
97
|
assert @path.is_a?(Pathname)
|
98
98
|
assert @path.directory?
|
99
99
|
assert_match(/tmp/, @path.to_s)
|
100
100
|
assert (@path + 'test.tar.gz').readable?
|
101
101
|
end
|
102
|
-
|
102
|
+
|
103
103
|
should "set the final_path" do
|
104
104
|
assert_equal @path, @extractor.final_path
|
105
105
|
end
|
106
106
|
end
|
107
|
-
|
107
|
+
|
108
108
|
context "single file" do
|
109
109
|
setup do
|
110
110
|
@destination = File.join(tmp_dir, "sammy.js")
|
111
111
|
@extractor = Downlow::Dir.new(fixture_path('sammy.git/lib/sammy.js'), :destination => @destination)
|
112
112
|
@path = @extractor.extract
|
113
113
|
end
|
114
|
-
|
114
|
+
|
115
115
|
should 'extract to the exact destination' do
|
116
116
|
assert @path.is_a?(Pathname)
|
117
117
|
assert @path.file?
|
@@ -119,13 +119,13 @@ class TestDownlowExtractor < Test::Unit::TestCase
|
|
119
119
|
assert @path.readable?
|
120
120
|
assert_equal @destination, @path.to_s
|
121
121
|
end
|
122
|
-
|
122
|
+
|
123
123
|
should "set the final_path" do
|
124
124
|
assert_equal @path, @extractor.final_path
|
125
125
|
end
|
126
126
|
end
|
127
127
|
end
|
128
|
-
|
128
|
+
|
129
129
|
end
|
130
130
|
|
131
131
|
end
|
@@ -1,96 +1,96 @@
|
|
1
1
|
require 'helper'
|
2
2
|
|
3
3
|
class TestDownlowFetcher < Test::Unit::TestCase
|
4
|
-
|
4
|
+
|
5
5
|
context "Downlow::Fetcher" do
|
6
6
|
setup do
|
7
7
|
FileUtils.rm_rf(tmp_dir) if File.readable?(tmp_dir)
|
8
8
|
@url = 'http://github.com/quirkey/sammy/'
|
9
9
|
FakeWeb.register_uri(:get, @url, :body => 'quirkey.com Sammy')
|
10
10
|
end
|
11
|
-
|
11
|
+
|
12
12
|
context ".fetch" do
|
13
13
|
setup do
|
14
14
|
@path = Downlow::Fetcher.fetch(@url, {:tmp_dir => tmp_dir})
|
15
15
|
end
|
16
|
-
|
16
|
+
|
17
17
|
should "fetch the files" do
|
18
18
|
assert @path.is_a?(Pathname)
|
19
19
|
assert @path.file?
|
20
20
|
assert_match(/tmp/, @path.to_s)
|
21
21
|
assert_match(/quirkey/, @path.read)
|
22
22
|
end
|
23
|
-
|
23
|
+
|
24
24
|
end
|
25
|
-
|
25
|
+
|
26
26
|
context ".fetcher_for" do
|
27
|
-
|
27
|
+
|
28
28
|
should 'determine the fetcher by URL' do
|
29
29
|
assert_equal Downlow::Git, Downlow::Fetcher.fetcher_for('git://github.com/quirkey/sammy.git')
|
30
30
|
assert_equal Downlow::Http, Downlow::Fetcher.fetcher_for('http://github.com/quirkey/sammy/')
|
31
31
|
end
|
32
|
-
|
32
|
+
|
33
33
|
end
|
34
|
-
|
34
|
+
|
35
35
|
context "initializing" do
|
36
36
|
setup do
|
37
37
|
@url = 'http://github.com/quirkey/sammy/'
|
38
38
|
@fetcher = Downlow::Http.new(@url, {:tmp_dir => tmp_dir})
|
39
39
|
end
|
40
|
-
|
40
|
+
|
41
41
|
should "set the url" do
|
42
42
|
assert_equal @url, @fetcher.url.to_s
|
43
43
|
end
|
44
|
-
|
44
|
+
|
45
45
|
should "set the options" do
|
46
46
|
assert_equal tmp_dir, @fetcher.options[:tmp_dir]
|
47
47
|
end
|
48
|
-
|
48
|
+
|
49
49
|
end
|
50
|
-
|
50
|
+
|
51
51
|
context "fetch" do
|
52
|
-
|
52
|
+
|
53
53
|
context "git" do
|
54
54
|
setup do
|
55
55
|
class Downlow::Git
|
56
|
-
def git_clone
|
56
|
+
def git_clone
|
57
57
|
FileUtils.cp_r(File.join(File.dirname(__FILE__), 'fixtures', 'sammy.git'), destination)
|
58
58
|
end
|
59
59
|
end
|
60
60
|
@fetcher = Downlow::Git.new('git://github.com/quirkey/sammy.git', :tmp_dir => tmp_dir)
|
61
61
|
@path = @fetcher.fetch
|
62
62
|
end
|
63
|
-
|
63
|
+
|
64
64
|
should 'clone a git repo to the temp dir' do
|
65
65
|
assert @path.is_a?(Pathname)
|
66
66
|
assert @path.directory?
|
67
67
|
assert_match(/tmp/, @path.to_s)
|
68
68
|
assert (@path + 'lib/sammy.js').readable?
|
69
69
|
end
|
70
|
-
|
70
|
+
|
71
71
|
should "set the local path" do
|
72
72
|
assert_equal @path, @fetcher.local_path
|
73
73
|
end
|
74
|
-
|
74
|
+
|
75
75
|
end
|
76
|
-
|
76
|
+
|
77
77
|
context "http" do
|
78
78
|
setup do
|
79
79
|
@fetcher = Downlow::Http.new(@url, :tmp_dir => tmp_dir)
|
80
80
|
@path = @fetcher.fetch
|
81
81
|
end
|
82
|
-
|
82
|
+
|
83
83
|
should 'download the file to the temp dir' do
|
84
84
|
assert @path.is_a?(Pathname)
|
85
85
|
assert @path.file?
|
86
86
|
assert_match(/tmp/, @path.to_s)
|
87
87
|
assert_match(/quirkey/, @path.read)
|
88
88
|
end
|
89
|
-
|
89
|
+
|
90
90
|
should "set the local path" do
|
91
91
|
assert_equal @path, @fetcher.local_path
|
92
92
|
end
|
93
|
-
|
93
|
+
|
94
94
|
should "strip query-string when determining file name" do
|
95
95
|
gist_url = "http://github.com/malsup/form/raw/master/jquery.form.js?v2.38"
|
96
96
|
FakeWeb.register_uri(:get, gist_url, :body => "I'm just a normal file")
|
@@ -100,7 +100,7 @@ class TestDownlowFetcher < Test::Unit::TestCase
|
|
100
100
|
assert @path.file?
|
101
101
|
assert_match(/jquery.form.js$/, @path.to_s)
|
102
102
|
end
|
103
|
-
|
103
|
+
|
104
104
|
should "respect content-disposition headers" do
|
105
105
|
gist_url = "http://gist.github.com/gists/290151/download"
|
106
106
|
FakeWeb.register_uri(:get, gist_url, :response => fixture('gist_response'))
|
@@ -110,7 +110,7 @@ class TestDownlowFetcher < Test::Unit::TestCase
|
|
110
110
|
assert @path.file?
|
111
111
|
assert_match(/\.tar\.gz$/, @path.to_s)
|
112
112
|
end
|
113
|
-
|
113
|
+
|
114
114
|
should "respect location headers" do
|
115
115
|
url = "http://github.com/quirkey/lighthouse_stats/tarball/master"
|
116
116
|
location_url = "http://github.com/quirkey-lighthouse_stats-e9012c9.tar.gz"
|
@@ -122,11 +122,11 @@ class TestDownlowFetcher < Test::Unit::TestCase
|
|
122
122
|
assert @path.file?
|
123
123
|
assert_match(/\.tar\.gz$/, @path.to_s)
|
124
124
|
end
|
125
|
-
|
125
|
+
|
126
126
|
end
|
127
|
-
|
127
|
+
|
128
128
|
context "github" do
|
129
|
-
|
129
|
+
|
130
130
|
setup do
|
131
131
|
@url = 'gh://quirkey/sammy'
|
132
132
|
@real_url = "http://github.com/quirkey/sammy/tarball/master"
|
@@ -134,38 +134,38 @@ class TestDownlowFetcher < Test::Unit::TestCase
|
|
134
134
|
@fetcher = Downlow::Github.new(@url, :tmp_dir => tmp_dir)
|
135
135
|
@path = @fetcher.fetch
|
136
136
|
end
|
137
|
-
|
137
|
+
|
138
138
|
should "reset the url to the tarball url" do
|
139
139
|
assert_equal @real_url, @fetcher.url
|
140
|
-
end
|
140
|
+
end
|
141
141
|
end
|
142
|
-
|
142
|
+
|
143
143
|
context "file" do
|
144
144
|
setup do
|
145
145
|
@fetcher = Downlow::Local.new(File.join(File.dirname(__FILE__), '..', 'lib'), :tmp_dir => tmp_dir)
|
146
146
|
@path = @fetcher.fetch
|
147
147
|
end
|
148
|
-
|
148
|
+
|
149
149
|
should "move directory into temp dir" do
|
150
150
|
assert @path.is_a?(Pathname)
|
151
151
|
assert @path.directory?
|
152
152
|
assert_match(/tmp/, @path.to_s)
|
153
153
|
assert (@path + 'downlow.rb').readable?
|
154
154
|
end
|
155
|
-
|
155
|
+
|
156
156
|
should "set the local path" do
|
157
157
|
assert_equal @path, @fetcher.local_path
|
158
158
|
end
|
159
|
-
|
159
|
+
|
160
160
|
end
|
161
|
-
|
161
|
+
|
162
162
|
context "ftp" do
|
163
163
|
should_eventually "download via ftp" do
|
164
|
-
|
164
|
+
|
165
165
|
end
|
166
166
|
end
|
167
167
|
end
|
168
|
-
|
168
|
+
|
169
169
|
end
|
170
170
|
|
171
171
|
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
version: 0.1.
|
8
|
+
- 4
|
9
|
+
version: 0.1.4
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Aaron Quint
|
@@ -14,13 +14,14 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-
|
17
|
+
date: 2010-11-21 00:00:00 -08:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: rubyzip
|
22
22
|
prerelease: false
|
23
23
|
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
24
25
|
requirements:
|
25
26
|
- - ">="
|
26
27
|
- !ruby/object:Gem::Version
|
@@ -35,6 +36,7 @@ dependencies:
|
|
35
36
|
name: archive-tar-minitar
|
36
37
|
prerelease: false
|
37
38
|
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
38
40
|
requirements:
|
39
41
|
- - ">="
|
40
42
|
- !ruby/object:Gem::Version
|
@@ -49,6 +51,7 @@ dependencies:
|
|
49
51
|
name: shoulda
|
50
52
|
prerelease: false
|
51
53
|
requirement: &id003 !ruby/object:Gem::Requirement
|
54
|
+
none: false
|
52
55
|
requirements:
|
53
56
|
- - ">="
|
54
57
|
- !ruby/object:Gem::Version
|
@@ -61,6 +64,7 @@ dependencies:
|
|
61
64
|
name: fakeweb
|
62
65
|
prerelease: false
|
63
66
|
requirement: &id004 !ruby/object:Gem::Requirement
|
67
|
+
none: false
|
64
68
|
requirements:
|
65
69
|
- - ">="
|
66
70
|
- !ruby/object:Gem::Version
|
@@ -81,7 +85,6 @@ extra_rdoc_files:
|
|
81
85
|
- README.rdoc
|
82
86
|
files:
|
83
87
|
- .document
|
84
|
-
- .gitignore
|
85
88
|
- LICENSE
|
86
89
|
- README.rdoc
|
87
90
|
- Rakefile
|
@@ -110,11 +113,12 @@ homepage: http://github.com/quirkey/downlow
|
|
110
113
|
licenses: []
|
111
114
|
|
112
115
|
post_install_message:
|
113
|
-
rdoc_options:
|
114
|
-
|
116
|
+
rdoc_options: []
|
117
|
+
|
115
118
|
require_paths:
|
116
119
|
- lib
|
117
120
|
required_ruby_version: !ruby/object:Gem::Requirement
|
121
|
+
none: false
|
118
122
|
requirements:
|
119
123
|
- - ">="
|
120
124
|
- !ruby/object:Gem::Version
|
@@ -122,6 +126,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
122
126
|
- 0
|
123
127
|
version: "0"
|
124
128
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
129
|
+
none: false
|
125
130
|
requirements:
|
126
131
|
- - ">="
|
127
132
|
- !ruby/object:Gem::Version
|
@@ -131,7 +136,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
131
136
|
requirements: []
|
132
137
|
|
133
138
|
rubyforge_project:
|
134
|
-
rubygems_version: 1.3.
|
139
|
+
rubygems_version: 1.3.7
|
135
140
|
signing_key:
|
136
141
|
specification_version: 3
|
137
142
|
summary: easy downloading and extracting API
|