px-service-client 2.0.0 → 2.0.1

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
  SHA1:
3
- metadata.gz: 9a10d1168c3cd74e1fb75eb062481a9aa8dfa25d
4
- data.tar.gz: 81dd905f9e51020552ed8c655c11678e8fe5fdc5
3
+ metadata.gz: 19e7ec8a32fa4b49f0fac0e10eab3b1a38e373f2
4
+ data.tar.gz: b583bc1b97b2ad936e30242238184ce2d4241034
5
5
  SHA512:
6
- metadata.gz: 53fce4eecc310c99c01ccf635de6616d46dc61edcfb40362657caf28390a99a3b6b51dc502812dbb5c4e006cd90d735295d812bfee4903452ceb2f4fe1069e5e
7
- data.tar.gz: 43d57237b4ab1e3b8f2882baa419ad14fb784cce1f270690d11fcd72268ff046bb1b012c4b96236b08546666a5525e8817671e4b5a6f837bd2a2549eaf122833
6
+ metadata.gz: afe66390c4020a0896b7d882e9bcf78463ab3a932b4373f428f16b96f5c84d0250d8eabd57df4e12f6ca27c0c4ceb05a33281b721f4cad51973de50f321f024e
7
+ data.tar.gz: cc9b24b80f6945371bfc339cb73e75a48473860e18a3a60bbfdac6554aa643ee5152c6421de579fb23f166e8db73aebaf2c5188bcda5a563027766e272ac3f55
@@ -1,6 +1,6 @@
1
1
  module Px::Service::Client
2
2
  class Base
3
- cattr_accessor :logger
3
+ class_attribute :logger, :config
4
4
 
5
5
  class DefaultConfig < OpenStruct
6
6
  def initialize
@@ -9,21 +9,19 @@ module Px::Service::Client
9
9
  end
10
10
  end
11
11
 
12
+ self.config = DefaultConfig.new
13
+
12
14
  ##
13
15
  # Configure the client
14
- def self.config
15
- @config ||= DefaultConfig.new
16
- yield(@config) if block_given?
17
- @config
16
+ def self.configure
17
+ c = self.config.dup
18
+ yield(c) if block_given?
19
+ self.config = c
18
20
  end
19
21
 
20
22
  # Make class config available to instances
21
- def config
22
- if block_given?
23
- self.class.config { |c| yield(c) }
24
- else
25
- self.class.config
26
- end
23
+ def configure
24
+ self.class.configure { |c| yield(c) }
27
25
  end
28
26
 
29
27
  private
@@ -19,15 +19,15 @@ module Px::Service::Client
19
19
  included do
20
20
  cattr_accessor :cache_client, :cache_logger
21
21
 
22
- config do |config|
22
+ configure do |config|
23
23
  config.cache_expiry = 30.seconds
24
24
  config.cache_default_policy_group = 'general'
25
25
  config.cache_logger = nil
26
26
  config.cache_client = nil
27
27
  end
28
28
 
29
- # DEPRECATED: Use .config (base class method) instead
30
- alias_method :caching, :config
29
+ # DEPRECATED: Use .configure (base class method) instead
30
+ alias_method :caching, :configure
31
31
  end
32
32
 
33
33
  def cache_request(url, strategy: nil, policy_group: config.cache_default_policy_group, expires_in: config.cache_expiry, refresh_probability: 1)
@@ -13,14 +13,14 @@ module Px::Service::Client
13
13
  end
14
14
 
15
15
  # Default config for signing
16
- config do |config|
16
+ configure do |config|
17
17
  config.hmac_secret = DEFAULT_SECRET
18
18
  config.hmac_keyspan = DEFAULT_KEYSPAN
19
19
  end
20
20
 
21
21
  ##
22
22
  # DEPRECATED: Use .config (base class method) instead
23
- alias_method :hmac_signing, :config
23
+ alias_method :hmac_signing, :configure
24
24
  end
25
25
 
26
26
  module ClassMethods
@@ -1,7 +1,7 @@
1
1
  module Px
2
2
  module Service
3
3
  module Client
4
- VERSION = "2.0.0"
4
+ VERSION = "2.0.1"
5
5
  end
6
6
  end
7
7
  end
@@ -8,7 +8,7 @@ describe Px::Service::Client::Base do
8
8
  subject {
9
9
  Class.new(Px::Service::Client::Base).tap do |c|
10
10
  c.include(Px::Service::Client::Caching)
11
- c.config do |config|
11
+ c.configure do |config|
12
12
  config.cache_client = dalli
13
13
  end
14
14
  end.new
@@ -30,7 +30,7 @@ describe Px::Service::Client::Base do
30
30
 
31
31
  context "when there are separate subclasses" do
32
32
  before :each do
33
- subject.config do |c|
33
+ subject.configure do |c|
34
34
  c.subject_field = "value"
35
35
  end
36
36
  end
@@ -43,6 +43,42 @@ describe Px::Service::Client::Base do
43
43
  expect(other_subclass.config.subject_field).not_to eq("value")
44
44
  end
45
45
  end
46
+
47
+ context "when the subclass is itself inherited" do
48
+ let(:subsubclass) {
49
+ Class.new(subject.class).new
50
+ }
51
+
52
+ before :each do
53
+ subject.configure do |c|
54
+ c.subject_field = "value"
55
+ end
56
+ end
57
+
58
+ it "sets the config value on the subject" do
59
+ expect(subject.config.subject_field).to eq("value")
60
+ end
61
+
62
+ it "inherits the config value on the sub-subclass" do
63
+ expect(subsubclass.config.subject_field).to eq("value")
64
+ end
65
+
66
+ context "when the config value is changed on the sub-subclass" do
67
+ before :each do
68
+ subsubclass.configure do |c|
69
+ c.subject_field = "other"
70
+ end
71
+ end
72
+
73
+ it "does not change the config value on the subject" do
74
+ expect(subject.config.subject_field).to eq("value")
75
+ end
76
+
77
+ it "changes the config value on the sub-subclass" do
78
+ expect(subsubclass.config.subject_field).to eq("other")
79
+ end
80
+ end
81
+ end
46
82
  end
47
83
 
48
84
  describe '#make_request' do
@@ -9,11 +9,11 @@ describe Px::Service::Client::Caching do
9
9
  subject {
10
10
  Class.new(Px::Service::Client::Base).tap do |c|
11
11
  c.include(Px::Service::Client::Caching)
12
-
12
+
13
13
  # Anonymous classes don't have a name. Stub out :name so that things work
14
14
  allow(c).to receive(:name).and_return("Caching")
15
15
 
16
- c.config do |config|
16
+ c.configure do |config|
17
17
  config.cache_client = dalli
18
18
  end
19
19
  end.new
@@ -87,7 +87,7 @@ describe Px::Service::Client::Caching do
87
87
 
88
88
  context 'when cache client is not set' do
89
89
  before :each do
90
- subject.config do |config|
90
+ subject.configure do |config|
91
91
  config.cache_client = nil
92
92
  end
93
93
  end
@@ -111,7 +111,7 @@ describe Px::Service::Client::Caching do
111
111
  context "when there is a cached response" do
112
112
  context 'when cache client is not set' do
113
113
  before :each do
114
- subject.config do |config|
114
+ subject.configure do |config|
115
115
  config.cache_client = nil
116
116
  end
117
117
  end
@@ -166,7 +166,7 @@ describe Px::Service::Client::Caching do
166
166
  context "when there is a cached response" do
167
167
  context 'when cache client is not set' do
168
168
  before :each do
169
- subject.config do |config|
169
+ subject.configure do |config|
170
170
  config.cache_client = nil
171
171
  end
172
172
  end
@@ -13,7 +13,7 @@ describe Px::Service::Client::HmacSigning do
13
13
  Class.new(Px::Service::Client::Base).tap do |c|
14
14
  c.include(Px::Service::Client::HmacSigning)
15
15
 
16
- c.config do |config|
16
+ c.configure do |config|
17
17
  config.hmac_secret = "different secret"
18
18
  end
19
19
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: px-service-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Micacchi