attachie 1.0.1 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/test.yml +27 -0
- data/CHANGELOG.md +8 -2
- data/README.md +1 -0
- data/lib/attachie.rb +4 -0
- data/lib/attachie/fake_driver.rb +6 -0
- data/lib/attachie/file_driver.rb +4 -0
- data/lib/attachie/s3_driver.rb +4 -0
- data/lib/attachie/version.rb +1 -1
- data/spec/attachie/fake_driver_spec.rb +15 -0
- data/spec/attachie/file_driver_spec.rb +16 -0
- data/spec/attachie/s3_driver_spec.rb +18 -1
- data/spec/attachie_spec.rb +17 -1
- metadata +4 -5
- data/.travis.yml +0 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 411157ac5a109d47177aefc6e164115c3359f053f4107f586d08000355c91992
|
4
|
+
data.tar.gz: 3d3aaf3badd3d27b04f4d9b7c0b2a723698c53c5ec683c7ca3856a02fc711b5e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 18e9e23f240a581dedda0cb4a0b0b19687202e5cce81497b5bbd2a4cf2322a420b28df111fee9444cd3dac96c0d89e442a126046392e5ded6875f34f16dcb96c
|
7
|
+
data.tar.gz: d656a2b8bc38593ac218100eddedadecd55ad5cffed2bac0dbc913ff9e7f7e57632872b3f327f7b312fcfe49acd21c6291ec06fed3e2a568de348d94d778e9a1
|
@@ -0,0 +1,27 @@
|
|
1
|
+
name: test
|
2
|
+
on: [push, pull_request]
|
3
|
+
jobs:
|
4
|
+
build:
|
5
|
+
runs-on: ubuntu-latest
|
6
|
+
strategy:
|
7
|
+
matrix:
|
8
|
+
ruby: ['2.5', '2.6', '2.7']
|
9
|
+
services:
|
10
|
+
fake-s3:
|
11
|
+
image: lphoward/fake-s3
|
12
|
+
ports:
|
13
|
+
- 4569:4569
|
14
|
+
steps:
|
15
|
+
- uses: actions/checkout@v1
|
16
|
+
- uses: actions/setup-ruby@v1
|
17
|
+
with:
|
18
|
+
ruby-version: ${{ matrix.ruby }}
|
19
|
+
- uses: actions/cache@v1
|
20
|
+
id: cache
|
21
|
+
with:
|
22
|
+
path: vendor/bundler
|
23
|
+
key: ${{ hashFiles('Gemfile.lock') }}-${{ matrix.ruby }}
|
24
|
+
- run: |
|
25
|
+
gem install bundler
|
26
|
+
bundle install --path=vendor/bundler
|
27
|
+
bundle exec rspec
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
data/lib/attachie.rb
CHANGED
data/lib/attachie/fake_driver.rb
CHANGED
@@ -76,6 +76,12 @@ module Attachie
|
|
76
76
|
objects(bucket)[name]
|
77
77
|
end
|
78
78
|
|
79
|
+
def download(name, bucket, path)
|
80
|
+
content = value(name, bucket)
|
81
|
+
|
82
|
+
open(path, "wb") { |stream| stream.write(content) }
|
83
|
+
end
|
84
|
+
|
79
85
|
def temp_url(name, bucket, options = {})
|
80
86
|
"https://example.com/#{bucket}/#{name}?signature=signature&expires=expires"
|
81
87
|
end
|
data/lib/attachie/file_driver.rb
CHANGED
data/lib/attachie/s3_driver.rb
CHANGED
@@ -114,6 +114,10 @@ module Attachie
|
|
114
114
|
s3_resource.bucket(bucket).object(name).get.body.read.force_encoding(Encoding::BINARY)
|
115
115
|
end
|
116
116
|
|
117
|
+
def download(name, bucket, path)
|
118
|
+
s3_resource.bucket(bucket).object(name).download_file(path)
|
119
|
+
end
|
120
|
+
|
117
121
|
def delete(name, bucket)
|
118
122
|
s3_resource.bucket(bucket).object(name).delete
|
119
123
|
end
|
data/lib/attachie/version.rb
CHANGED
@@ -32,6 +32,21 @@ RSpec.describe Attachie::FakeDriver do
|
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
|
+
describe "#download" do
|
36
|
+
it "downloads the blob to the specified path" do
|
37
|
+
tempfile = Tempfile.new
|
38
|
+
|
39
|
+
begin
|
40
|
+
driver.store("name", "blob", "bucket")
|
41
|
+
driver.download("name", "bucket", tempfile.path)
|
42
|
+
|
43
|
+
expect(tempfile.read).to eq("blob")
|
44
|
+
ensure
|
45
|
+
tempfile.close(true)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
35
50
|
describe "#store_multipart" do
|
36
51
|
it "stores a blob via multipart upload" do
|
37
52
|
driver.store_multipart("name", "bucket") do |upload|
|
@@ -23,6 +23,22 @@ RSpec.describe Attachie::FileDriver do
|
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
|
+
describe "#download" do
|
27
|
+
it "downloads the blob to the specified path" do
|
28
|
+
tempfile = Tempfile.new
|
29
|
+
|
30
|
+
begin
|
31
|
+
driver.store("name", "blob", "bucket")
|
32
|
+
driver.download("name", "bucket", tempfile.path)
|
33
|
+
|
34
|
+
expect(tempfile.read).to eq("blob")
|
35
|
+
ensure
|
36
|
+
driver.delete("name", "bucket")
|
37
|
+
tempfile.close(true)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
26
42
|
describe" #store_multipart" do
|
27
43
|
it "stores a blob via multipart upload" do
|
28
44
|
begin
|
@@ -7,6 +7,7 @@ RSpec.describe Attachie::S3Driver do
|
|
7
7
|
access_key_id: "access_key_id",
|
8
8
|
secret_access_key: "secret_access_key",
|
9
9
|
endpoint: "http://localhost:4569",
|
10
|
+
force_path_style: true,
|
10
11
|
region: "us-east-1"
|
11
12
|
))
|
12
13
|
end
|
@@ -40,6 +41,22 @@ RSpec.describe Attachie::S3Driver do
|
|
40
41
|
end
|
41
42
|
end
|
42
43
|
|
44
|
+
describe "#download" do
|
45
|
+
it "downloads the blob to the specified path" do
|
46
|
+
tempfile = Tempfile.new
|
47
|
+
|
48
|
+
begin
|
49
|
+
driver.store("name", "blob", "bucket")
|
50
|
+
driver.download("name", "bucket", tempfile.path)
|
51
|
+
|
52
|
+
expect(tempfile.read).to eq("blob")
|
53
|
+
ensure
|
54
|
+
driver.delete("name", "bucket")
|
55
|
+
tempfile.close(true)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
43
60
|
describe "#store_multipart" do
|
44
61
|
it "stores a blob via multipart upload" do
|
45
62
|
begin
|
@@ -82,7 +99,7 @@ RSpec.describe Attachie::S3Driver do
|
|
82
99
|
fields: hash_including("key" => "path/to/object"),
|
83
100
|
headers: {},
|
84
101
|
method: "post",
|
85
|
-
url: "http://
|
102
|
+
url: "http://localhost:4569/bucket"
|
86
103
|
)
|
87
104
|
end
|
88
105
|
|
data/spec/attachie_spec.rb
CHANGED
@@ -37,7 +37,7 @@ RSpec.describe TestModel do
|
|
37
37
|
|
38
38
|
it "correctly uses the driver" do
|
39
39
|
test_model = TestModel.new(filename: "blob.txt")
|
40
|
-
test_model.file(:large).store
|
40
|
+
test_model.file(:large).store("blob")
|
41
41
|
|
42
42
|
expect(test_model.file(:large).value).to eq("blob")
|
43
43
|
end
|
@@ -54,6 +54,22 @@ RSpec.describe TestModel do
|
|
54
54
|
expect(test_model.updated_at).to be_nil
|
55
55
|
end
|
56
56
|
|
57
|
+
describe "#download" do
|
58
|
+
it "downloads the file to the specified path" do
|
59
|
+
tempfile = Tempfile.new
|
60
|
+
|
61
|
+
begin
|
62
|
+
test_model = TestModel.new(filename: "blob.txt")
|
63
|
+
test_model.file(:large).store("blob")
|
64
|
+
test_model.file(:large).download(tempfile.path)
|
65
|
+
|
66
|
+
expect(tempfile.read).to eq("blob")
|
67
|
+
ensure
|
68
|
+
tempfile.close(true)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
57
73
|
describe "#info" do
|
58
74
|
it "returns info about the attachment" do
|
59
75
|
test_model = TestModel.new(filename: "blob.txt")
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: attachie
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Benjamin Vetter
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-01-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aws-sdk-s3
|
@@ -129,8 +129,8 @@ executables: []
|
|
129
129
|
extensions: []
|
130
130
|
extra_rdoc_files: []
|
131
131
|
files:
|
132
|
+
- ".github/workflows/test.yml"
|
132
133
|
- ".gitignore"
|
133
|
-
- ".travis.yml"
|
134
134
|
- CHANGELOG.md
|
135
135
|
- Gemfile
|
136
136
|
- LICENSE.txt
|
@@ -169,8 +169,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
169
169
|
- !ruby/object:Gem::Version
|
170
170
|
version: '0'
|
171
171
|
requirements: []
|
172
|
-
|
173
|
-
rubygems_version: 2.7.3
|
172
|
+
rubygems_version: 3.0.3
|
174
173
|
signing_key:
|
175
174
|
specification_version: 4
|
176
175
|
summary: Declarative and flexible attachments
|