saviour 0.2.1 → 0.2.2

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
  SHA1:
3
- metadata.gz: 2408d3766fe7e343df39bf80798d3f1c55b257bb
4
- data.tar.gz: 982c9775fda3297f502b5dd5675d0887c65a51e5
3
+ metadata.gz: 68e8a4112de62c4fe7d28f634ba8b296a9c28602
4
+ data.tar.gz: 696487d7c403c9d8792825cefec5991a81f1b3dd
5
5
  SHA512:
6
- metadata.gz: 2fe5f34e9257b8268a0716b122488da444bbcb2564fc9809d37edd74e56475594f7a3f506a3733c29d21b9034964c2dca99284c11c7575e77de94462ed0da796
7
- data.tar.gz: b036f619061734cccf4437c4ded64aabef8712f02adc8136c28390cd6706d21e30dbb484d99426ea8c0461a6ec02c75913c2d0a966d863ae8bb58b7d0f9f7b58
6
+ metadata.gz: b6964d6d057e12efd48c702ad0928966c172d63f45579a8ab72df6fb07bfecf467167946b6a3267baaaee3a24f57165f2094f11937497bb64f70afe4587cd198
7
+ data.tar.gz: 29ed2dd0ffd4cc4fade49f01455b8715f24d5302a904259399f8859a6f761feab9b707f38300b7adba17878b506d9051c750f0f509864f21abf9ac8c6993f2b5
data/README.md CHANGED
@@ -180,8 +180,9 @@ You must configure Saviour by providing the storage to use:
180
180
  Saviour::Config.storage = MyStorageImplementation.new
181
181
  ```
182
182
 
183
- The provided storage object will be used for all the lifespan of the running application, for all the file uploads
184
- handled by Saviour.
183
+ The provided storage object is considered a global configuration state that will be used by Saviour for all mounters.
184
+ However, this configuration is thread-safe and can be changed at runtime, allowing you in practice to work with different
185
+ storages by swapping them depending on your use case.
185
186
 
186
187
 
187
188
  ### public_url
@@ -389,7 +390,7 @@ Saviour::Config.processing_enabled = true
389
390
  ```
390
391
 
391
392
  You can use this when running tests, for example, or if you want processors to not execute for some reason. The flag can be
392
- changed in real time.
393
+ changed in real time and is thread-safe.
393
394
 
394
395
 
395
396
  ## Versions
@@ -1,13 +1,16 @@
1
1
  module Saviour
2
- module Config
3
- extend self
4
-
5
- attr_writer :storage
6
- def storage
7
- @storage || raise(RuntimeError, "You need to provide a storage! Set Saviour::Config.storage = xxx")
2
+ class Config
3
+ class NotImplemented
4
+ def method_missing(*)
5
+ raise(RuntimeError, "You need to provide a storage! Set Saviour::Config.storage = xxx")
6
+ end
8
7
  end
9
8
 
10
- attr_accessor :processing_enabled
11
- @processing_enabled = true
9
+ extend ActiveSupport::PerThreadRegistry
10
+
11
+ attr_accessor :storage, :processing_enabled
12
+
13
+ self.processing_enabled = true
14
+ self.storage = NotImplemented.new
12
15
  end
13
16
  end
@@ -1,3 +1,3 @@
1
1
  module Saviour
2
- VERSION = "0.2.1"
2
+ VERSION = "0.2.2"
3
3
  end
@@ -1,8 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe "access to model data from uploaders" do
4
- before { Saviour::Config.storage = Saviour::LocalStorage.new(local_prefix: @tmpdir, public_url_prefix: "http://domain.com") }
5
- after { Saviour::Config.storage = nil }
4
+ before { allow(Saviour::Config).to receive(:storage).and_return(Saviour::LocalStorage.new(local_prefix: @tmpdir, public_url_prefix: "http://domain.com")) }
6
5
 
7
6
  let(:uploader) {
8
7
  Class.new(Saviour::BaseUploader) do
@@ -12,7 +11,8 @@ describe "access to model data from uploaders" do
12
11
  }
13
12
 
14
13
  let(:klass) {
15
- a = Class.new(Text)
14
+ a = Class.new(Test)
15
+ a.include Saviour
16
16
  a.attach_file :file, uploader
17
17
  a
18
18
  }
@@ -1,8 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe "saving a new file" do
4
- before { Saviour::Config.storage = Saviour::LocalStorage.new(local_prefix: @tmpdir, public_url_prefix: "http://domain.com") }
5
- after { Saviour::Config.storage = nil }
4
+ before { allow(Saviour::Config).to receive(:storage).and_return(Saviour::LocalStorage.new(local_prefix: @tmpdir, public_url_prefix: "http://domain.com")) }
6
5
 
7
6
  let(:uploader) {
8
7
  Class.new(Saviour::BaseUploader) {
@@ -1,8 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe "persisted path" do
4
- before { Saviour::Config.storage = Saviour::LocalStorage.new(local_prefix: @tmpdir, public_url_prefix: "http://domain.com") }
5
- after { Saviour::Config.storage = nil }
4
+ before { allow(Saviour::Config).to receive(:storage).and_return(Saviour::LocalStorage.new(local_prefix: @tmpdir, public_url_prefix: "http://domain.com")) }
6
5
 
7
6
  context "can change the default_path on the uploader and previous instances are not affected" do
8
7
  it do
@@ -1,8 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe "reload model" do
4
- before { Saviour::Config.storage = Saviour::LocalStorage.new(local_prefix: @tmpdir, public_url_prefix: "http://domain.com") }
5
- after { Saviour::Config.storage = nil }
4
+ before { allow(Saviour::Config).to receive(:storage).and_return(Saviour::LocalStorage.new(local_prefix: @tmpdir, public_url_prefix: "http://domain.com")) }
6
5
 
7
6
  context "updates the Saviour::File instance" do
8
7
  it do
@@ -1,8 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe "validations saving a new file" do
4
- before { Saviour::Config.storage = Saviour::LocalStorage.new(local_prefix: @tmpdir, public_url_prefix: "http://domain.com") }
5
- after { Saviour::Config.storage = nil }
4
+ before { allow(Saviour::Config).to receive(:storage).and_return(Saviour::LocalStorage.new(local_prefix: @tmpdir, public_url_prefix: "http://domain.com")) }
6
5
 
7
6
  let(:uploader) {
8
7
  Class.new(Saviour::BaseUploader) {
@@ -1,8 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe "saving a new file" do
4
- before { Saviour::Config.storage = Saviour::LocalStorage.new(local_prefix: @tmpdir, public_url_prefix: "http://domain.com") }
5
- after { Saviour::Config.storage = nil }
4
+ before { allow(Saviour::Config).to receive(:storage).and_return(Saviour::LocalStorage.new(local_prefix: @tmpdir, public_url_prefix: "http://domain.com")) }
6
5
 
7
6
  let(:uploader) {
8
7
  Class.new(Saviour::BaseUploader) do
@@ -1,16 +1,24 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Saviour::Config do
4
- after { Saviour::Config.storage = nil }
5
-
6
4
  describe "#storage" do
7
5
  it do
8
- expect { Saviour::Config.storage }.to raise_error(RuntimeError)
6
+ expect { Saviour::Config.storage.anything }.to raise_error(RuntimeError)
9
7
  end
10
8
 
11
9
  it do
12
10
  Saviour::Config.storage = :test
13
11
  expect(Saviour::Config.storage).to eq :test
14
12
  end
13
+
14
+ it "is thread-safe" do
15
+ (0.upto(1_000)).map do |x|
16
+ Thread.new do
17
+ Saviour::Config.storage = x
18
+ sleep 0.05 # Simulate work
19
+ expect(Saviour::Config.storage).to eq x
20
+ end
21
+ end.each(&:join)
22
+ end
15
23
  end
16
24
  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.2.1
4
+ version: 0.2.2
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-30 00:00:00.000000000 Z
11
+ date: 2016-06-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -149,7 +149,7 @@ files:
149
149
  - lib/saviour/url_source.rb
150
150
  - lib/saviour/version.rb
151
151
  - saviour.gemspec
152
- - spec/feature/access_to_model_and_mounted_as.rb
152
+ - spec/feature/access_to_model_and_mounted_as_spec.rb
153
153
  - spec/feature/crud_workflows_spec.rb
154
154
  - spec/feature/persisted_path_spec.rb
155
155
  - spec/feature/reload_model_spec.rb