survey-gizmo-ruby 6.7.0 → 7.0.0
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/CHANGELOG.md +2 -0
- data/README.md +4 -0
- data/lib/survey_gizmo/configuration.rb +21 -13
- data/lib/survey_gizmo/version.rb +1 -1
- data/spec/configuration_spec.rb +84 -6
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2a08475717245ba2f53f58bf497f7b18fd8bab1f61554e73862c83fafb8fa8c6
|
4
|
+
data.tar.gz: eb9c8b9f1591d2a381bd926fe61d8649290aeee8ea22a1c879d37c845610e132
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 75a62b2a9af99e373beca17f5f2c4bef2ff9ee1a1b047b01a2110fc22109bcf5bf63fc50d11b0760c939c84c7475bd2d3a69956d49913ecbe3dc4c7961247db6
|
7
|
+
data.tar.gz: 718d88e0d421b56ae97467cb078f69bf5230337db62e387bf42dddb5c2aa2d308c4c4a5fd2e39834323658898ad5b5f43cd589e0f616c4e47eb83c168c813bf4
|
data/CHANGELOG.md
CHANGED
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 @
|
9
|
-
@
|
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(
|
20
|
+
yield(configuration) if block_given?
|
15
21
|
|
16
|
-
if
|
17
|
-
|
18
|
-
|
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
|
22
|
-
|
23
|
-
|
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
|
-
|
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
|
-
|
38
|
+
Thread.current[CONFIG_THREAD_VARIABLE_NAME] = Configuration.new
|
31
39
|
Connection.reset!
|
32
40
|
end
|
33
41
|
end
|
data/lib/survey_gizmo/version.rb
CHANGED
data/spec/configuration_spec.rb
CHANGED
@@ -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 =
|
8
|
-
config.api_token_secret =
|
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
|
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 =
|
22
|
-
config.api_token_secret =
|
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
|
-
|
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:
|
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-
|
14
|
+
date: 2019-09-23 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: activesupport
|