tori 0.0.9 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +2 -0
- data/lib/tori/backend/filesystem.rb +1 -1
- data/lib/tori/backend/s3.rb +18 -4
- data/lib/tori/file.rb +2 -2
- data/lib/tori/version.rb +1 -1
- data/test/test_tori_backend_s3.rb +25 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ba8a418f17265ffd2b81e4545a5bd47729af267a
|
4
|
+
data.tar.gz: fbce0ab36e74cd56a2febdfe2fd91bd06bdd4b90
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1085709277defe46b902ebbb0a00b660d8bab9f62769cb54dc493bd37ef4732cf664a29160be6ca7b08c03a04a1b1d1643d1c15cd8c8b482c6da17f3c5a8565c
|
7
|
+
data.tar.gz: 8695d363d39f5ff6fd5daed438151525a16ea0dad2e43fa7df10f69a4354ddf17c5b3f4925956338ab752df47614f9fbd475d317a9a90be904d6999dfc010811
|
data/.travis.yml
CHANGED
data/lib/tori/backend/s3.rb
CHANGED
@@ -17,18 +17,32 @@ module Tori
|
|
17
17
|
@client = nil
|
18
18
|
end
|
19
19
|
|
20
|
-
def write(filename, resource)
|
20
|
+
def write(filename, resource, opts = nil)
|
21
|
+
opts ||= {}
|
21
22
|
case resource
|
22
23
|
when String
|
23
|
-
put_object
|
24
|
+
put_object({
|
25
|
+
key: filename,
|
26
|
+
body: resource,
|
27
|
+
content_type: DEFAULT_CONTENT_TYPE,
|
28
|
+
}.merge(opts))
|
24
29
|
when File, Pathname
|
25
30
|
path = resource.to_path
|
26
31
|
content_type = MIME::Types.type_for(path).first || DEFAULT_CONTENT_TYPE
|
27
32
|
::File.open(path) { |f|
|
28
|
-
put_object
|
33
|
+
put_object({
|
34
|
+
key: filename,
|
35
|
+
body: f,
|
36
|
+
content_type: content_type.to_s,
|
37
|
+
content_length: f.size,
|
38
|
+
}.merge(opts))
|
29
39
|
}
|
30
40
|
else
|
31
|
-
put_object
|
41
|
+
put_object({
|
42
|
+
key: filename,
|
43
|
+
body: resource,
|
44
|
+
content_type: DEFAULT_CONTENT_TYPE,
|
45
|
+
}.merge(opts))
|
32
46
|
end
|
33
47
|
end
|
34
48
|
|
data/lib/tori/file.rb
CHANGED
@@ -19,10 +19,10 @@ module Tori
|
|
19
19
|
!@from.nil? && @from.respond_to?(:path)
|
20
20
|
end
|
21
21
|
|
22
|
-
def write
|
22
|
+
def write(opts = nil)
|
23
23
|
path = @from.path
|
24
24
|
path = Pathname.new(path) if path.kind_of?(String)
|
25
|
-
Tori.config.backend.write name, path
|
25
|
+
Tori.config.backend.write name, path, opts
|
26
26
|
end
|
27
27
|
|
28
28
|
def delete
|
data/lib/tori/version.rb
CHANGED
@@ -5,6 +5,14 @@ if ENV["TORI_TEST_BUCKET"]
|
|
5
5
|
|
6
6
|
class TestToriBackendS3 < Test::Unit::TestCase
|
7
7
|
BucketNotFoundError = Class.new(StandardError)
|
8
|
+
def request_head(url)
|
9
|
+
uri = URI.parse(url)
|
10
|
+
req = Net::HTTP::Head.new(uri.path)
|
11
|
+
Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == 'https') { |http|
|
12
|
+
http.request req
|
13
|
+
}
|
14
|
+
end
|
15
|
+
|
8
16
|
setup do
|
9
17
|
@backend = Tori::Backend::S3.new(bucket: ENV["TORI_TEST_BUCKET"])
|
10
18
|
fail BucketNotFoundError, "S3 test need make s3 bucket '#{@backend.bucket}'" unless @backend.exists?
|
@@ -31,12 +39,27 @@ class TestToriBackendS3 < Test::Unit::TestCase
|
|
31
39
|
end
|
32
40
|
end
|
33
41
|
|
34
|
-
test "#write" do
|
42
|
+
test "#write String" do
|
43
|
+
@backend.write("testfile", "foo", content_type: "image/png")
|
44
|
+
testfile = @backend.get_object(key: "testfile")
|
45
|
+
assert { "image/png" == testfile.content_type }
|
46
|
+
assert { "foo" == testfile[:body].read }
|
47
|
+
end
|
48
|
+
|
49
|
+
test "#write Pathname" do
|
35
50
|
assert_nothing_raised { @backend.write("testfile", @testfile_path) }
|
36
51
|
testfile = @backend.get_object(key: "testfile")
|
37
|
-
assert { "plain
|
52
|
+
assert { "text/plain" == testfile.content_type }
|
38
53
|
assert { 4 == testfile.content_length }
|
39
54
|
assert { "text" == testfile[:body].read }
|
55
|
+
|
56
|
+
@backend.write("testfile", @testfile_path, acl: "public-read-write")
|
57
|
+
res = request_head(@backend.public_url("testfile"))
|
58
|
+
assert { Net::HTTPOK === res}
|
59
|
+
|
60
|
+
@backend.write("testfile", @testfile_path, acl: "private")
|
61
|
+
res = request_head(@backend.public_url("testfile"))
|
62
|
+
assert { Net::HTTPForbidden === res}
|
40
63
|
end
|
41
64
|
|
42
65
|
test "#read" do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tori
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ksss
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-07-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aws-sdk-core
|