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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 518c8ff0b7b4f9109e1639526b4ff4d25e1878b9e0a4e572cbaab60321788f58
4
- data.tar.gz: bfba0fd29fc19d8464e9c4aac30e8b100c029b2a034dba3bc44a62fc36d2cd94
3
+ metadata.gz: 482a04ef6b634ab6764da860557971b844fa1100c86f27eca3abf87eee26c9fa
4
+ data.tar.gz: 4ec9ed3937d113c39e0a8258a40771985258ca791e817cc9b84aaf39a4a2fbcb
5
5
  SHA512:
6
- metadata.gz: 6b3d3a893c42fdc9cec9eeb661955f2c43be8540f8175772bb4d8086de9625bb86026ee2038fa1566fc8db81996f42d17107620abfddb7a6f65061adeb54e72d
7
- data.tar.gz: c1b569e988c4a515289ea4cbabe48ba6ad3ab739bd791b19cefd2168ba0c81f6c148aef3745fdb3b8c0e55e8581700090abc14866ec4705463a250ff87cff80e
6
+ metadata.gz: c9ca2eb4c9ac709ac1ec724476663217eede8c9a3081f7a4caeaf56891da2d458142d184310c3b4b38554dcda3c5e297de2cdadc4ecbbb0dbfe881985f27bd80
7
+ data.tar.gz: fa501dce7fa4030e4a7ba93f865e276d56aca9eebabaebf0152e44dc25e757a969b396291c7c56b28272d70846106c4f2a0edc314250ec9b75c1956bc777f6ec
@@ -6,6 +6,7 @@ rvm:
6
6
  - 2.3.5
7
7
  - 2.4.2
8
8
  - 2.5.0
9
+ - 2.6.0
9
10
 
10
11
  gemfile:
11
12
  - gemfiles/5.1.gemfile
@@ -79,6 +79,8 @@ module Saviour
79
79
 
80
80
  def storage
81
81
  @storage ||= Config.storage
82
+
83
+ @storage.respond_to?(:call) ? @storage.call : @storage
82
84
  end
83
85
 
84
86
  def process(name = nil, opts = {}, type = :memory, &block)
@@ -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
- access_key_id: @conf[:aws_access_key_id],
123
- secret_access_key: @conf[:aws_secret_access_key],
124
- region: @region
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
@@ -58,7 +58,7 @@ module Saviour
58
58
  result = run_method_or_block(method_or_block, opts, file)
59
59
 
60
60
  self.file = result[0]
61
- file.reopen(file.path)
61
+ file.reopen(file.path, "r+")
62
62
 
63
63
  self.filename = result[1]
64
64
  end
@@ -1,3 +1,3 @@
1
1
  module Saviour
2
- VERSION = "0.6.3"
2
+ VERSION = "0.6.4"
3
3
  end
@@ -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.3
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-06-20 00:00:00.000000000 Z
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/storage_overriding_spec.rb
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