tori 0.6.5 → 0.6.6

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: ef7b4999b8e45c9a0dc01694ed2d959d17937605
4
- data.tar.gz: cc3f86d2242538bbe8dd0e6014d2df4ba2078c6f
3
+ metadata.gz: e11c2e0db7bb0f1a6c31deecc5a07f21d38b8f56
4
+ data.tar.gz: f6b4c1abe7704d7b6e0718993771cb7842ee9c7c
5
5
  SHA512:
6
- metadata.gz: e613f73fcfb2195a1f3635527be1a60e2627bc0db7c1c39f10056d35c970f3683666519cb4d3afecde4e69faff43df83a089ae0e9ef31fb2f84e5fa772827799
7
- data.tar.gz: e7c63029df20ff69d6def1c69bbe38ea7f2c27bb1a2afe4d8fe417851bf8de84f15709802e64e7e7c0fec9e9d2bc5a48ee5779cb3560990029c1d026fff820d5
6
+ metadata.gz: 0bc44fe133ca9d2192066f6a01bd2f3f252f5994b48fa08b6614282fd7a96b56fcbab13dbafdb4ad7e05e6e9c281e92de7dc5e5f381bf0c3e874f3c6515972bf
7
+ data.tar.gz: e051c4febe852bbc5f37f4978ee4cd67db08bbd561575b3affaabdd73d5cf1195c94e9ca4032ec5b3ada5c85551ab7548580db3c622c23bf81c6cbeaf8af230f
@@ -1,6 +1,8 @@
1
1
  module Tori
2
2
  module Backend
3
3
  class FileSystem
4
+ ResourceError = Class.new(StandardError)
5
+
4
6
  attr_accessor :root
5
7
  def initialize(root)
6
8
  @root = root
@@ -11,6 +13,10 @@ module Tori
11
13
  pathname = path(filename)
12
14
  FileUtils.mkdir_p pathname.dirname
13
15
 
16
+ if resource.nil? && opts && opts[:body]
17
+ resource = opts[:body]
18
+ end
19
+
14
20
  case resource
15
21
  when String
16
22
  ::File.open(pathname, 'wb'){ |f| f.write resource }
@@ -21,6 +27,8 @@ module Tori
21
27
  ::IO.copy_stream src, dst
22
28
  }
23
29
  }
30
+ when NilClass
31
+ raise ResourceError, "null resource"
24
32
  else
25
33
  ::File.open(pathname, 'wb') do |dst|
26
34
  ::IO.copy_stream resource, dst
@@ -113,9 +113,9 @@ module Tori
113
113
  put_object key: filename, body: body, **opts
114
114
  end
115
115
 
116
- def head(filename = nil)
116
+ def head(filename = nil, **opts)
117
117
  if filename
118
- head_object key: filename
118
+ head_object key: filename, **opts
119
119
  else
120
120
  head_bucket
121
121
  end
data/lib/tori/file.rb CHANGED
@@ -38,10 +38,6 @@ module Tori
38
38
  !@from.nil?
39
39
  end
40
40
 
41
- def read
42
- backend.read name
43
- end
44
-
45
41
  def write(opts = nil)
46
42
  opts ||= {}
47
43
  backend.write name, @from, opts.merge(from_path: @from_path)
@@ -73,7 +69,7 @@ module Tori
73
69
  if respond_to_missing?(sym, false)
74
70
  backend.__send__ sym, name, *args, &block
75
71
  else
76
- fail NameError, "undefined method `#{sym}' for #{Tori.config.backend.inspect}"
72
+ raise NameError, "undefined method `#{sym}' for #{backend}"
77
73
  end
78
74
  end
79
75
  end
data/lib/tori/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Tori
2
- VERSION = "0.6.5"
2
+ VERSION = "0.6.6"
3
3
  end
@@ -25,9 +25,16 @@ class TestToriBackendFileSystem < Test::Unit::TestCase
25
25
  test "#read" do
26
26
  assert { "text" == @filesystem.read("testfile") }
27
27
  assert_raise(Errno::ENOENT){ @filesystem.read("nothing_file") }
28
+
28
29
  bin = (0..0xFF).to_a.pack("c*")
29
- File.open(@filesystem.root.join("binfile"), 'wb'){ |f| f.write bin }
30
+ File.open(@filesystem.root.join("binfile"), 'wb') { |f| f.write bin }
30
31
  assert { bin == @filesystem.read("binfile") }
32
+
33
+ utf8 = "こんにちは世界"
34
+ File.open(@filesystem.root.join("utf8file"), 'wb') { |f| f.write utf8 }
35
+ assert { utf8 != @filesystem.read("utf8file") }
36
+ assert { utf8 == @filesystem.read("utf8file", external_encoding: Encoding::UTF_8) }
37
+
31
38
  assert { Encoding::ASCII_8BIT == @filesystem.read("binfile").encoding }
32
39
  assert { Encoding::UTF_8 == @filesystem.read("binfile", external_encoding: Encoding::UTF_8).encoding }
33
40
  end
@@ -48,6 +55,16 @@ class TestToriBackendFileSystem < Test::Unit::TestCase
48
55
  @filesystem.write("copyfile", "string")
49
56
  assert { "string" == @filesystem.read("copyfile") }
50
57
 
58
+ assert_raise(Tori::Backend::FileSystem::ResourceError) do
59
+ @filesystem.write("copyfile", nil)
60
+ end
61
+
62
+ @filesystem.write("copyfile", nil, body: "S3 compatible API")
63
+ assert { "S3 compatible API" == @filesystem.read("copyfile") }
64
+
65
+ @filesystem.write("copyfile", "resource is priority", body: "S3 compatible API")
66
+ assert { "resource is priority" == @filesystem.read("copyfile") }
67
+
51
68
  bin = (0..0xFF).to_a.pack("c*")
52
69
  @filesystem.write("binfile", bin)
53
70
  assert { bin == @filesystem.read("binfile") }
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.6.5
4
+ version: 0.6.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - ksss
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-17 00:00:00.000000000 Z
11
+ date: 2016-03-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk-core