tori 0.2.0 → 0.3.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: 00e78b51cb71ee2dae463df6a3b2bc3518c9d4b1
4
- data.tar.gz: a451f2d4fd7cdc7b4dcf15d4792a8ce36bbaabe7
3
+ metadata.gz: 7f9e73b59d43f6d816af38e163263f8ad366b29f
4
+ data.tar.gz: 61c1bfa6790ebf0b8f5e9ee6aa967c2a56d4150f
5
5
  SHA512:
6
- metadata.gz: 9e0474b601c7e5b5c9ecc9a53b8218eed8e39b8ae768527894f1eed5e28b2e10387dcebccf9a89d11e46fc8d5937495ba63997504648cbcb3d8456319595ea1e
7
- data.tar.gz: 8f3dfe3d4309f8528129a341805c881fcfb3d23139ac9357cbaefbc41990ab892f3be9992730125e6ea2b057840b0ff3e58d3a2d4603bafb7b63c61dce3ed717
6
+ metadata.gz: 62cf0872b2c0798d92a223c45badb6a7665bbddf923af5b42ef3e24588a081632b4e26805cbfde96092899c3fb8ea4730288a6e28fb68dccfd66c4d7c90f17e9
7
+ data.tar.gz: c95fe43b976782cc20085f1ef00a562bd3b3eba620d6c13ecc66c6c19909dcbb1680f4962f4b1444dbbb0d26e930aae77211ce3944be51ff97e84d2f1142392b
@@ -10,17 +10,19 @@ module Tori
10
10
  def write(filename, resource, opts = nil)
11
11
  case resource
12
12
  when String
13
- ::File.open(path(filename), 'w'){ |f| f.write resource }
13
+ ::File.open(path(filename), 'wb'){ |f| f.write resource }
14
14
  when Pathname
15
15
  # see also https://bugs.ruby-lang.org/issues/11199
16
16
  ::File.open(resource) { |src|
17
17
  FileUtils.mkdir_p path(filename).dirname
18
- ::File.open(path(filename), 'w'){ |dst|
18
+ ::File.open(path(filename), 'wb'){ |dst|
19
19
  ::IO.copy_stream src, dst
20
20
  }
21
21
  }
22
22
  else
23
- ::IO.copy_stream resource, path(filename)
23
+ ::File.open(path(filename), 'wb') do |dst|
24
+ ::IO.copy_stream resource, dst
25
+ end
24
26
  end
25
27
  end
26
28
 
@@ -34,7 +36,7 @@ module Tori
34
36
  alias exists? exist?
35
37
 
36
38
  def read(filename)
37
- ::File.read path(filename)
39
+ ::File.read(path(filename), mode: 'rb')
38
40
  end
39
41
 
40
42
  def path(filename)
@@ -14,6 +14,15 @@ module Tori
14
14
  #
15
15
  # example:
16
16
  # Tori.config.backend = Tori::Backend::S3.new(bucket: 'tori_bucket')
17
+ # # or
18
+ # Tori.config.backend = Tori::Backend::S3.new(
19
+ # bucket: 'tori_bucket',
20
+ # client: Aws::S3::Client.new(
21
+ # access_key_id: 'your_access_key',
22
+ # secret_access_key: 'your_secret_access_key',
23
+ # region: 'your-region-1'
24
+ # )
25
+ # )
17
26
  def initialize(bucket:, client: nil)
18
27
  @bucket = bucket
19
28
  if client
@@ -2,7 +2,12 @@ module Tori
2
2
  class File
3
3
  def initialize(model, from: nil, &block)
4
4
  @model = model
5
- @from = from
5
+ if from.respond_to?(:read) and from.respond_to?(:rewind)
6
+ from.rewind
7
+ @from = from.read
8
+ else
9
+ @from = from
10
+ end
6
11
  @filename_callback = block
7
12
  end
8
13
 
@@ -16,13 +21,11 @@ module Tori
16
21
  alias to_s name
17
22
 
18
23
  def from?
19
- !@from.nil? && @from.respond_to?(:path)
24
+ !@from.nil?
20
25
  end
21
26
 
22
27
  def write(opts = nil)
23
- path = @from.path
24
- path = Pathname.new(path) if path.kind_of?(String)
25
- Tori.config.backend.write name, path, opts
28
+ Tori.config.backend.write name, @from, opts
26
29
  end
27
30
 
28
31
  def delete
@@ -1,3 +1,3 @@
1
1
  module Tori
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
@@ -24,6 +24,9 @@ class TestToriBackendFileSystem < Test::Unit::TestCase
24
24
  test "#read" do
25
25
  assert { "text" == @filesystem.read("testfile") }
26
26
  assert_raise(Errno::ENOENT){ @filesystem.read("nothing_file") }
27
+ bin = (0..0xFF).to_a.pack("c*")
28
+ File.open(@filesystem.root.join("binfile"), 'wb'){ |f| f.write bin }
29
+ assert { bin == @filesystem.read("binfile") }
27
30
  end
28
31
 
29
32
  test "#path" do
@@ -42,6 +45,10 @@ class TestToriBackendFileSystem < Test::Unit::TestCase
42
45
  @filesystem.write("copyfile", "string")
43
46
  assert { "string" == @filesystem.read("copyfile") }
44
47
 
48
+ bin = (0..0xFF).to_a.pack("c*")
49
+ @filesystem.write("binfile", bin)
50
+ assert { bin == @filesystem.read("binfile") }
51
+
45
52
  @filesystem.write(Pathname.new("copyfile"), @filesystem.path("testfile"))
46
53
  assert { "text" == @filesystem.read("copyfile") }
47
54
 
@@ -15,7 +15,10 @@ class TestToriFile < Test::Unit::TestCase
15
15
  end
16
16
 
17
17
  class From
18
- def path
18
+ def rewind
19
+ end
20
+
21
+ def read
19
22
  __FILE__
20
23
  end
21
24
  end
@@ -47,6 +50,21 @@ class TestToriFile < Test::Unit::TestCase
47
50
  assert { true == File.exist?("test/tmp/copy") }
48
51
  end
49
52
 
53
+ test "write with closed file" do
54
+ tori_file = nil
55
+ path = nil
56
+ Tempfile.create("tempfile") do |f|
57
+ path = f.path
58
+ f.write("should be match ;)")
59
+ tori_file = Tori::File.new("tempfile", from: f)
60
+ end
61
+ tori_file.write
62
+ assert { true == File.exist?("test/tmp/tempfile") }
63
+ assert { false == File.exist?(path) }
64
+ assert { "should be match ;)" == File.read("test/tmp/tempfile") }
65
+ assert { "should be match ;)" == tori_file.read }
66
+ end
67
+
50
68
  test "#method_missing" do
51
69
  assert { true == Tori::File.new(nil).respond_to?(:read) }
52
70
  assert_raise(NameError) { Tori::File.new(nil).undefined }
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.2.0
4
+ version: 0.3.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-09-18 00:00:00.000000000 Z
11
+ date: 2015-09-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk-core