saviour 0.6.3 → 0.6.4
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/.travis.yml +1 -0
- data/lib/saviour/base_uploader.rb +2 -0
- data/lib/saviour/s3_storage.rb +6 -3
- data/lib/saviour/uploader/processors_runner.rb +1 -1
- data/lib/saviour/version.rb +1 -1
- data/spec/feature/storages_spec.rb +87 -0
- metadata +3 -3
- data/spec/feature/storage_overriding_spec.rb +0 -44
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 482a04ef6b634ab6764da860557971b844fa1100c86f27eca3abf87eee26c9fa
|
4
|
+
data.tar.gz: 4ec9ed3937d113c39e0a8258a40771985258ca791e817cc9b84aaf39a4a2fbcb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c9ca2eb4c9ac709ac1ec724476663217eede8c9a3081f7a4caeaf56891da2d458142d184310c3b4b38554dcda3c5e297de2cdadc4ecbbb0dbfe881985f27bd80
|
7
|
+
data.tar.gz: fa501dce7fa4030e4a7ba93f865e276d56aca9eebabaebf0152e44dc25e757a969b396291c7c56b28272d70846106c4f2a0edc314250ec9b75c1956bc777f6ec
|
data/.travis.yml
CHANGED
data/lib/saviour/s3_storage.rb
CHANGED
@@ -11,6 +11,7 @@ module Saviour
|
|
11
11
|
def initialize(conf = {})
|
12
12
|
@bucket = conf.delete(:bucket)
|
13
13
|
@public_url_prefix = conf.delete(:public_url_prefix)
|
14
|
+
@extra_aws_client_options = conf.delete(:aws_client_opts)
|
14
15
|
@conf = conf
|
15
16
|
@create_options = conf.delete(:create_options) { {} }
|
16
17
|
conf.fetch(:aws_access_key_id) { raise(ArgumentError, "aws_access_key_id is required") }
|
@@ -119,9 +120,11 @@ module Saviour
|
|
119
120
|
|
120
121
|
def client
|
121
122
|
@client ||= Aws::S3::Client.new(
|
122
|
-
|
123
|
-
|
124
|
-
|
123
|
+
{
|
124
|
+
access_key_id: @conf[:aws_access_key_id],
|
125
|
+
secret_access_key: @conf[:aws_secret_access_key],
|
126
|
+
region: @region
|
127
|
+
}.merge(@extra_aws_client_options || {})
|
125
128
|
)
|
126
129
|
end
|
127
130
|
end
|
data/lib/saviour/version.rb
CHANGED
@@ -0,0 +1,87 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "uploader declaration" do
|
4
|
+
let!(:default_storage) do
|
5
|
+
Saviour::LocalStorage.new(
|
6
|
+
local_prefix: @tmpdir,
|
7
|
+
public_url_prefix: "http://domain.com"
|
8
|
+
)
|
9
|
+
end
|
10
|
+
|
11
|
+
let!(:another_storage) do
|
12
|
+
Saviour::LocalStorage.new(
|
13
|
+
local_prefix: @tmpdir,
|
14
|
+
public_url_prefix: "http://custom-domain.com"
|
15
|
+
)
|
16
|
+
end
|
17
|
+
|
18
|
+
before { allow(Saviour::Config).to receive(:storage).and_return(default_storage) }
|
19
|
+
|
20
|
+
it "lets you override storage on attachment basis" do
|
21
|
+
klass = Class.new(Test) { include Saviour::Model }
|
22
|
+
custom_storage = another_storage
|
23
|
+
|
24
|
+
klass.attach_file(:file) do
|
25
|
+
store_dir { "/store/dir" }
|
26
|
+
end
|
27
|
+
|
28
|
+
klass.attach_file(:file_thumb) do
|
29
|
+
store_dir { "/store/dir" }
|
30
|
+
with_storage custom_storage
|
31
|
+
end
|
32
|
+
|
33
|
+
a = klass.create!(
|
34
|
+
file: Saviour::StringSource.new("content", "houhou.txt"),
|
35
|
+
file_thumb: Saviour::StringSource.new("content", "custom_houhou.txt")
|
36
|
+
)
|
37
|
+
|
38
|
+
expect(a.file.filename).to eq "houhou.txt"
|
39
|
+
expect(a.file.url).to eq 'http://domain.com/store/dir/houhou.txt'
|
40
|
+
|
41
|
+
expect(a.file_thumb.filename).to eq "custom_houhou.txt"
|
42
|
+
expect(a.file_thumb.url).to eq 'http://custom-domain.com/store/dir/custom_houhou.txt'
|
43
|
+
end
|
44
|
+
|
45
|
+
context do
|
46
|
+
it "allows for lambda storages" do
|
47
|
+
allow(Saviour::Config).to receive(:storage).and_return(-> { default_storage })
|
48
|
+
|
49
|
+
klass = Class.new(Test) { include Saviour::Model }
|
50
|
+
|
51
|
+
klass.attach_file(:file) do
|
52
|
+
store_dir { "/store/dir" }
|
53
|
+
end
|
54
|
+
|
55
|
+
a = klass.create!(file: Saviour::StringSource.new("content", "houhou.txt"))
|
56
|
+
|
57
|
+
expect(a.file.filename).to eq "houhou.txt"
|
58
|
+
expect(a.file.url).to eq 'http://domain.com/store/dir/houhou.txt'
|
59
|
+
end
|
60
|
+
|
61
|
+
it "allow to change storage on the fly" do
|
62
|
+
dynamic_storage = default_storage
|
63
|
+
allow(Saviour::Config).to receive(:storage).and_return(-> { dynamic_storage })
|
64
|
+
|
65
|
+
klass = Class.new(Test) { include Saviour::Model }
|
66
|
+
|
67
|
+
klass.attach_file(:file) do
|
68
|
+
store_dir { "/store/dir" }
|
69
|
+
end
|
70
|
+
|
71
|
+
a = klass.create!(
|
72
|
+
file: Saviour::StringSource.new("content", "houhou.txt"),
|
73
|
+
file_thumb: Saviour::StringSource.new("content", "custom_houhou.txt")
|
74
|
+
)
|
75
|
+
|
76
|
+
expect(a.file.filename).to eq "houhou.txt"
|
77
|
+
expect(a.file.url).to eq 'http://domain.com/store/dir/houhou.txt'
|
78
|
+
|
79
|
+
dynamic_storage = another_storage # Lambda will pick up the new storage.
|
80
|
+
|
81
|
+
a = klass.create!(file: Saviour::StringSource.new("content", "houhou.txt"))
|
82
|
+
|
83
|
+
expect(a.file.filename).to eq "houhou.txt"
|
84
|
+
expect(a.file.url).to eq 'http://custom-domain.com/store/dir/houhou.txt'
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
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.6.
|
4
|
+
version: 0.6.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Roger Campos
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-07-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -217,7 +217,7 @@ files:
|
|
217
217
|
- spec/feature/reopens_file_at_every_process_spec.rb
|
218
218
|
- spec/feature/rewind_source_before_read_spec.rb
|
219
219
|
- spec/feature/stash_spec.rb
|
220
|
-
- spec/feature/
|
220
|
+
- spec/feature/storages_spec.rb
|
221
221
|
- spec/feature/transactional_behavior_spec.rb
|
222
222
|
- spec/feature/uploader_declaration_spec.rb
|
223
223
|
- spec/feature/validations_spec.rb
|
@@ -1,44 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe "uploader declaration" do
|
4
|
-
let!(:default_storage) do
|
5
|
-
Saviour::LocalStorage.new(
|
6
|
-
local_prefix: @tmpdir,
|
7
|
-
public_url_prefix: "http://domain.com"
|
8
|
-
)
|
9
|
-
end
|
10
|
-
|
11
|
-
let!(:another_storage) do
|
12
|
-
Saviour::LocalStorage.new(
|
13
|
-
local_prefix: @tmpdir,
|
14
|
-
public_url_prefix: "http://custom-domain.com"
|
15
|
-
)
|
16
|
-
end
|
17
|
-
|
18
|
-
before { allow(Saviour::Config).to receive(:storage).and_return(default_storage) }
|
19
|
-
|
20
|
-
it "lets you override storage on attachment basis" do
|
21
|
-
klass = Class.new(Test) { include Saviour::Model }
|
22
|
-
custom_storage = another_storage
|
23
|
-
|
24
|
-
klass.attach_file(:file) do
|
25
|
-
store_dir { "/store/dir" }
|
26
|
-
end
|
27
|
-
|
28
|
-
klass.attach_file(:file_thumb) do
|
29
|
-
store_dir { "/store/dir" }
|
30
|
-
with_storage custom_storage
|
31
|
-
end
|
32
|
-
|
33
|
-
a = klass.create!(
|
34
|
-
file: Saviour::StringSource.new("content", "houhou.txt"),
|
35
|
-
file_thumb: Saviour::StringSource.new("content", "custom_houhou.txt")
|
36
|
-
)
|
37
|
-
|
38
|
-
expect(a.file.filename).to eq "houhou.txt"
|
39
|
-
expect(a.file.url).to eq 'http://domain.com/store/dir/houhou.txt'
|
40
|
-
|
41
|
-
expect(a.file_thumb.filename).to eq "custom_houhou.txt"
|
42
|
-
expect(a.file_thumb.url).to eq 'http://custom-domain.com/store/dir/custom_houhou.txt'
|
43
|
-
end
|
44
|
-
end
|