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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3e50f43aa37d6ed820e9cc05f6109098afa10a24
4
- data.tar.gz: eee5148dcf9c70b91ade06ea3590d4b11aa54c8f
3
+ metadata.gz: ba8a418f17265ffd2b81e4545a5bd47729af267a
4
+ data.tar.gz: fbce0ab36e74cd56a2febdfe2fd91bd06bdd4b90
5
5
  SHA512:
6
- metadata.gz: 62e61605a2a75da736cac9e063463ad95709fe01011677f3910ba371508f674ce4f822c463df7f1f0d4a3acdca446a7a317f31f1be6a1e4aafff92671649d02f
7
- data.tar.gz: 5bf1624b4371d24b319a4f7b7ca9897a04d9f89cd37e4c2c08dff6be52fb6400984fe77c33f5a6648ee14c7298042c7231cdd75e60779921a788139724e76acd
6
+ metadata.gz: 1085709277defe46b902ebbb0a00b660d8bab9f62769cb54dc493bd37ef4732cf664a29160be6ca7b08c03a04a1b1d1643d1c15cd8c8b482c6da17f3c5a8565c
7
+ data.tar.gz: 8695d363d39f5ff6fd5daed438151525a16ea0dad2e43fa7df10f69a4354ddf17c5b3f4925956338ab752df47614f9fbd475d317a9a90be904d6999dfc010811
data/.travis.yml CHANGED
@@ -2,3 +2,5 @@ language: ruby
2
2
  rvm:
3
3
  - 2.1.6
4
4
  - 2.2.2
5
+ notifications:
6
+ email: false
@@ -7,7 +7,7 @@ module Tori
7
7
  FileUtils.mkdir_p @root.to_s
8
8
  end
9
9
 
10
- def write(filename, resource)
10
+ def write(filename, resource, opts = nil)
11
11
  case resource
12
12
  when String
13
13
  ::File.open(path(filename), 'w'){ |f| f.write resource }
@@ -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 key: filename, body: resource, content_type: DEFAULT_CONTENT_TYPE
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 key: filename, body: f, content_type: content_type.to_s, content_length: f.size
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 key: filename, body: resource
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
@@ -1,3 +1,3 @@
1
1
  module Tori
2
- VERSION = "0.0.9"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -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/text" == testfile.content_type }
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.9
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-06-29 00:00:00.000000000 Z
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