saviour 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +14 -2
- data/lib/saviour/s3_storage.rb +6 -4
- data/lib/saviour/version.rb +1 -1
- data/spec/models/s3_storage_spec.rb +13 -0
- data/spec/spec_helper.rb +7 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2408d3766fe7e343df39bf80798d3f1c55b257bb
|
4
|
+
data.tar.gz: 982c9775fda3297f502b5dd5675d0887c65a51e5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2fe5f34e9257b8268a0716b122488da444bbcb2564fc9809d37edd74e56475594f7a3f506a3733c29d21b9034964c2dca99284c11c7575e77de94462ed0da796
|
7
|
+
data.tar.gz: b036f619061734cccf4437c4ded64aabef8712f02adc8136c28390cd6706d21e30dbb484d99426ea8c0461a6ec02c75913c2d0a966d863ae8bb58b7d0f9f7b58
|
data/README.md
CHANGED
@@ -246,11 +246,23 @@ the `host` option, as well as `region`, etc.
|
|
246
246
|
|
247
247
|
The `exists?` method uses a head request to verify existence, so it doesn't actually download the file.
|
248
248
|
|
249
|
-
All files will be created as public
|
249
|
+
All files will be created as public by default, but you can set an additional argument when initializing the storage to
|
250
|
+
declare options to be used when creating files to S3, and those options will take precedence. Use this for example to
|
251
|
+
set an expiration time for the asset. Example:
|
252
|
+
|
253
|
+
```
|
254
|
+
Saviour::Config.storage = Saviour::S3Storage.new(
|
255
|
+
bucket: "my-bucket-name",
|
256
|
+
aws_access_key_id: "stub",
|
257
|
+
aws_secret_access_key: "stub",
|
258
|
+
create_options: {public: false, 'Cache-Control' => 'max-age=31536000'}
|
259
|
+
)
|
260
|
+
```
|
250
261
|
|
251
262
|
This storage includes a feature of overwrite protection, raising an exception if an attempt is made of writing something
|
252
263
|
on a path that already exists. This behaviour in enabled by default, but you can turn it off by passing an additional
|
253
|
-
argument when instantiating the storage: `overwrite_protection: false`.
|
264
|
+
argument when instantiating the storage: `overwrite_protection: false`. This feature requires an additional HEAD request
|
265
|
+
to verify existence for every write.
|
254
266
|
|
255
267
|
|
256
268
|
## Source abstraction
|
data/lib/saviour/s3_storage.rb
CHANGED
@@ -5,6 +5,7 @@ module Saviour
|
|
5
5
|
@public_url_prefix = conf.delete(:public_url_prefix)
|
6
6
|
@conf = conf
|
7
7
|
@overwrite_protection = conf.delete(:overwrite_protection) { true }
|
8
|
+
@create_options = conf.delete(:create_options) { {} }
|
8
9
|
assert_directory_exists!
|
9
10
|
end
|
10
11
|
|
@@ -12,10 +13,11 @@ module Saviour
|
|
12
13
|
raise(RuntimeError, "The path you're trying to write already exists!") if @overwrite_protection && exists?(path)
|
13
14
|
|
14
15
|
path = sanitize_leading_slash(path)
|
15
|
-
directory.files.create(
|
16
|
-
|
17
|
-
|
18
|
-
|
16
|
+
directory.files.create({
|
17
|
+
key: path,
|
18
|
+
body: contents,
|
19
|
+
public: true
|
20
|
+
}.merge(@create_options)
|
19
21
|
)
|
20
22
|
end
|
21
23
|
|
data/lib/saviour/version.rb
CHANGED
@@ -76,6 +76,19 @@ describe Saviour::S3Storage do
|
|
76
76
|
expect(subject.exists?("/folder/file.out")).to be_truthy
|
77
77
|
expect(subject.exists?("////folder/file.out")).to be_truthy
|
78
78
|
end
|
79
|
+
|
80
|
+
describe "fog create options" do
|
81
|
+
subject { Saviour::S3Storage.new(bucket: "fake-bucket", aws_access_key_id: "stub", aws_secret_access_key: "stub", public_url_prefix: "https://fake-bucket.s3.amazonaws.com", create_options: {'Cache-Control' => 'max-age=31536000'}) }
|
82
|
+
|
83
|
+
it "uses passed options to create new files in S3" do
|
84
|
+
with_test_file("camaloon.jpg") do |file, _|
|
85
|
+
contents = file.read
|
86
|
+
subject.write(contents, destination_path)
|
87
|
+
file_data = mocked_s3.head(destination_path)
|
88
|
+
expect(file_data.cache_control).to eq "max-age=31536000"
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
79
92
|
end
|
80
93
|
|
81
94
|
describe "#read" do
|
data/spec/spec_helper.rb
CHANGED
@@ -33,6 +33,8 @@ RSpec.configure do |config|
|
|
33
33
|
example.run
|
34
34
|
}
|
35
35
|
end
|
36
|
+
|
37
|
+
config.after { Fog::Mock.reset }
|
36
38
|
end
|
37
39
|
|
38
40
|
def with_tempfile(ext = ".jpg")
|
@@ -77,8 +79,12 @@ class MockedS3Helper
|
|
77
79
|
directory.files.get(path).destroy
|
78
80
|
end
|
79
81
|
|
82
|
+
def head(path)
|
83
|
+
directory.files.head(path)
|
84
|
+
end
|
85
|
+
|
80
86
|
def exists?(path)
|
81
|
-
!!
|
87
|
+
!!head(path)
|
82
88
|
end
|
83
89
|
|
84
90
|
def public_url(path)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: saviour
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Roger Campos
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-04-
|
11
|
+
date: 2016-04-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|