survey-gizmo-ruby 6.7.0 → 7.0.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: 0f7c1b7c1989e807e2aad794b3b55836382ce2a667ef1fca0c60dbd1ca6045c8
4
- data.tar.gz: 1c91c4b30cfb6af1485f92051a023115d146c8e5b03f8079a84b013e45560768
3
+ metadata.gz: 2a08475717245ba2f53f58bf497f7b18fd8bab1f61554e73862c83fafb8fa8c6
4
+ data.tar.gz: eb9c8b9f1591d2a381bd926fe61d8649290aeee8ea22a1c879d37c845610e132
5
5
  SHA512:
6
- metadata.gz: 762529071658cb08a7cc48be9872bc8b11a8ba647925951254aa55c7584947c4a8d0df248003cd753247f7ee90c6a15ae74a6d972a1f2edf7be03cf01e8535c1
7
- data.tar.gz: a82828bca4c4c2a45051149ce9d1ae0cdecf3e7f1291287c2aadec97de1ea2b81c039082baab264f849d1fc76fe092230ad0e8a6504ed2705dfe97f519adfa8d
6
+ metadata.gz: 75a62b2a9af99e373beca17f5f2c4bef2ff9ee1a1b047b01a2110fc22109bcf5bf63fc50d11b0760c939c84c7475bd2d3a69956d49913ecbe3dc4c7961247db6
7
+ data.tar.gz: 718d88e0d421b56ae97467cb078f69bf5230337db62e387bf42dddb5c2aa2d308c4c4a5fd2e39834323658898ad5b5f43cd589e0f616c4e47eb83c168c813bf4
data/CHANGELOG.md CHANGED
@@ -1,4 +1,6 @@
1
1
  # Versions
2
+ ## 7.0.0
3
+ * Makes configuration thread safe. When a new thread is created, the last configuration set through `SurveyGizmo.configure` will be used.
2
4
 
3
5
  ## 6.7.0
4
6
  * Change timezone for EU servers to UTC (#103)
data/README.md CHANGED
@@ -18,6 +18,10 @@ gem 'survey-gizmo-ruby'
18
18
 
19
19
  ## Configuration
20
20
 
21
+ The configuration is thread safe.
22
+ When a new thread is created, the last configuration set through `SurveyGizmo.configure` or `SurveyGizmo.configuration=` will be used.
23
+ When `SurveyGizmo.reset!` is called, only the current thread configuration will be reset.
24
+
21
25
  ```ruby
22
26
  require 'survey-gizmo-ruby'
23
27
 
@@ -1,33 +1,41 @@
1
1
  require 'survey_gizmo/faraday_middleware/parse_survey_gizmo'
2
2
 
3
3
  module SurveyGizmo
4
- class << self
5
- attr_writer :configuration
6
4
 
5
+ CONFIG_THREAD_VARIABLE_NAME = :survey_gizmo_configuration
6
+
7
+ class << self
7
8
  def configuration
8
- fail 'Not configured!' unless @configuration
9
- @configuration
9
+ fail 'Not configured!' unless Thread.current[CONFIG_THREAD_VARIABLE_NAME] || @global_config
10
+ Thread.current[CONFIG_THREAD_VARIABLE_NAME] ||= @global_config.dup
11
+ end
12
+
13
+ def configuration=(new_config)
14
+ @global_config = new_config.dup
15
+ Thread.current[CONFIG_THREAD_VARIABLE_NAME] = new_config
10
16
  end
11
17
 
12
18
  def configure
13
19
  reset!
14
- yield(@configuration) if block_given?
20
+ yield(configuration) if block_given?
15
21
 
16
- if @configuration.retry_attempts
17
- @configuration.logger.warn('Configuring retry_attempts is deprecated; pass a retriable_params hash instead.')
18
- @configuration.retriable_params[:tries] = @configuration.retry_attempts + 1
22
+ if configuration.retry_attempts
23
+ configuration.logger.warn('Configuring retry_attempts is deprecated; pass a retriable_params hash instead.')
24
+ configuration.retriable_params[:tries] = configuration.retry_attempts + 1
19
25
  end
20
26
 
21
- if @configuration.retry_interval
22
- @configuration.logger.warn('Configuring retry_interval is deprecated; pass a retriable_params hash instead.')
23
- @configuration.retriable_params[:base_interval] = @configuration.retry_interval
27
+ if configuration.retry_interval
28
+ configuration.logger.warn('Configuring retry_interval is deprecated; pass a retriable_params hash instead.')
29
+ configuration.retriable_params[:base_interval] = configuration.retry_interval
24
30
  end
25
31
 
26
- @configuration.retriable_params = Configuration::DEFAULT_RETRIABLE_PARAMS.merge(@configuration.retriable_params)
32
+ configuration.retriable_params = Configuration::DEFAULT_RETRIABLE_PARAMS.merge(configuration.retriable_params)
33
+
34
+ @global_config = configuration
27
35
  end
28
36
 
29
37
  def reset!
30
- @configuration = Configuration.new
38
+ Thread.current[CONFIG_THREAD_VARIABLE_NAME] = Configuration.new
31
39
  Connection.reset!
32
40
  end
33
41
  end
@@ -1,3 +1,3 @@
1
1
  module SurveyGizmo
2
- VERSION = '6.7.0'
2
+ VERSION = '7.0.0'
3
3
  end
@@ -2,10 +2,14 @@ require 'spec_helper'
2
2
  require 'survey_gizmo/configuration'
3
3
 
4
4
  describe SurveyGizmo::Configuration do
5
+
6
+ let(:api_token) { "token" }
7
+ let(:api_token_secret) { "doken" }
8
+
5
9
  before(:each) do
6
10
  SurveyGizmo.configure do |config|
7
- config.api_token = 'token'
8
- config.api_token_secret = 'doken'
11
+ config.api_token = api_token
12
+ config.api_token_secret = api_token_secret
9
13
  end
10
14
  end
11
15
 
@@ -13,16 +17,90 @@ describe SurveyGizmo::Configuration do
13
17
  SurveyGizmo.reset!
14
18
  end
15
19
 
16
- it 'should allow changing user and pass' do
20
+ it "should allow changing user and pass" do
17
21
  # preload connection to verify that memoization is purged
18
22
  SurveyGizmo::Connection.send(:connection)
19
23
 
20
24
  SurveyGizmo.configure do |config|
21
- config.api_token = 'slimthug'
22
- config.api_token_secret = 'fourfourz'
25
+ config.api_token = "slimthug"
26
+ config.api_token_secret = "fourfourz"
27
+ end
28
+
29
+ expect(SurveyGizmo::Connection.send(:connection).params).to eq("api_token" => "slimthug", "api_token_secret" => "fourfourz")
30
+ end
31
+
32
+ context "thread safety" do
33
+ it "is set from the last known configuration" do
34
+ expect(SurveyGizmo.configuration.api_token).to eq(api_token)
35
+
36
+ Thread.new do
37
+ expect(SurveyGizmo.configuration.api_token).to eq(api_token)
38
+ end
39
+ end
40
+
41
+ it "is not affected by a change in another thread" do
42
+ expect(SurveyGizmo.configuration.api_token).to eq(api_token)
43
+
44
+ Thread.new do
45
+ SurveyGizmo.configure {|c| c.api_token = "new_token"}
46
+ expect(SurveyGizmo.configuration.api_token).to eq("new_token")
47
+ end.join
48
+
49
+ expect(SurveyGizmo.configuration.api_token).to eq(api_token)
50
+ end
51
+
52
+ it "is not affected by a reset in another thread" do
53
+ expect(SurveyGizmo.configuration.api_token).to eq(api_token)
54
+
55
+ Thread.new do
56
+ SurveyGizmo.reset!
57
+ expect(SurveyGizmo.configuration.api_token).to eq(nil)
58
+ end.join
59
+
60
+ expect(SurveyGizmo.configuration.api_token).to eq(api_token)
23
61
  end
24
62
 
25
- expect(SurveyGizmo::Connection.send(:connection).params).to eq('api_token' => 'slimthug', 'api_token_secret' => 'fourfourz')
63
+ it "updates the last known configuration" do
64
+ expect(SurveyGizmo.configuration.api_token).to eq(api_token)
65
+
66
+ Thread.new do
67
+ SurveyGizmo.configure {|c| c.api_token = "new_token"}
68
+ expect(SurveyGizmo.configuration.api_token).to eq("new_token")
69
+ end.join
70
+ Thread.new do
71
+ expect(SurveyGizmo.configuration.api_token).to eq("new_token")
72
+ end.join
73
+ end
74
+
75
+ describe ".configuration=" do
76
+ let(:new_config) { SurveyGizmo::Configuration.new.tap { |c| c.api_token = "new_token" } }
77
+
78
+ it "sets the configuration" do
79
+ expect{
80
+ SurveyGizmo.configuration = new_config
81
+ }.to change {
82
+ SurveyGizmo.configuration.api_token
83
+ }.from(api_token).to("new_token")
84
+ end
85
+
86
+ it "does not affect other threads" do
87
+ expect {
88
+ Thread.new do
89
+ SurveyGizmo.configuration = new_config
90
+ expect(SurveyGizmo.configuration.api_token).to eq("new_token")
91
+ end.join
92
+ }.not_to change {
93
+ SurveyGizmo.configuration.api_token
94
+ }.from(api_token)
95
+ end
96
+
97
+ it "updates the last known configuration" do
98
+ SurveyGizmo.configuration = new_config
99
+ Thread.new do
100
+ expect(SurveyGizmo.configuration.api_token).to eq("new_token")
101
+ end.join
102
+ end
103
+ end
26
104
  end
27
105
 
28
106
  describe '#region=' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: survey-gizmo-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.7.0
4
+ version: 7.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kabari Hendrick
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2019-04-11 00:00:00.000000000 Z
14
+ date: 2019-09-23 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: activesupport