tori 0.6.6 → 0.7.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: e11c2e0db7bb0f1a6c31deecc5a07f21d38b8f56
4
- data.tar.gz: f6b4c1abe7704d7b6e0718993771cb7842ee9c7c
3
+ metadata.gz: 0d60157537bc5707d71835f133dbc0006b6151d9
4
+ data.tar.gz: 51cb59357eaf4282e9bb4b8121a2eafb2a54a66c
5
5
  SHA512:
6
- metadata.gz: 0bc44fe133ca9d2192066f6a01bd2f3f252f5994b48fa08b6614282fd7a96b56fcbab13dbafdb4ad7e05e6e9c281e92de7dc5e5f381bf0c3e874f3c6515972bf
7
- data.tar.gz: e051c4febe852bbc5f37f4978ee4cd67db08bbd561575b3affaabdd73d5cf1195c94e9ca4032ec5b3ada5c85551ab7548580db3c622c23bf81c6cbeaf8af230f
6
+ metadata.gz: 7b17ef8fe35a5237b4c49ddcbe20aa65e5c9d9c26e22800d4dc0b40450b87b964a394c860e52c721ee74218b46f30cdcc61e7175c6f3db01735f70e212c2dd2c
7
+ data.tar.gz: 095f0fca184b6eabd8f8ded81412c436785febe9d6c26e17669190134c9783f1e9fd9e58e69ad132ed9e9bf82e48b8dfb61d18edfa9b8e902b69bfecda022176
data/README.md CHANGED
@@ -121,29 +121,6 @@ class PhotoController < ApplicationController
121
121
  end
122
122
  ```
123
123
 
124
- # Custom configure example
125
-
126
- ```ruby
127
- # Save to S3 bucket.
128
- require 'tori/backend/s3'
129
- Tori.config.backend = Tori::Backend::S3.new(bucket: 'tori_bucket')
130
-
131
- # Filename decided by model.class.name,id and hidden words.
132
- Tori.config.filename_callback do |model|
133
- "#{model.class.name}/#{Digest::SHA1.hexdigest "#{ENV["TORI_MAGICKWORD"]}/#{model.id}"}"
134
- end
135
-
136
- # You can change any way define filename.
137
- Tori.config.filename_callback do |model|
138
- # `__tori__` method is meta name of defined by `tori` method.
139
- "#{model.class.name}/#{__tori__}/#{model.title}"
140
- # class Photo
141
- # tori :orig #=> "Photo/orig/cool-shot.png"
142
- # tori :strip #=> "Photo/strip/cool-shot.png"
143
- # end
144
- end
145
- ```
146
-
147
124
  # Default configure
148
125
 
149
126
  [https://github.com/ksss/tori/blob/master/lib/tori.rb](https://github.com/ksss/tori/blob/master/lib/tori.rb)
@@ -45,14 +45,31 @@ module Tori
45
45
  end
46
46
  alias exists? exist?
47
47
 
48
- def read(filename, **args)
49
- ::File.read(path(filename), { mode: 'rb' }.merge(args))
48
+ def read(filename, *args)
49
+ if args.last.kind_of?(Hash)
50
+ opt = args.pop
51
+ else
52
+ opt = {}
53
+ end
54
+ open(filename, {mode: 'rb'}.merge(opt)) do |f|
55
+ f.read(*args)
56
+ end
50
57
  end
51
58
 
52
59
  def open(filename, *rest, &block)
53
60
  ::File.open(path(filename), *rest, &block)
54
61
  end
55
62
 
63
+ def copy_to(filename, tori_file, **opts)
64
+ FileUtils.mkdir_p tori_file.path.dirname
65
+
66
+ ::File.open(path(filename)) do |from|
67
+ ::File.open(tori_file.path, 'w+') do |to|
68
+ IO.copy_stream(from, to)
69
+ end
70
+ end
71
+ end
72
+
56
73
  def path(filename)
57
74
  @root.join filename.to_s
58
75
  end
@@ -57,6 +57,10 @@ module Tori
57
57
  opts[:content_type] = self.class.type_for(from_path)
58
58
  end
59
59
 
60
+ if resource.nil? && opts[:body]
61
+ resource = opts[:body]
62
+ end
63
+
60
64
  case resource
61
65
  when String
62
66
  put_object({
@@ -121,6 +125,15 @@ module Tori
121
125
  end
122
126
  end
123
127
 
128
+ def copy_to(filename, tori_file, **opts)
129
+ copy_object(
130
+ copy_source: "#{bucket}/#{filename}",
131
+ bucket: backend.bucket,
132
+ key: tori_file.name,
133
+ **opts,
134
+ )
135
+ end
136
+
124
137
  def public_url(filename)
125
138
  "#{client.config.endpoint}/#{@bucket}/#{filename}"
126
139
  end
@@ -169,6 +182,10 @@ module Tori
169
182
  def delete_object(opts={})
170
183
  client.delete_object bucket: @bucket, **opts
171
184
  end
185
+
186
+ def copy_object(opts = {})
187
+ client.copy_object bucket: @bucket, **opts
188
+ end
172
189
  end
173
190
  end
174
191
  end
data/lib/tori/config.rb CHANGED
@@ -8,6 +8,8 @@ module Tori
8
8
 
9
9
  def filename_callback(&block)
10
10
  if block_given?
11
+ warn "DEPRECATED: `#{__method__}' is deprecated method."
12
+ warn "Please use `tori` method block style in model like `tori :name, { |model| model.id }`."
11
13
  @filename_callback = block
12
14
  else
13
15
  @filename_callback
data/lib/tori/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Tori
2
- VERSION = "0.6.6"
2
+ VERSION = "0.7.0"
3
3
  end
@@ -34,6 +34,7 @@ class TestToriBackendFileSystem < Test::Unit::TestCase
34
34
  File.open(@filesystem.root.join("utf8file"), 'wb') { |f| f.write utf8 }
35
35
  assert { utf8 != @filesystem.read("utf8file") }
36
36
  assert { utf8 == @filesystem.read("utf8file", external_encoding: Encoding::UTF_8) }
37
+ assert { "\xE3".b == @filesystem.read("utf8file", 1) }
37
38
 
38
39
  assert { Encoding::ASCII_8BIT == @filesystem.read("binfile").encoding }
39
40
  assert { Encoding::UTF_8 == @filesystem.read("binfile", external_encoding: Encoding::UTF_8).encoding }
@@ -18,7 +18,7 @@ class TestToriFile < Test::Unit::TestCase
18
18
  def rewind
19
19
  end
20
20
 
21
- def read
21
+ def read(*)
22
22
  __FILE__
23
23
  end
24
24
  end
@@ -57,6 +57,14 @@ class TestToriFile < Test::Unit::TestCase
57
57
  assert { true == File.exist?("test/tmp/copy") }
58
58
  end
59
59
 
60
+ test "write with body" do
61
+ assert { false == File.exist?("test/tmp/copy") }
62
+ Tori::File.new("copy").write(
63
+ body: From.new,
64
+ )
65
+ assert { true == File.exist?("test/tmp/copy") }
66
+ end
67
+
60
68
  test "backend" do
61
69
  assert { Tori.config.backend == Tori::File.new(nil).backend }
62
70
  end
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.6
4
+ version: 0.7.0
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-29 00:00:00.000000000 Z
11
+ date: 2016-06-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk-core
@@ -132,7 +132,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
132
132
  version: '0'
133
133
  requirements: []
134
134
  rubyforge_project:
135
- rubygems_version: 2.6.1
135
+ rubygems_version: 2.6.4
136
136
  signing_key:
137
137
  specification_version: 4
138
138
  summary: Simple file uploader