remote_files 1.6.1 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +11 -0
- data/lib/remote_files/file_store.rb +8 -2
- data/lib/remote_files/memory_store.rb +2 -1
- data/lib/remote_files/version.rb +1 -1
- data/test/file_store_test.rb +28 -6
- data/test/memory_store_test.rb +26 -4
- metadata +9 -8
data/README.md
CHANGED
@@ -77,6 +77,17 @@ This will store the file on one of the stores and then asynchronously copy the f
|
|
77
77
|
If you just need to store the file in a single store, the you can use `RemoteFiles::File#store_once!`. It will
|
78
78
|
behave exactly like `RemoteFiles::File#store!`, but will not asynchronously copy the file to the other stores.
|
79
79
|
|
80
|
+
## Copyright and license
|
81
|
+
|
82
|
+
Copyright 2013 Zendesk
|
83
|
+
|
84
|
+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
|
85
|
+
You may obtain a copy of the License at
|
86
|
+
|
87
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
88
|
+
|
89
|
+
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
|
90
|
+
|
80
91
|
## Contributing
|
81
92
|
|
82
93
|
1. Fork it
|
@@ -19,8 +19,14 @@ module RemoteFiles
|
|
19
19
|
FileUtils.mkdir_p(file_name.parent)
|
20
20
|
|
21
21
|
file_name.open('w') do |f|
|
22
|
-
|
23
|
-
|
22
|
+
if file.content.respond_to?(:read)
|
23
|
+
while blk = file.content.read(2048)
|
24
|
+
f << blk
|
25
|
+
end
|
26
|
+
else
|
27
|
+
f.write(file.content)
|
28
|
+
# what about content-type?
|
29
|
+
end
|
24
30
|
end
|
25
31
|
end
|
26
32
|
|
@@ -21,7 +21,8 @@ module RemoteFiles
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def store!(file)
|
24
|
-
|
24
|
+
content = file.content.respond_to?(:read) ? file.content.read : file.content
|
25
|
+
data[file.identifier] = { :content => content, :content_type => file.content_type}
|
25
26
|
end
|
26
27
|
|
27
28
|
def retrieve!(identifier)
|
data/lib/remote_files/version.rb
CHANGED
data/test/file_store_test.rb
CHANGED
@@ -11,16 +11,38 @@ describe RemoteFiles::FileStore do
|
|
11
11
|
|
12
12
|
describe '#store!' do
|
13
13
|
before do
|
14
|
-
@file = RemoteFiles::File.new('foo/identifier', :content_type => 'text/plain', :content =>
|
14
|
+
@file = RemoteFiles::File.new('foo/identifier', :content_type => 'text/plain', :content => content)
|
15
15
|
end
|
16
16
|
|
17
|
-
|
18
|
-
|
17
|
+
def self.it_should_store_file
|
18
|
+
it 'should store the file on disk' do
|
19
|
+
@store.store!(@file)
|
19
20
|
|
20
|
-
|
21
|
-
|
21
|
+
file_path = @directory + 'foo/identifier'
|
22
|
+
file_path.exist?
|
22
23
|
|
23
|
-
|
24
|
+
assert_equal 'content', file_path.read
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe "content = string" do
|
29
|
+
let(:content) { "content" }
|
30
|
+
it_should_store_file
|
31
|
+
end
|
32
|
+
|
33
|
+
describe "content = stringio" do
|
34
|
+
let(:content) { StringIO.new("content") }
|
35
|
+
it_should_store_file
|
36
|
+
end
|
37
|
+
|
38
|
+
describe "content = io" do
|
39
|
+
let(:content) do
|
40
|
+
mock('IO').tap do |io|
|
41
|
+
io.stubs(:read).returns("content").then.returns(nil)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
it_should_store_file
|
24
46
|
end
|
25
47
|
end
|
26
48
|
|
data/test/memory_store_test.rb
CHANGED
@@ -8,13 +8,35 @@ describe RemoteFiles::MemoryStore do
|
|
8
8
|
|
9
9
|
describe '#store!' do
|
10
10
|
before do
|
11
|
-
@file = RemoteFiles::File.new('identifier', :content_type => 'text/plain', :content =>
|
11
|
+
@file = RemoteFiles::File.new('identifier', :content_type => 'text/plain', :content => content)
|
12
12
|
end
|
13
13
|
|
14
|
-
|
15
|
-
|
14
|
+
def self.it_should_store_file
|
15
|
+
it 'should store the file in the memory' do
|
16
|
+
@store.store!(@file)
|
16
17
|
|
17
|
-
|
18
|
+
assert_equal({:content_type => 'text/plain', :content => 'content'}, @store.data['identifier'])
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "content = string" do
|
23
|
+
let(:content) { "content" }
|
24
|
+
it_should_store_file
|
25
|
+
end
|
26
|
+
|
27
|
+
describe "content = stringio" do
|
28
|
+
let(:content) { StringIO.new("content") }
|
29
|
+
it_should_store_file
|
30
|
+
end
|
31
|
+
|
32
|
+
describe "content = io" do
|
33
|
+
let(:content) do
|
34
|
+
mock('IO').tap do |io|
|
35
|
+
io.stubs(:read).returns("content").then.returns(nil)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
it_should_store_file
|
18
40
|
end
|
19
41
|
end
|
20
42
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: remote_files
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,24 +9,24 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-02-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: fog
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
|
-
- -
|
19
|
+
- - ~>
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version: '
|
21
|
+
version: '1.7'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
25
25
|
none: false
|
26
26
|
requirements:
|
27
|
-
- -
|
27
|
+
- - ~>
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version: '
|
29
|
+
version: '1.7'
|
30
30
|
- !ruby/object:Gem::Dependency
|
31
31
|
name: rake
|
32
32
|
requirement: !ruby/object:Gem::Requirement
|
@@ -134,8 +134,9 @@ files:
|
|
134
134
|
- test/resque_job_test.rb
|
135
135
|
- test/test_helper.rb
|
136
136
|
- README.md
|
137
|
-
homepage: https://github.com/
|
138
|
-
licenses:
|
137
|
+
homepage: https://github.com/zendesk/remote_files
|
138
|
+
licenses:
|
139
|
+
- Apache License Version 2.0
|
139
140
|
post_install_message:
|
140
141
|
rdoc_options: []
|
141
142
|
require_paths:
|