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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b46cc167a6c4926e50df706732529767dd6d57a39cafa5460f840ef069f9d503
4
- data.tar.gz: e95f361bc70b9cbe82711e53665a7a3e44eee7f3cdf154517bbedf6371ca04c0
3
+ metadata.gz: 411157ac5a109d47177aefc6e164115c3359f053f4107f586d08000355c91992
4
+ data.tar.gz: 3d3aaf3badd3d27b04f4d9b7c0b2a723698c53c5ec683c7ca3856a02fc711b5e
5
5
  SHA512:
6
- metadata.gz: 882ddb538d5369758fa73eccb272ca8be5384697bd018670d1a5e88ffc09bdcf0401bf4cd59016f291fffdbd2dc1f02b1dba78ea56e04d05a26f4c1c9df5342d
7
- data.tar.gz: 36b8a206de8998afbce19fd9495a16259686f14a5ea395e425bda7d4f5bc479111212648a3372dbdfa2c9d5e82a9f4099543cac000684825bfce90f68e8ebed6
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
@@ -1,3 +1,9 @@
1
- # 1.0.1
2
- ## Fixed
1
+ # CHANGELOG
2
+
3
+ ## 1.1.0
4
+ ### Added
5
+ * Added a download method to download files to a specific path
6
+
7
+ ## 1.0.1
8
+ ### Fixed
3
9
  * dup list result in FakeDriver before iterating
data/README.md CHANGED
@@ -70,6 +70,7 @@ user.avatar(:icon).delete
70
70
  user.avatar(:icon).exists?
71
71
  user.avatar(:icon).value
72
72
  user.avatar(:icon).temp_url(expires_in: 2.days) # Must be supported by the driver
73
+ user.avator(:icon).download("/path/to/destination")
73
74
  ```
74
75
 
75
76
  ## Drivers
@@ -59,6 +59,10 @@ module Attachie
59
59
  option(:driver).store(path, data_or_io, container, opts)
60
60
  end
61
61
 
62
+ def download(dest_path)
63
+ option(:driver).download(path, container, dest_path)
64
+ end
65
+
62
66
  def info
63
67
  option(:driver).info(path, container)
64
68
  end
@@ -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
@@ -89,6 +89,10 @@ module Attachie
89
89
  File.binread path_for(name, bucket)
90
90
  end
91
91
 
92
+ def download(name, bucket, path)
93
+ FileUtils.cp(path_for(name, bucket), path)
94
+ end
95
+
92
96
  def delete(name, bucket)
93
97
  path = path_for(name, bucket)
94
98
 
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Attachie
2
- VERSION = "1.0.1"
2
+ VERSION = "1.1.0"
3
3
  end
@@ -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://bucket.localhost:4569"
102
+ url: "http://localhost:4569/bucket"
86
103
  )
87
104
  end
88
105
 
@@ -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 "blob"
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.1
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: 2019-12-12 00:00:00.000000000 Z
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
- rubyforge_project:
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
@@ -1,13 +0,0 @@
1
- sudo: false
2
- language: ruby
3
- rvm:
4
- - 2.3.3
5
- addons:
6
- hosts:
7
- - bucket.localhost
8
- before_install:
9
- - docker-compose up -d
10
- - sleep 10
11
- install:
12
- - travis_retry bundle install
13
- script: rspec